-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathmaterial_app_example.dart
179 lines (168 loc) · 4.42 KB
/
material_app_example.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_storyboard/flutter_storyboard.dart';
import 'package:random_color/random_color.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return StoryBoard.material(
enabled: true,
crossAxisCount: 7,
screenSize: Size(400, 700),
customScreens: [
for (var i = 0; i < 25; i++)
_generateScreen(
title: Text('Screen$i'),
color: RandomColor(i + 25).randomColor(),
),
],
customRoutes: [
RouteSettings(name: '/about'),
RouteSettings(name: '/counter'),
RouteSettings(name: '/screen_2'),
RouteSettings(name: '/screen_5'),
RouteSettings(
name: '/screen_8',
arguments: <String, dynamic>{"id": 1234},
),
],
child: MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter Storyboard Example',
theme: ThemeData.light().copyWith(
visualDensity: VisualDensity.adaptivePlatformDensity,
),
darkTheme: ThemeData.dark().copyWith(
visualDensity: VisualDensity.adaptivePlatformDensity,
),
themeMode: ThemeMode.light,
// home: HomeScreen(),
initialRoute: '/settings',
routes: {
'/': (_) => HomeScreen(),
'/counter': (_) => CounterScreen(),
'/settings': (_) => SettingsScreen(),
for (var i = 0; i < 25; i++)
'/screen_$i': (_) => _generateScreen(
title: Text('Screen$i'),
color: RandomColor(i).randomColor(),
),
},
onGenerateRoute: (settings) {
return MaterialPageRoute(
settings: settings,
builder: (context) {
if (settings.name == '/about') return AboutScreen();
return UnknownScreen();
},
);
},
),
);
}
}
Widget _generateScreen({
Text title,
FloatingActionButton fab,
Color color,
}) {
return Builder(
builder: (context) {
final Map<String, dynamic> args =
ModalRoute.of(context).settings.arguments;
return Scaffold(
appBar: AppBar(title: title),
backgroundColor: color,
body: args == null ? null : Center(child: Text(args.toString())),
floatingActionButton: fab,
);
},
);
}
class HomeScreen extends StatelessWidget {
const HomeScreen({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
final _size = MediaQuery.of(context).size;
return Scaffold(
appBar: AppBar(
title: Text('Home Screen'),
),
body: Center(
child: Text(_size.toString()),
),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.info),
onPressed: () {
Navigator.of(context).push(MaterialPageRoute(
builder: (_) => SettingsScreen(),
));
},
),
);
}
}
class CounterScreen extends StatefulWidget {
const CounterScreen({Key key}) : super(key: key);
@override
_CounterScreenState createState() => _CounterScreenState();
}
class _CounterScreenState extends State<CounterScreen> {
int _counter = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Counter Example'),
),
body: Center(
child: Text('Counter: $_counter'),
),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add),
onPressed: () {
if (mounted)
setState(() {
_counter++;
});
},
),
);
}
}
class SettingsScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Settings'),
),
backgroundColor: Colors.blue.shade300,
);
}
}
class AboutScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('About'),
),
backgroundColor: Colors.purple.shade300,
);
}
}
class UnknownScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('404'),
),
backgroundColor: Colors.red.shade300,
);
}
}