mirror of
https://github.com/inventree/inventree-app.git
synced 2025-04-28 05:26:47 +00:00
Fixes for login dialogs
This commit is contained in:
parent
78f3bc0b26
commit
911f988fa5
@ -55,43 +55,28 @@ class _InvenTreeLoginSettingsState extends State<InvenTreeLoginSettingsWidget> {
|
||||
showFormDialog(
|
||||
I18N.of(context).profileAdd,
|
||||
key: _addProfileKey,
|
||||
actions: <Widget> [
|
||||
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: <Widget> [
|
||||
StringField(
|
||||
label: I18N.of(context).name,
|
||||
@ -188,9 +173,6 @@ class _InvenTreeLoginSettingsState extends State<InvenTreeLoginSettingsWidget> {
|
||||
|
||||
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<InvenTreeLoginSettingsWidget> {
|
||||
|
||||
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<InvenTreeLoginSettingsWidget> {
|
||||
|
||||
await UserProfileDBManager().addProfile(profile);
|
||||
|
||||
// Dismiss the create dialog
|
||||
Navigator.of(context).pop();
|
||||
|
||||
_reload();
|
||||
}
|
||||
|
||||
@ -303,9 +279,9 @@ class _InvenTreeLoginSettingsState extends State<InvenTreeLoginSettingsWidget> {
|
||||
),
|
||||
SimpleDialogOption(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
// Navigator.of(context, rootNavigator: true).pop();
|
||||
confirmationDialog(
|
||||
context,
|
||||
I18N.of(context).delete,
|
||||
"Delete this profile?",
|
||||
onAccept: () {
|
||||
|
@ -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<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) {
|
||||
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<FormState> key, List<Widget> 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<FormState> key, List<Widget> 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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user