2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-05-11 19:53:03 +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

View File

@ -1,5 +1,5 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
class InvenTreeLoginSettingsWidget extends StatefulWidget { class InvenTreeLoginSettingsWidget extends StatefulWidget {
@ -41,8 +41,16 @@ class _InvenTreeLoginSettingsState extends State<InvenTreeLoginSettingsWidget> {
return null; return null;
} }
@override
void initState() {
load();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
print("here we are");
print("Server: " + _addr);
final Size screenSize = MediaQuery.of(context).size; final Size screenSize = MediaQuery.of(context).size;
@ -58,6 +66,7 @@ class _InvenTreeLoginSettingsState extends State<InvenTreeLoginSettingsWidget> {
children: <Widget>[ children: <Widget>[
Text("Server"), Text("Server"),
new TextFormField( new TextFormField(
initialValue: _addr,
decoration: InputDecoration( decoration: InputDecoration(
hintText: "127.0.0.1:8000", hintText: "127.0.0.1:8000",
labelText: "Server:Port", labelText: "Server:Port",
@ -69,6 +78,7 @@ class _InvenTreeLoginSettingsState extends State<InvenTreeLoginSettingsWidget> {
), ),
Text("Login Details"), Text("Login Details"),
TextFormField( TextFormField(
initialValue: _user,
decoration: InputDecoration( decoration: InputDecoration(
hintText: "Username", hintText: "Username",
labelText: "Username", labelText: "Username",
@ -79,6 +89,7 @@ class _InvenTreeLoginSettingsState extends State<InvenTreeLoginSettingsWidget> {
} }
), ),
TextFormField( TextFormField(
initialValue: _pass,
obscureText: true, obscureText: true,
decoration: InputDecoration( decoration: InputDecoration(
hintText: "Password", 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()) { if (_formKey.currentState.validate()) {
_formKey.currentState.save(); _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);
} }
} }
} }

View File

@ -144,6 +144,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.2" 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: sky_engine:
dependency: transitive dependency: transitive
description: flutter description: flutter
@ -221,3 +228,4 @@ packages:
version: "2.1.16" version: "2.1.16"
sdks: sdks:
dart: ">=2.2.0 <3.0.0" dart: ">=2.2.0 <3.0.0"
flutter: ">=1.5.0 <2.0.0"

View File

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