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

View File

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

View File

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