Improve server form.
This commit is contained in:
parent
4e7bec0f93
commit
05ce295fb4
|
@ -1,5 +1,6 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:logger/logger.dart';
|
import 'package:logger/logger.dart';
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
import 'dialog.dart';
|
import 'dialog.dart';
|
||||||
|
@ -8,18 +9,22 @@ import '../utils/verify_server.dart';
|
||||||
final log = Logger();
|
final log = Logger();
|
||||||
|
|
||||||
class ServerForm extends StatefulWidget {
|
class ServerForm extends StatefulWidget {
|
||||||
ServerForm({Key key}) : super(key: key);
|
ServerForm({@required this.defaultNextRoute, Key key}) : super(key: key);
|
||||||
|
final String title = "Server data";
|
||||||
|
final String defaultNextRoute;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_ServerFormState createState() => _ServerFormState();
|
_ServerFormState createState() => _ServerFormState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _ServerFormState extends State<ServerForm> {
|
class _ServerFormState extends State<ServerForm> {
|
||||||
|
static String title = "Server info";
|
||||||
Uri zAddress;
|
Uri zAddress;
|
||||||
Uri botZAddress;
|
Uri botZAddress;
|
||||||
bool _autoValidate = false;
|
bool _autoValidate = false;
|
||||||
bool _disableFields = false;
|
bool _disableFields = false;
|
||||||
final _serverFormKey = GlobalKey<FormState>();
|
final _serverFormKey = GlobalKey<FormState>();
|
||||||
|
final _scaffoldKey = GlobalKey<ScaffoldState>();
|
||||||
|
|
||||||
final zController = TextEditingController();
|
final zController = TextEditingController();
|
||||||
final botZController = TextEditingController();
|
final botZController = TextEditingController();
|
||||||
|
@ -69,18 +74,30 @@ class _ServerFormState extends State<ServerForm> {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<String> getNextRoute() async {
|
||||||
|
var persistence = await SharedPreferences.getInstance();
|
||||||
|
String nextRoute = persistence.getString("nextRoute");
|
||||||
|
if (nextRoute != null) {
|
||||||
|
log.d("nextRoute: $nextRoute");
|
||||||
|
return nextRoute;
|
||||||
|
}
|
||||||
|
log.d("defaultNextRoute: ${widget.defaultNextRoute}");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> _onPressed() async {
|
Future<void> _onPressed() async {
|
||||||
log.d("Button pressed");
|
log.d("Button pressed");
|
||||||
|
var persistence = await SharedPreferences.getInstance();
|
||||||
setState(() {
|
setState(() {
|
||||||
_disableFields = true;
|
_disableFields = true;
|
||||||
});
|
});
|
||||||
Scaffold.of(context).showSnackBar(this.showProgress());
|
_scaffoldKey.currentState.showSnackBar(this.showProgress());
|
||||||
if (!_serverFormKey.currentState.validate()) {
|
if (!_serverFormKey.currentState.validate()) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_autoValidate = true;
|
_autoValidate = true;
|
||||||
_disableFields = false;
|
_disableFields = false;
|
||||||
});
|
});
|
||||||
Scaffold.of(context).hideCurrentSnackBar();
|
_scaffoldKey.currentState.hideCurrentSnackBar();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,7 +118,7 @@ class _ServerFormState extends State<ServerForm> {
|
||||||
setState(() {
|
setState(() {
|
||||||
_disableFields = false;
|
_disableFields = false;
|
||||||
});
|
});
|
||||||
Scaffold.of(context).hideCurrentSnackBar();
|
_scaffoldKey.currentState.hideCurrentSnackBar();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!resp) {
|
if (!resp) {
|
||||||
|
@ -111,15 +128,19 @@ class _ServerFormState extends State<ServerForm> {
|
||||||
"The BotZ server does not target the provided Z server."));
|
"The BotZ server does not target the provided Z server."));
|
||||||
} else {
|
} else {
|
||||||
_serverFormKey.currentState.save();
|
_serverFormKey.currentState.save();
|
||||||
// TODO: go to the next window.
|
persistence.setString("zAddress", this.zAddress.toString());
|
||||||
|
persistence.setString("botZAddress", this.botZAddress.toString());
|
||||||
|
String nextRoute = await getNextRoute();
|
||||||
|
if (nextRoute == null) {
|
||||||
|
nextRoute = widget.defaultNextRoute;
|
||||||
|
}
|
||||||
|
Navigator.pushNamed(context, nextRoute);
|
||||||
}
|
}
|
||||||
|
|
||||||
log.d("Done");
|
log.d("Done");
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
Form theForm() => Form(
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Form(
|
|
||||||
key: _serverFormKey,
|
key: _serverFormKey,
|
||||||
child: Column(children: <Widget>[
|
child: Column(children: <Widget>[
|
||||||
TextFormField(
|
TextFormField(
|
||||||
|
@ -149,5 +170,10 @@ class _ServerFormState extends State<ServerForm> {
|
||||||
),
|
),
|
||||||
]),
|
]),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
key: _scaffoldKey, appBar: AppBar(title: Text(title)), body: theForm());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user