1+ import 'package:flutter/foundation.dart' ;
12import 'package:flutter/material.dart' ;
23import 'package:flutter_bloc_pattern/flutter_bloc_pattern.dart' ;
34import 'package:flutter_provider/flutter_provider.dart' ;
45
56import 'bloc_with_deps.dart' ;
67import 'counter_bloc.dart' ;
78
8- void main () => runApp (MyApp ());
9+ void main () {
10+ RxStreamBuilder .checkStateStreamEnabled = ! kReleaseMode;
11+ runApp (const MyApp ());
12+ }
913
1014class MyApp extends StatelessWidget {
15+ const MyApp ({Key ? key}) : super (key: key);
16+
1117 @override
1218 Widget build (BuildContext context) {
1319 return Provider <Dependencies >.factory (
@@ -16,46 +22,48 @@ class MyApp extends StatelessWidget {
1622 child: MaterialApp (
1723 title: 'Flutter bloc pattern' ,
1824 theme: ThemeData .dark (),
19- home: StartPage (),
25+ home: const StartPage (),
2026 ),
2127 );
2228 }
2329}
2430
2531class StartPage extends StatelessWidget {
32+ const StartPage ({Key ? key}) : super (key: key);
33+
2634 @override
2735 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+ },
5056 ),
51- child: Text ('GO TO HOME' ),
5257 ),
58+ child: const Text ('GO TO HOME' ),
5359 ),
5460 );
5561 }
5662}
5763
5864class MyHomePage extends StatefulWidget {
65+ const MyHomePage ({Key ? key}) : super (key: key);
66+
5967 @override
6068 _MyHomePageState createState () => _MyHomePageState ();
6169}
@@ -65,21 +73,22 @@ class _MyHomePageState extends State<MyHomePage> {
6573 Widget build (BuildContext context) {
6674 return Scaffold (
6775 appBar: AppBar (
68- title: Text ('Home page' ),
76+ title: const Text ('Home page' ),
6977 ),
7078 body: Center (
7179 child: Column (
7280 mainAxisAlignment: MainAxisAlignment .center,
7381 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 (),
7586 const SizedBox (height: 8 ),
76- TextCounter1 (),
77- TextCounter2 (),
87+ const TextBloc1 (),
7888 const SizedBox (height: 8 ),
79- TextBloc1 (),
8089 ElevatedButton (
8190 onPressed: () => context.bloc <Bloc2 >(),
82- child: Text ('Access Bloc 2' ),
91+ child: const Text ('Access Bloc 2' ),
8392 )
8493 ],
8594 ),
@@ -137,12 +146,14 @@ class IncrementButton extends StatelessWidget {
137146 return FloatingActionButton (
138147 onPressed: bloc.increment,
139148 tooltip: 'Increment' ,
140- child: Icon (Icons .add),
149+ child: const Icon (Icons .add),
141150 );
142151 }
143152}
144153
145154class TextBloc1 extends StatelessWidget {
155+ const TextBloc1 ({Key ? key}) : super (key: key);
156+
146157 @override
147158 Widget build (BuildContext context) {
148159 final bloc = context.bloc <Bloc1 >();
0 commit comments