diff --git a/lib/main_app.dart b/lib/main_app.dart index a8599afd2..4e687d4fe 100644 --- a/lib/main_app.dart +++ b/lib/main_app.dart @@ -353,7 +353,7 @@ class InvoiceNinjaAppState extends State { return StyledToast( locale: locale, - duration: Duration(seconds: 3), + duration: Duration(seconds: 4), backgroundColor: state.prefState.enableDarkMode ? Colors.white : Colors.black, textStyle: TextStyle( diff --git a/lib/utils/dialogs.dart b/lib/utils/dialogs.dart index afaeb2089..ed922ce72 100644 --- a/lib/utils/dialogs.dart +++ b/lib/utils/dialogs.dart @@ -6,6 +6,7 @@ import 'package:flutter/services.dart'; // Package imports: import 'package:flutter_redux/flutter_redux.dart'; +import 'package:flutter_styled_toast/flutter_styled_toast.dart'; import 'package:invoiceninja_flutter/data/web_client.dart'; import 'package:invoiceninja_flutter/main_app.dart'; import 'package:invoiceninja_flutter/redux/task/task_actions.dart'; @@ -628,6 +629,7 @@ class RunTemplateDialog extends StatefulWidget { class _RunTemplateDialogState extends State { String _designId = ''; bool _sendEmail = false; + bool _isLoading = false; @override Widget build(BuildContext context) { @@ -660,12 +662,22 @@ class _RunTemplateDialogState extends State { }; print('## DATA: $data'); + + setState(() => _isLoading = true); + WebClient() .post(url, credentials.token, data: jsonEncode(data)) .then((response) { print('## RESPONSE: $response'); + setState(() => _isLoading = false); + + if (_sendEmail) { + Navigator.of(navigatorKey.currentContext!).pop(); + showToast(localization.exportedData); + } }).catchError((error) { print('## ERROR: $error'); + setState(() => _isLoading = false); }); }, child: Text(localization.start.toUpperCase()), @@ -685,28 +697,34 @@ class _RunTemplateDialogState extends State { ...widget.entities .map((entity) => Text(entity.listDisplayName)) .toList(), - SizedBox(height: 8), - DesignPicker( - autofocus: true, - entityType: widget.entityType, - onSelected: (design) { - setState(() { - _designId = design?.id ?? ''; - }); - }, - ), - SizedBox(height: 16), - SwitchListTile( - value: _sendEmail, - title: Text( - localization.sendEmail, + if (_isLoading) ...[ + SizedBox(height: 30), + LinearProgressIndicator() + ] else ...[ + SizedBox(height: 8), + DesignPicker( + autofocus: true, + entityType: widget.entityType, + initialValue: _designId, + onSelected: (design) { + setState(() { + _designId = design?.id ?? ''; + }); + }, ), - onChanged: (value) { - setState(() { - _sendEmail = value; - }); - }, - ), + SizedBox(height: 16), + SwitchListTile( + value: _sendEmail, + title: Text( + localization.sendEmail, + ), + onChanged: (value) { + setState(() { + _sendEmail = value; + }); + }, + ), + ], ], ), ),