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:
parent
78f3bc0b26
commit
911f988fa5
@ -55,43 +55,28 @@ class _InvenTreeLoginSettingsState extends State<InvenTreeLoginSettingsWidget> {
|
|||||||
showFormDialog(
|
showFormDialog(
|
||||||
I18N.of(context).profileAdd,
|
I18N.of(context).profileAdd,
|
||||||
key: _addProfileKey,
|
key: _addProfileKey,
|
||||||
actions: <Widget> [
|
callback: () {
|
||||||
FlatButton(
|
if (createNew) {
|
||||||
child: Text(I18N.of(context).cancel),
|
// TODO - create the new profile...
|
||||||
onPressed: () {
|
UserProfile profile = UserProfile(
|
||||||
Navigator.of(context).pop();
|
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> [
|
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: () {
|
||||||
|
@ -5,48 +5,49 @@ 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(
|
||||||
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,
|
|
||||||
builder: (BuildContext context) {
|
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(
|
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) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user