2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-05-11 03:38:51 +00:00

Load / save login settings

- Using simple shared_preferences package for now
This commit is contained in:
Oliver Walters 2019-06-25 22:14:31 +10:00
parent e723a70d15
commit 6b58ccb844
3 changed files with 41 additions and 5 deletions

@ -1,5 +1,5 @@
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
class InvenTreeLoginSettingsWidget extends StatefulWidget {
@ -41,8 +41,16 @@ class _InvenTreeLoginSettingsState extends State<InvenTreeLoginSettingsWidget> {
return null;
}
@override
void initState() {
load();
}
@override
Widget build(BuildContext context) {
print("here we are");
print("Server: " + _addr);
final Size screenSize = MediaQuery.of(context).size;
@ -58,6 +66,7 @@ class _InvenTreeLoginSettingsState extends State<InvenTreeLoginSettingsWidget> {
children: <Widget>[
Text("Server"),
new TextFormField(
initialValue: _addr,
decoration: InputDecoration(
hintText: "127.0.0.1:8000",
labelText: "Server:Port",
@ -69,6 +78,7 @@ class _InvenTreeLoginSettingsState extends State<InvenTreeLoginSettingsWidget> {
),
Text("Login Details"),
TextFormField(
initialValue: _user,
decoration: InputDecoration(
hintText: "Username",
labelText: "Username",
@ -79,6 +89,7 @@ class _InvenTreeLoginSettingsState extends State<InvenTreeLoginSettingsWidget> {
}
),
TextFormField(
initialValue: _pass,
obscureText: true,
decoration: InputDecoration(
hintText: "Password",
@ -103,11 +114,27 @@ class _InvenTreeLoginSettingsState extends State<InvenTreeLoginSettingsWidget> {
);
}
void save() {
void load() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
_addr = prefs.getString('server');
_user = prefs.getString('username');
_pass = prefs.getString('password');
// Refresh the widget
setState(() {
});
}
void save() async {
if (_formKey.currentState.validate()) {
_formKey.currentState.save();
// TODO - Save the login settings
SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.setString('server', _addr);
await prefs.setString('username', _user);
await prefs.setString('password', _pass);
}
}
}

@ -144,6 +144,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.2"
shared_preferences:
dependency: "direct main"
description:
name: shared_preferences
url: "https://pub.dartlang.org"
source: hosted
version: "0.5.3+1"
sky_engine:
dependency: transitive
description: flutter
@ -221,3 +228,4 @@ packages:
version: "2.1.16"
sdks:
dart: ">=2.2.0 <3.0.0"
flutter: ">=1.5.0 <2.0.0"

@ -1,5 +1,5 @@
name: inventree_app
description: InvenTree mobile application
name: InvenTree
description: InvenTree stock management
# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
@ -24,6 +24,7 @@ dependencies:
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
http: ^0.12.0+2
shared_preferences: ^0.5.3+1
dev_dependencies:
flutter_test: