From 911f988fa5e7069560771a34e60d82db35a4aa96 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Tue, 16 Feb 2021 23:03:01 +1100 Subject: [PATCH] Fixes for login dialogs --- lib/settings/login.dart | 68 ++++++++++++------------------------ lib/widget/dialogs.dart | 77 ++++++++++++++++++++++------------------- 2 files changed, 63 insertions(+), 82 deletions(-) diff --git a/lib/settings/login.dart b/lib/settings/login.dart index 730a42c0..56a058e9 100644 --- a/lib/settings/login.dart +++ b/lib/settings/login.dart @@ -55,43 +55,28 @@ class _InvenTreeLoginSettingsState extends State { showFormDialog( I18N.of(context).profileAdd, key: _addProfileKey, - actions: [ - FlatButton( - child: Text(I18N.of(context).cancel), - onPressed: () { - Navigator.of(context).pop(); + callback: () { + if (createNew) { + // TODO - create the new profile... + UserProfile profile = UserProfile( + name: _name, + server: _server, + username: _username, + password: _password + ); + + _addProfile(profile); + } else { + + profile.name = _name; + profile.server = _server; + profile.username = _username; + profile.password = _password; + + _updateProfile(profile); + } - ), - FlatButton( - child: Text(I18N.of(context).save), - onPressed: () { - if (_addProfileKey.currentState.validate()) { - _addProfileKey.currentState.save(); - - if (createNew) { - // TODO - create the new profile... - UserProfile profile = UserProfile( - name: _name, - server: _server, - username: _username, - password: _password - ); - - _addProfile(profile); - } else { - - profile.name = _name; - profile.server = _server; - profile.username = _username; - profile.password = _password; - - _updateProfile(profile); - - } - } - } - ) - ], + }, fields: [ StringField( label: I18N.of(context).name, @@ -188,9 +173,6 @@ class _InvenTreeLoginSettingsState extends State { await UserProfileDBManager().deleteProfile(profile); - // Close the dialog - Navigator.of(context).pop(); - _reload(); if (InvenTreeAPI().isConnected() && profile.key == InvenTreeAPI().profile.key) { @@ -202,9 +184,6 @@ class _InvenTreeLoginSettingsState extends State { await UserProfileDBManager().updateProfile(profile); - // Dismiss the dialog - Navigator.of(context).pop(); - _reload(); if (InvenTreeAPI().isConnected() && profile.key == InvenTreeAPI().profile.key) { @@ -220,9 +199,6 @@ class _InvenTreeLoginSettingsState extends State { await UserProfileDBManager().addProfile(profile); - // Dismiss the create dialog - Navigator.of(context).pop(); - _reload(); } @@ -303,9 +279,9 @@ class _InvenTreeLoginSettingsState extends State { ), SimpleDialogOption( onPressed: () { + Navigator.of(context).pop(); // Navigator.of(context, rootNavigator: true).pop(); confirmationDialog( - context, I18N.of(context).delete, "Delete this profile?", onAccept: () { diff --git a/lib/widget/dialogs.dart b/lib/widget/dialogs.dart index 375e2bf0..1e467ec5 100644 --- a/lib/widget/dialogs.dart +++ b/lib/widget/dialogs.dart @@ -5,48 +5,49 @@ import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:one_context/one_context.dart'; -Future confirmationDialog(BuildContext context, String title, String text, {String acceptText, String rejectText, Function onAccept, Function onReject}) async { +Future confirmationDialog(String title, String text, {String acceptText, String rejectText, Function onAccept, Function onReject}) async { if (acceptText == null || acceptText.isEmpty) { - acceptText = I18N.of(context).ok; + acceptText = I18N.of(OneContext().context).ok; } if (rejectText == null || rejectText.isEmpty) { - rejectText = I18N.of(context).cancel; + rejectText = I18N.of(OneContext().context).cancel; } - AlertDialog dialog = AlertDialog( - title: ListTile( - title: Text(title), - leading: FaIcon(FontAwesomeIcons.questionCircle), - ), - content: Text(text), - actions: [ - FlatButton( - child: Text(rejectText), - onPressed: () { - Navigator.of(context, rootNavigator: true).pop(); - if (onReject != null) { - onReject(); - } - } - ), - FlatButton( - child: Text(acceptText), - onPressed: () { - Navigator.of(context, rootNavigator: true).pop(); - if (onAccept != null) { - onAccept(); - } - } - ) - ], - ); - - showDialog( - context: context, + OneContext().showDialog( builder: (BuildContext context) { - return dialog; + return AlertDialog( + title: ListTile( + title: Text(title), + leading: FaIcon(FontAwesomeIcons.questionCircle), + ), + content: Text(text), + actions: [ + FlatButton( + child: Text(rejectText), + onPressed: () { + // Close this dialog + Navigator.pop(context); + + if (onReject != null) { + onReject(); + } + } + ), + FlatButton( + child: Text(acceptText), + onPressed: () { + // Close this dialog + Navigator.pop(context); + + if (onAccept != null) { + onAccept(); + } + }, + ) + ] + ); } ); } @@ -171,8 +172,10 @@ void showFormDialog(String title, {GlobalKey key, List fields FlatButton( child: Text(I18N.of(OneContext().context).cancel), onPressed: () { + + print("cancel and close the dialog"); // Close the form - Navigator.of(OneContext().context).pop(); + Navigator.pop(dialogContext); } ), FlatButton( @@ -181,8 +184,10 @@ void showFormDialog(String title, {GlobalKey key, List fields if (key.currentState.validate()) { key.currentState.save(); + print("Saving and closing the dialog"); + // Close the dialog - Navigator.pop(OneContext().context); + Navigator.pop(dialogContext); // Callback if (callback != null) {