2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-04-28 13:36:50 +00:00

Fixes for login dialogs

This commit is contained in:
Oliver Walters 2021-02-16 23:03:01 +11:00
parent 78f3bc0b26
commit 911f988fa5
2 changed files with 63 additions and 82 deletions

View File

@ -55,19 +55,7 @@ class _InvenTreeLoginSettingsState extends State<InvenTreeLoginSettingsWidget> {
showFormDialog( showFormDialog(
I18N.of(context).profileAdd, I18N.of(context).profileAdd,
key: _addProfileKey, key: _addProfileKey,
actions: <Widget> [ callback: () {
FlatButton(
child: Text(I18N.of(context).cancel),
onPressed: () {
Navigator.of(context).pop();
}
),
FlatButton(
child: Text(I18N.of(context).save),
onPressed: () {
if (_addProfileKey.currentState.validate()) {
_addProfileKey.currentState.save();
if (createNew) { if (createNew) {
// TODO - create the new profile... // TODO - create the new profile...
UserProfile profile = UserProfile( UserProfile profile = UserProfile(
@ -88,10 +76,7 @@ class _InvenTreeLoginSettingsState extends State<InvenTreeLoginSettingsWidget> {
_updateProfile(profile); _updateProfile(profile);
} }
} },
}
)
],
fields: <Widget> [ fields: <Widget> [
StringField( StringField(
label: I18N.of(context).name, label: I18N.of(context).name,
@ -188,9 +173,6 @@ class _InvenTreeLoginSettingsState extends State<InvenTreeLoginSettingsWidget> {
await UserProfileDBManager().deleteProfile(profile); await UserProfileDBManager().deleteProfile(profile);
// Close the dialog
Navigator.of(context).pop();
_reload(); _reload();
if (InvenTreeAPI().isConnected() && profile.key == InvenTreeAPI().profile.key) { if (InvenTreeAPI().isConnected() && profile.key == InvenTreeAPI().profile.key) {
@ -202,9 +184,6 @@ class _InvenTreeLoginSettingsState extends State<InvenTreeLoginSettingsWidget> {
await UserProfileDBManager().updateProfile(profile); await UserProfileDBManager().updateProfile(profile);
// Dismiss the dialog
Navigator.of(context).pop();
_reload(); _reload();
if (InvenTreeAPI().isConnected() && profile.key == InvenTreeAPI().profile.key) { if (InvenTreeAPI().isConnected() && profile.key == InvenTreeAPI().profile.key) {
@ -220,9 +199,6 @@ class _InvenTreeLoginSettingsState extends State<InvenTreeLoginSettingsWidget> {
await UserProfileDBManager().addProfile(profile); await UserProfileDBManager().addProfile(profile);
// Dismiss the create dialog
Navigator.of(context).pop();
_reload(); _reload();
} }
@ -303,9 +279,9 @@ class _InvenTreeLoginSettingsState extends State<InvenTreeLoginSettingsWidget> {
), ),
SimpleDialogOption( SimpleDialogOption(
onPressed: () { onPressed: () {
Navigator.of(context).pop();
// Navigator.of(context, rootNavigator: true).pop(); // Navigator.of(context, rootNavigator: true).pop();
confirmationDialog( confirmationDialog(
context,
I18N.of(context).delete, I18N.of(context).delete,
"Delete this profile?", "Delete this profile?",
onAccept: () { onAccept: () {

View File

@ -5,17 +5,19 @@ import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:one_context/one_context.dart'; import 'package:one_context/one_context.dart';
Future<void> confirmationDialog(BuildContext context, String title, String text, {String acceptText, String rejectText, Function onAccept, Function onReject}) async { Future<void> confirmationDialog(String title, String text, {String acceptText, String rejectText, Function onAccept, Function onReject}) async {
if (acceptText == null || acceptText.isEmpty) { if (acceptText == null || acceptText.isEmpty) {
acceptText = I18N.of(context).ok; acceptText = I18N.of(OneContext().context).ok;
} }
if (rejectText == null || rejectText.isEmpty) { if (rejectText == null || rejectText.isEmpty) {
rejectText = I18N.of(context).cancel; rejectText = I18N.of(OneContext().context).cancel;
} }
AlertDialog dialog = AlertDialog( OneContext().showDialog(
builder: (BuildContext context) {
return AlertDialog(
title: ListTile( title: ListTile(
title: Text(title), title: Text(title),
leading: FaIcon(FontAwesomeIcons.questionCircle), leading: FaIcon(FontAwesomeIcons.questionCircle),
@ -25,7 +27,9 @@ Future<void> confirmationDialog(BuildContext context, String title, String text,
FlatButton( FlatButton(
child: Text(rejectText), child: Text(rejectText),
onPressed: () { onPressed: () {
Navigator.of(context, rootNavigator: true).pop(); // Close this dialog
Navigator.pop(context);
if (onReject != null) { if (onReject != null) {
onReject(); onReject();
} }
@ -34,19 +38,16 @@ Future<void> confirmationDialog(BuildContext context, String title, String text,
FlatButton( FlatButton(
child: Text(acceptText), child: Text(acceptText),
onPressed: () { onPressed: () {
Navigator.of(context, rootNavigator: true).pop(); // Close this dialog
Navigator.pop(context);
if (onAccept != null) { if (onAccept != null) {
onAccept(); onAccept();
} }
} },
) )
], ]
); );
showDialog(
context: context,
builder: (BuildContext context) {
return dialog;
} }
); );
} }
@ -171,8 +172,10 @@ void showFormDialog(String title, {GlobalKey<FormState> key, List<Widget> fields
FlatButton( FlatButton(
child: Text(I18N.of(OneContext().context).cancel), child: Text(I18N.of(OneContext().context).cancel),
onPressed: () { onPressed: () {
print("cancel and close the dialog");
// Close the form // Close the form
Navigator.of(OneContext().context).pop(); Navigator.pop(dialogContext);
} }
), ),
FlatButton( FlatButton(
@ -181,8 +184,10 @@ void showFormDialog(String title, {GlobalKey<FormState> key, List<Widget> fields
if (key.currentState.validate()) { if (key.currentState.validate()) {
key.currentState.save(); key.currentState.save();
print("Saving and closing the dialog");
// Close the dialog // Close the dialog
Navigator.pop(OneContext().context); Navigator.pop(dialogContext);
// Callback // Callback
if (callback != null) { if (callback != null) {