diff --git a/lib/login_settings.dart b/lib/login_settings.dart index fd19ab5c..f143438e 100644 --- a/lib/login_settings.dart +++ b/lib/login_settings.dart @@ -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 { 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 { children: [ 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 { ), Text("Login Details"), TextFormField( + initialValue: _user, decoration: InputDecoration( hintText: "Username", labelText: "Username", @@ -79,6 +89,7 @@ class _InvenTreeLoginSettingsState extends State { } ), TextFormField( + initialValue: _pass, obscureText: true, decoration: InputDecoration( hintText: "Password", @@ -103,11 +114,27 @@ class _InvenTreeLoginSettingsState extends State { ); } - 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); } } } \ No newline at end of file diff --git a/pubspec.lock b/pubspec.lock index 593bf706..27775ead 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -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" diff --git a/pubspec.yaml b/pubspec.yaml index d0791b30..d2861c89 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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: