1
+ import 'package:flutter/foundation.dart' ;
1
2
import 'package:flutter/material.dart' ;
2
3
import 'package:flutter_bloc_pattern/flutter_bloc_pattern.dart' ;
3
4
import 'package:flutter_provider/flutter_provider.dart' ;
4
5
5
6
import 'bloc_with_deps.dart' ;
6
7
import 'counter_bloc.dart' ;
7
8
8
- void main () => runApp (MyApp ());
9
+ void main () {
10
+ RxStreamBuilder .checkStateStreamEnabled = ! kReleaseMode;
11
+ runApp (const MyApp ());
12
+ }
9
13
10
14
class MyApp extends StatelessWidget {
15
+ const MyApp ({Key ? key}) : super (key: key);
16
+
11
17
@override
12
18
Widget build (BuildContext context) {
13
19
return Provider <Dependencies >.factory (
@@ -16,46 +22,48 @@ class MyApp extends StatelessWidget {
16
22
child: MaterialApp (
17
23
title: 'Flutter bloc pattern' ,
18
24
theme: ThemeData .dark (),
19
- home: StartPage (),
25
+ home: const StartPage (),
20
26
),
21
27
);
22
28
}
23
29
}
24
30
25
31
class StartPage extends StatelessWidget {
32
+ const StartPage ({Key ? key}) : super (key: key);
33
+
26
34
@override
27
35
Widget build (BuildContext context) {
28
- return Container (
29
- child: Center (
30
- child: TextButton (
31
- onPressed: () => Navigator .of (context).push (
32
- MaterialPageRoute (
33
- builder: (context) {
34
- return BlocProvider <CounterBloc >(
35
- initBloc: (_) => CounterBloc (),
36
- child: BlocProviders (
37
- blocProviders: [
38
- BlocProvider <Bloc1 >(
39
- initBloc: (context) => Bloc1 (context.get ()),
40
- ),
41
- BlocProvider <Bloc2 >(
42
- initBloc: (context) => Bloc2 (context.bloc ()),
43
- ),
44
- ],
45
- child: MyHomePage (),
46
- ),
47
- );
48
- },
49
- ),
36
+ return Center (
37
+ child: TextButton (
38
+ onPressed: () => Navigator .of (context).push (
39
+ MaterialPageRoute (
40
+ builder: (context) {
41
+ return BlocProvider <CounterBloc >(
42
+ initBloc: (_) => CounterBloc (),
43
+ child: BlocProviders (
44
+ blocProviders: [
45
+ BlocProvider <Bloc1 >(
46
+ initBloc: (context) => Bloc1 (context.get ()),
47
+ ),
48
+ BlocProvider <Bloc2 >(
49
+ initBloc: (context) => Bloc2 (context.bloc ()),
50
+ ),
51
+ ],
52
+ child: const MyHomePage (),
53
+ ),
54
+ );
55
+ },
50
56
),
51
- child: Text ('GO TO HOME' ),
52
57
),
58
+ child: const Text ('GO TO HOME' ),
53
59
),
54
60
);
55
61
}
56
62
}
57
63
58
64
class MyHomePage extends StatefulWidget {
65
+ const MyHomePage ({Key ? key}) : super (key: key);
66
+
59
67
@override
60
68
_MyHomePageState createState () => _MyHomePageState ();
61
69
}
@@ -65,21 +73,22 @@ class _MyHomePageState extends State<MyHomePage> {
65
73
Widget build (BuildContext context) {
66
74
return Scaffold (
67
75
appBar: AppBar (
68
- title: Text ('Home page' ),
76
+ title: const Text ('Home page' ),
69
77
),
70
78
body: Center (
71
79
child: Column (
72
80
mainAxisAlignment: MainAxisAlignment .center,
73
81
children: < Widget > [
74
- Text ('You have pushed the button this many times:' ),
82
+ const Text ('You have pushed the button this many times:' ),
83
+ const SizedBox (height: 8 ),
84
+ const TextCounter1 (),
85
+ const TextCounter2 (),
75
86
const SizedBox (height: 8 ),
76
- TextCounter1 (),
77
- TextCounter2 (),
87
+ const TextBloc1 (),
78
88
const SizedBox (height: 8 ),
79
- TextBloc1 (),
80
89
ElevatedButton (
81
90
onPressed: () => context.bloc <Bloc2 >(),
82
- child: Text ('Access Bloc 2' ),
91
+ child: const Text ('Access Bloc 2' ),
83
92
)
84
93
],
85
94
),
@@ -137,12 +146,14 @@ class IncrementButton extends StatelessWidget {
137
146
return FloatingActionButton (
138
147
onPressed: bloc.increment,
139
148
tooltip: 'Increment' ,
140
- child: Icon (Icons .add),
149
+ child: const Icon (Icons .add),
141
150
);
142
151
}
143
152
}
144
153
145
154
class TextBloc1 extends StatelessWidget {
155
+ const TextBloc1 ({Key ? key}) : super (key: key);
156
+
146
157
@override
147
158
Widget build (BuildContext context) {
148
159
final bloc = context.bloc <Bloc1 >();
0 commit comments