aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgutmet <me.git@gutmet.org>2020-05-22 15:13:11 +0200
committergutmet <me.git@gutmet.org>2020-05-22 15:13:11 +0200
commit0bd793e0e202f3e3d8ce81965e3e2c21a74c887b (patch)
tree903082e47e84a5008546666e6ea52de4b7bd0feb
parent73a854d103b0c531c3b38192a0e4651f404a2854 (diff)
downloadsnippets-0bd793e0e202f3e3d8ce81965e3e2c21a74c887b.tar.gz
createFlutter: automatically create loading screen that switches over to home
-rwxr-xr-xcreateFlutter86
1 files changed, 65 insertions, 21 deletions
diff --git a/createFlutter b/createFlutter
index 889564a..1a1d488 100755
--- a/createFlutter
+++ b/createFlutter
@@ -202,33 +202,39 @@ EOF
#########################
cat > lib/main.dart <<EOF
import 'package:flutter/material.dart';
+import 'screens/loading.dart';
+
+void main() {
+ runApp(MaterialApp(
+ theme: ThemeData(
+ primarySwatch: Colors.blue,
+ ),
+ home: Loading(),
+ ));
+}
-void main() => runApp(MyApp());
+EOF
-class MyApp extends StatelessWidget {
- @override
- Widget build(BuildContext context) {
- return MaterialApp(
- title: '$appName',
- theme: ThemeData(
- primarySwatch: Colors.blue,
- ),
- home: MyHomePage(title: '$appName'),
- );
- }
-}
+####################################
+## create loading and home screen ##
+####################################
-class MyHomePage extends StatefulWidget {
- MyHomePage({Key key, this.title}) : super(key: key);
- final String title;
+mkdir lib/screens
+
+cat > lib/screens/home.dart <<EOF
+import 'package:flutter/material.dart';
+
+class Home extends StatefulWidget {
+ Home({Key key}) : super(key: key);
+ static const title = '$appName';
@override
- _MyHomePageState createState() => _MyHomePageState();
+ _HomeState createState() => _HomeState();
}
-class _MyHomePageState extends State<MyHomePage> {
+class _HomeState extends State<Home> {
int state = 1;
-
+
void _changeState(int s) {
setState(() {
state = s;
@@ -241,7 +247,7 @@ class _MyHomePageState extends State<MyHomePage> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
- title: Text(widget.title),
+ title: Text(Home.title),
actions: <Widget>[
PopupMenuButton<String>(
onSelected: (String value) => handleClick(context, value),
@@ -268,10 +274,48 @@ class _MyHomePageState extends State<MyHomePage> {
void handleClick(BuildContext context, String value) {
switch (value) {
case 'About':
- showLicensePage(context: context, applicationName: widget.title);
+ showLicensePage(context: context, applicationName: Home.title);
}
}
}
+
+EOF
+
+
+cat > lib/screens/loading.dart <<EOF
+import 'package:flutter/material.dart';
+import 'package:shared_preferences/shared_preferences.dart';
+import 'home.dart';
+
+class Loading extends StatefulWidget {
+ @override
+ _LoadingState createState() => _LoadingState();
+}
+
+class _LoadingState extends State<Loading> {
+ void load() async {
+ await Future.delayed(Duration.zero, () {});
+ // load some stuff here and await results
+ Navigator.pushReplacement(context,
+ MaterialPageRoute(builder: (context) => Home()));
+ }
+
+ @override
+ void initState() {
+ super.initState();
+ load();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ return Scaffold(
+ body: SafeArea(
+ child: Text("Loading..."),
+ ),
+ );
+ }
+}
+
EOF