createFlutter: automatically create loading screen that switches over to home

This commit is contained in:
gutmet 2020-05-22 15:13:11 +02:00
parent 73a854d103
commit 0bd793e0e2

View File

@ -202,31 +202,37 @@ EOF
######################### #########################
cat > lib/main.dart <<EOF cat > lib/main.dart <<EOF
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'screens/loading.dart';
void main() => runApp(MyApp()); void main() {
runApp(MaterialApp(
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: '$appName',
theme: ThemeData( theme: ThemeData(
primarySwatch: Colors.blue, primarySwatch: Colors.blue,
), ),
home: MyHomePage(title: '$appName'), home: Loading(),
); ));
}
} }
class MyHomePage extends StatefulWidget { EOF
MyHomePage({Key key, this.title}) : super(key: key);
final String title; ####################################
## create loading and home screen ##
####################################
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 @override
_MyHomePageState createState() => _MyHomePageState(); _HomeState createState() => _HomeState();
} }
class _MyHomePageState extends State<MyHomePage> { class _HomeState extends State<Home> {
int state = 1; int state = 1;
void _changeState(int s) { void _changeState(int s) {
@ -241,7 +247,7 @@ class _MyHomePageState extends State<MyHomePage> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text(widget.title), title: Text(Home.title),
actions: <Widget>[ actions: <Widget>[
PopupMenuButton<String>( PopupMenuButton<String>(
onSelected: (String value) => handleClick(context, value), onSelected: (String value) => handleClick(context, value),
@ -268,10 +274,48 @@ class _MyHomePageState extends State<MyHomePage> {
void handleClick(BuildContext context, String value) { void handleClick(BuildContext context, String value) {
switch (value) { switch (value) {
case 'About': 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 EOF