2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-04-28 05:26:47 +00:00

Add a 'login setings' form

This commit is contained in:
Oliver Walters 2019-06-25 21:48:37 +10:00
parent 75306a9ca5
commit e723a70d15
2 changed files with 116 additions and 1 deletions

113
lib/login_settings.dart Normal file
View File

@ -0,0 +1,113 @@
import 'package:flutter/material.dart';
class InvenTreeLoginSettingsWidget extends StatefulWidget {
@override
_InvenTreeLoginSettingsState createState() => _InvenTreeLoginSettingsState();
}
class _InvenTreeLoginSettingsState extends State<InvenTreeLoginSettingsWidget> {
final GlobalKey<FormState> _formKey = new GlobalKey<FormState>();
String _addr;
String _user;
String _pass;
String _validateServer(String value) {
if (value.isEmpty) {
return 'Server cannot be empty';
}
return null;
}
String _validateUsername(String value) {
if (value.isEmpty) {
return 'Username cannot be empty';
}
return null;
}
String _validatePassword(String value) {
if (value.isEmpty) {
return 'Password cannot be empty';
}
return null;
}
@override
Widget build(BuildContext context) {
final Size screenSize = MediaQuery.of(context).size;
return Scaffold(
appBar: AppBar(
title: Text("Login Settings"),
),
body: new Container(
padding: new EdgeInsets.all(20.0),
child: new Form(
key: _formKey,
child: new ListView(
children: <Widget>[
Text("Server"),
new TextFormField(
decoration: InputDecoration(
hintText: "127.0.0.1:8000",
labelText: "Server:Port",
),
validator: _validateServer,
onSaved: (String value) {
_addr = value;
},
),
Text("Login Details"),
TextFormField(
decoration: InputDecoration(
hintText: "Username",
labelText: "Username",
),
validator: _validateUsername,
onSaved: (String value) {
_user = value;
}
),
TextFormField(
obscureText: true,
decoration: InputDecoration(
hintText: "Password",
labelText: "Password",
),
validator: _validatePassword,
onSaved: (String value) {
_pass = value;
},
),
Container(
width: screenSize.width,
child: RaisedButton(
child: Text("Login"),
onPressed: this.save,
)
)
],
)
)
)
);
}
void save() {
if (_formKey.currentState.validate()) {
_formKey.currentState.save();
// TODO - Save the login settings
}
}
}

View File

@ -1,5 +1,7 @@
import 'package:flutter/material.dart';
import 'login_settings.dart';
class InvenTreeSettingsWidget extends StatefulWidget {
// InvenTree settings view
@ -31,6 +33,6 @@ class _InvenTreeSettingsState extends State<InvenTreeSettingsWidget> {
}
void _editServerSettings() {
Navigator.push(context, MaterialPageRoute(builder: (context) => InvenTreeLoginSettingsWidget()));
}
}