• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wger-project / flutter / 30854254088

03 Aug 2026 09:21PM UTC coverage: 40.895% (-15.0%) from 55.93%
30854254088

Pull #1260

github

web-flow
Merge d93794de5 into e3affdd4f
Pull Request #1260: WIP: health sync

9980 of 24404 relevant lines covered (40.89%)

1.72 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.0
/lib/core/widgets/form_submit_button.dart
1
/*
2
 * This file is part of wger Workout Manager <https://github.com/wger-project>.
3
 * Copyright (c) 2026 - 2026 wger Team
4
 *
5
 * wger Workout Manager is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU Affero General Public License as published by
7
 * the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU Affero General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU Affero General Public License
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 */
18

19
import 'package:flutter/material.dart';
20
import 'package:wger/core/error_dialogs.dart';
21
import 'package:wger/core/exceptions/http_exception.dart';
22
import 'package:wger/core/widgets/progress_indicator.dart';
23

24
/// Submit button that owns the saving and error state of an async form action.
25
///
26
/// While [onPressed] is in flight the button is disabled and renders a
27
/// [FormProgressIndicator], which also prevents a double submit. A
28
/// [WgerHttpException] thrown by [onPressed] is caught and rendered as a
29
/// [FormHttpErrorsWidget] directly above the button, other errors propagate
30
/// to the global error handler. Set [enabled] to false to disable the button
31
/// for other reasons, e.g. while offline.
32
class FormSubmitButton extends StatefulWidget {
33
  const FormSubmitButton({
13✔
34
    required this.onPressed,
35
    required this.label,
36
    this.enabled = true,
37
    super.key,
38
  });
39

40
  /// Async submit action. The spinner is shown until the returned future
41
  /// completes. A [WgerHttpException] is rendered inline; any other error is
42
  /// left to propagate.
43
  final Future<void> Function() onPressed;
44

45
  final String label;
46

47
  /// When false the button is disabled regardless of the saving state.
48
  final bool enabled;
49

50
  @override
13✔
51
  State<FormSubmitButton> createState() => _FormSubmitButtonState();
13✔
52
}
53

54
class _FormSubmitButtonState extends State<FormSubmitButton> {
55
  bool _isSaving = false;
56
  WgerHttpException? _error;
57

58
  Future<void> _handlePressed() async {
8✔
59
    setState(() {
16✔
60
      _isSaving = true;
8✔
61
      _error = null;
8✔
62
    });
63
    try {
64
      await widget.onPressed();
24✔
65
    } on WgerHttpException catch (error) {
×
66
      if (mounted) {
×
67
        setState(() => _error = error);
×
68
      }
69
    } finally {
70
      if (mounted) {
8✔
71
        setState(() => _isSaving = false);
24✔
72
      }
73
    }
74
  }
75

76
  @override
13✔
77
  Widget build(BuildContext context) {
78
    return Column(
13✔
79
      mainAxisSize: MainAxisSize.min,
80
      children: [
13✔
81
        if (_error != null) FormHttpErrorsWidget(_error!),
13✔
82
        ElevatedButton(
13✔
83
          onPressed: _isSaving || !widget.enabled ? null : _handlePressed,
50✔
84
          child: _isSaving ? const FormProgressIndicator() : Text(widget.label),
52✔
85
        ),
86
      ],
87
    );
88
  }
89
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc