2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-04-28 05:26:47 +00:00
This commit is contained in:
Oliver Walters 2021-02-09 09:12:47 +11:00
parent 74e6315a57
commit d918079440
5 changed files with 80 additions and 78 deletions

@ -1 +1 @@
Subproject commit ef139565bba4fcd5889aa242a0062827eab5eceb Subproject commit c342d99f068f8ac662dfb729fea0b5867aac1cc6

View File

@ -83,24 +83,4 @@ class InvenTreePreferences {
} }
InvenTreePreferences._internal(); InvenTreePreferences._internal();
// Load saved login details, and attempt connection
void loadLoginDetails(BuildContext context) async {
print("Loading login details");
await InvenTreeAPI().connectToServer(context);
}
void saveLoginDetails(BuildContext context, String server, String username, String password) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.setString(_SERVER, server);
await prefs.setString(_USERNAME, username);
await prefs.setString(_PASSWORD, password);
// Reconnect the API
await InvenTreeAPI().connectToServer(context);
}
} }

View File

@ -166,7 +166,7 @@ class _InvenTreeLoginSettingsState extends State<InvenTreeLoginSettingsWidget> {
return null; return null;
} }
void _selectProfile(UserProfile profile) async { void _selectProfile(BuildContext context, UserProfile profile) async {
// Mark currently selected profile as unselected // Mark currently selected profile as unselected
final selected = await UserProfileDBManager().getSelectedProfile(); final selected = await UserProfileDBManager().getSelectedProfile();
@ -180,6 +180,9 @@ class _InvenTreeLoginSettingsState extends State<InvenTreeLoginSettingsWidget> {
await UserProfileDBManager().updateProfile(profile); await UserProfileDBManager().updateProfile(profile);
_reload(); _reload();
// Attempt server login (this will load the newly selected profile
InvenTreeAPI().connect(context);
} }
void _deleteProfile(UserProfile profile) async { void _deleteProfile(UserProfile profile) async {
@ -219,60 +222,78 @@ class _InvenTreeLoginSettingsState extends State<InvenTreeLoginSettingsWidget> {
List<Widget> children = []; List<Widget> children = [];
for (int idx = 0; idx < profiles.length; idx++) { if (profiles.length > 0) {
for (int idx = 0; idx < profiles.length; idx++) {
UserProfile profile = profiles[idx];
UserProfile profile = profiles[idx]; children.add(ListTile(
title: Text(
children.add(ListTile(
title: Text(
profile.name, profile.name,
), ),
subtitle: Text(profile.server), subtitle: Text(profile.server),
trailing: profile.selected ? FaIcon(FontAwesomeIcons.checkCircle) : null, trailing: profile.selected
onLongPress: () { ? FaIcon(FontAwesomeIcons.checkCircle)
showDialog( : null,
context: context, onLongPress: () {
builder: (BuildContext context) { showDialog(
return SimpleDialog( context: context,
title: Text(profile.name), builder: (BuildContext context) {
children: <Widget> [ return SimpleDialog(
SimpleDialogOption( title: Text(profile.name),
onPressed: () { children: <Widget>[
Navigator.of(context).pop(); SimpleDialogOption(
_selectProfile(profile); onPressed: () {
}, Navigator.of(context).pop();
child: Text(I18N.of(context).profileSelect), _selectProfile(context, profile);
), },
SimpleDialogOption( child: Text(I18N
onPressed: () { .of(context)
Navigator.of(context).pop(); .profileSelect),
_editProfile(context, userProfile: profile); ),
}, SimpleDialogOption(
child: Text(I18N.of(context).profileEdit), onPressed: () {
), Navigator.of(context).pop();
SimpleDialogOption( _editProfile(context, userProfile: profile);
onPressed: () { },
// Navigator.of(context, rootNavigator: true).pop(); child: Text(I18N
confirmationDialog( .of(context)
context, .profileEdit),
I18N.of(context).delete, ),
"Delete this profile?", SimpleDialogOption(
onAccept: () { onPressed: () {
_deleteProfile(profile); // Navigator.of(context, rootNavigator: true).pop();
} confirmationDialog(
); context,
}, I18N
child: Text(I18N.of(context).profileDelete), .of(context)
) .delete,
], "Delete this profile?",
); onAccept: () {
} _deleteProfile(profile);
); }
}, );
onTap: () { },
child: Text(I18N
.of(context)
.profileDelete),
)
],
);
}
);
},
onTap: () {
}, },
)); ));
}
} else {
// No profile available!
children.add(
ListTile(
title: Text("No profiles available"),
)
);
} }
return Scaffold( return Scaffold(

View File

@ -30,15 +30,15 @@ class _InvenTreeSettingsState extends State<InvenTreeSettingsWidget> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text("InvenTree Settings"), title: Text(I18N.of(context).settings),
), ),
body: Center( body: Center(
child: ListView( child: ListView(
children: <Widget>[ children: <Widget>[
ListTile( ListTile(
title: Text(I18N.of(context).serverSettings), title: Text(I18N.of(context).profile),
subtitle: Text("Configure server and login settings"), subtitle: Text("Configure user profile settings"),
leading: FaIcon(FontAwesomeIcons.server), leading: FaIcon(FontAwesomeIcons.user),
onTap: _editServerSettings, onTap: _editServerSettings,
), ),
Divider(), Divider(),

View File

@ -3,6 +3,7 @@ import 'package:InvenTree/barcode.dart';
import 'package:InvenTree/widget/company_list.dart'; import 'package:InvenTree/widget/company_list.dart';
import 'package:InvenTree/widget/search.dart'; import 'package:InvenTree/widget/search.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:InvenTree/api.dart'; import 'package:InvenTree/api.dart';
@ -155,7 +156,7 @@ class InvenTreeDrawer extends StatelessWidget {
*/ */
new Divider(), new Divider(),
new ListTile( new ListTile(
title: new Text("Settings"), title: new Text(I18N.of(context).settings),
leading: new Icon(Icons.settings), leading: new Icon(Icons.settings),
onTap: _settings, onTap: _settings,
), ),