Welcome flow sketch and welcome page added.

This commit is contained in:
sfigato 2019-08-21 21:46:07 -03:00
parent 05ce295fb4
commit 849bdbb881
Signed by: blallo
GPG Key ID: 0CBE577C9B72DC3F
3 changed files with 215 additions and 5 deletions

View File

@ -1,11 +1,14 @@
import 'package:flutter/material.dart';
import 'ui/main_page.dart';
import 'ui/welcome_page.dart';
import 'ui/credentials_form.dart';
import 'ui/server_form.dart';
import 'ui/dialog.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
final title = 'Welcome page test';
final title = 'BotZ';
@override
Widget build(BuildContext context) {
@ -15,10 +18,13 @@ class MyApp extends StatelessWidget {
primarySwatch: Colors.green,
dialogTheme: baseDialogTheme,
),
home: Scaffold(
appBar: AppBar(title: Text(title)),
body: ServerForm(),
));
initialRoute: "/",
routes: {
"/": (context) => HomePage(nextRoute: "/welcome"),
"/welcome": (context) => WelcomePage(nextRoute: "/settings/server"),
"/settings/server": (context) => ServerForm(defaultNextRoute: "/settings/credentials"),
"/settings/credentials": (context) => CredentialsForm(defaultNextRoute: "/"),
});
}
}

147
lib/ui/main_page.dart Normal file
View File

@ -0,0 +1,147 @@
import 'package:flutter/material.dart';
import 'package:logger/logger.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'dart:async';
var log = Logger();
class _DataState {
_DataState(
{this.userPresent = false,
this.passPresent = false,
this.zServerPresent = false,
this.botZServerPresent = false});
bool userPresent;
bool passPresent;
bool zServerPresent;
bool botZServerPresent;
bool all() {
assert(userPresent != null);
assert(passPresent != null);
assert(zServerPresent != null);
assert(botZServerPresent != null);
var result =
userPresent && passPresent && zServerPresent && botZServerPresent;
return result;
}
String toString() {
return "\tuser: $userPresent\n\tpass: $passPresent\n\tzServer: $zServerPresent\n\tbotZServer: $botZServerPresent";
}
}
class HomePage extends StatefulWidget {
HomePage(
{@required this.nextRoute,
this.timeout = const Duration(seconds: 1),
Key key})
: assert(nextRoute != null),
super(key: key);
final String nextRoute;
final Duration timeout;
HomePageState createState() => HomePageState();
}
class HomePageState extends State<HomePage> {
_DataState status = _DataState();
bool _retrieved = false;
bool _waitingForWelcome = false;
String title = "BotZ";
Future<void> _retriveStateData() async {
var persistence = await SharedPreferences.getInstance();
var stateFromPersistence = {
"user": (persistence.getString("username") != null) ? true : false,
"pass": (persistence.getString("password") != null) ? true : false,
"zAddr": (persistence.getString("zAddress") != null) ? true : false,
"botZAddr": (persistence.getString("botZAddress") != null) ? true : false,
};
log.d("State from persistence: ${stateFromPersistence.toString()}");
setState(() {
status.userPresent = stateFromPersistence["user"];
status.passPresent = stateFromPersistence["pass"];
status.zServerPresent = stateFromPersistence["zAddr"];
status.botZServerPresent = stateFromPersistence["botZAddr"];
_retrieved = true;
});
}
@override
void initState() {
super.initState();
_retriveStateData();
}
bool _checkData() {
log.d("State: ${status.toString()}");
if (status.all()) {
log.d("Necessary data is present");
return true;
}
log.d("Necessary data is MISSING");
return false;
}
void _goToNextPage() {
Navigator.pushReplacementNamed(context, widget.nextRoute);
}
Future<void> _cleanState() async {
var persistence = await SharedPreferences.getInstance();
persistence.setString("username", null);
persistence.setString("password", null);
persistence.setString("zAddress", null);
persistence.setString("botZAddress", null);
setState(() {
status.userPresent = false;
status.passPresent = false;
status.zServerPresent = false;
status.botZServerPresent = false;
});
}
Widget mainView() {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
RaisedButton(onPressed: _cleanState, child: Text("Clean state")),
Column(children: <Widget>[
Text("Username: ${status.userPresent}"),
Text("Password: ${status.passPresent}"),
Text("Z Address: ${status.zServerPresent}"),
Text("BotZ Address: ${status.botZServerPresent}"),
])
],
));
}
Widget _body() {
log.d("Retrieved: $_retrieved");
if (_retrieved) {
if (_checkData()) {
log.d("Main body");
return mainView();
} else {
if (!_waitingForWelcome) {
log.d("Go to ask the user for the data...");
Future.delayed(widget.timeout, _goToNextPage);
setState(() {
_waitingForWelcome = true;
});
}
}
}
return CircularProgressIndicator();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text(title)),
body: _body(),
);
}
}

57
lib/ui/welcome_page.dart Normal file
View File

@ -0,0 +1,57 @@
import 'package:flutter/material.dart';
import 'package:logger/logger.dart';
import 'package:flutter/services.dart';
var log = Logger();
class WelcomePage extends StatefulWidget {
WelcomePage(
{@required this.nextRoute,
this.timeout = const Duration(seconds: 5),
Key key})
: assert(nextRoute != null),
super(key: key);
final String nextRoute;
final Duration timeout;
WelcomePageState createState() => WelcomePageState();
}
class WelcomePageState extends State<WelcomePage> {
void _goToNext() {
Navigator.pushReplacementNamed(context, widget.nextRoute);
}
@override
void initState() {
log.d("Initing WelcomePage...");
super.initState();
Future.delayed(widget.timeout, _goToNext);
}
@override
Widget build(BuildContext build) {
SystemChrome.setEnabledSystemUIOverlays([]);
log.d("Building WelcomePage...");
return Container(
color: Colors.green[300],
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Center(
child: Text("Welcome to BotZ",
textAlign: TextAlign.center,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 15.0,
color: Colors.blue[700]))),
FlatButton(
color: Colors.green[350],
textColor: Colors.black,
padding: EdgeInsets.all(8.0),
splashColor: Colors.greenAccent,
child: Text("Go"),
onPressed: _goToNext)
]));
}
}