createFlutter: automatically create loading screen that switches over to home
This commit is contained in:
parent
73a854d103
commit
0bd793e0e2
|
@ -202,33 +202,39 @@ EOF
|
|||
#########################
|
||||
cat > lib/main.dart <<EOF
|
||||
import 'package:flutter/material.dart';
|
||||
import 'screens/loading.dart';
|
||||
|
||||
void main() => runApp(MyApp());
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
title: '$appName',
|
||||
theme: ThemeData(
|
||||
primarySwatch: Colors.blue,
|
||||
),
|
||||
home: MyHomePage(title: '$appName'),
|
||||
);
|
||||
}
|
||||
void main() {
|
||||
runApp(MaterialApp(
|
||||
theme: ThemeData(
|
||||
primarySwatch: Colors.blue,
|
||||
),
|
||||
home: Loading(),
|
||||
));
|
||||
}
|
||||
|
||||
class MyHomePage extends StatefulWidget {
|
||||
MyHomePage({Key key, this.title}) : super(key: key);
|
||||
final String title;
|
||||
EOF
|
||||
|
||||
####################################
|
||||
## 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
|
||||
_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
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user