@@ -17,86 +17,97 @@ class HomeScreen extends StatefulWidget {
17
17
class _HomeScreenState extends State <HomeScreen > {
18
18
@override
19
19
Widget build (BuildContext context) {
20
- return Scaffold (
21
- appBar: AppBar (
22
- title: Text (widget.title),
23
- backgroundColor: widget.color,
24
- ),
25
- body: Center (
26
- child: Column (
27
- mainAxisAlignment: MainAxisAlignment .center,
28
- children: < Widget > [
29
- BlocBuilder <InternetCubit , InternetState >(
30
- builder: (context, state) {
31
- if (state is InternetConnected &&
32
- state.connectionType == ConnectionType .Wifi ) {
33
- return const Text ('Wifi' );
34
- } else if (state is InternetConnected &&
35
- state.connectionType == ConnectionType .Mobile ) {
36
- return const Text ('Mobile' );
37
- } else if (state is InternetDisconnected ) {
38
- return const Text ('Disconnected' );
39
- }
40
- return const CircularProgressIndicator ();
41
- },
42
- ),
43
- const Text ('You have pushed the button this many times:' ),
44
- BlocConsumer <CounterCubit , CounterState >(
45
- listener: (context, state) {
46
- if (state.wasIncremented == true ) {
47
- ScaffoldMessenger .of (context).showSnackBar (
48
- const SnackBar (content: Text ('Incremented' )));
49
- } else {
50
- ScaffoldMessenger .of (context).showSnackBar (
51
- const SnackBar (content: Text ('Decremented' )));
52
- }
53
- },
54
- builder: (context, state) {
55
- return Text (
56
- '${state .countValue }' ,
57
- style: Theme .of (context).textTheme.headline4,
58
- );
59
- },
60
- ),
61
- const SizedBox (height: 12 ),
62
- Row (
63
- mainAxisAlignment: MainAxisAlignment .spaceAround,
64
- children: [
65
- FloatingActionButton (
66
- onPressed: () {
67
- BlocProvider .of <CounterCubit >(context).increment ();
68
- },
69
- tooltip: 'Increment' ,
70
- backgroundColor: widget.color,
71
- child: const Icon (Icons .add),
72
- ),
73
- FloatingActionButton (
74
- onPressed: () {
75
- BlocProvider .of <CounterCubit >(context).decrement ();
76
- },
77
- tooltip: 'Decrement' ,
78
- backgroundColor: widget.color,
79
- child: const Icon (Icons .remove),
80
- ),
81
- ],
82
- ),
83
- const SizedBox (height: 24 ),
84
- MaterialButton (
85
- onPressed: () {
86
- Navigator .of (context).pushNamed ('/second' );
87
- },
88
- color: widget.color,
89
- child: const Text ('Go to Second Screen' ),
90
- ),
91
- const SizedBox (height: 24 ),
92
- MaterialButton (
93
- onPressed: () {
94
- Navigator .of (context).pushNamed ('/third' );
95
- },
96
- color: widget.color,
97
- child: const Text ('Go to Third Screen' ),
98
- ),
99
- ],
20
+ return BlocListener <InternetCubit , InternetState >(
21
+ listener: (context, state) {
22
+ if (state is InternetConnected &&
23
+ state.connectionType == ConnectionType .Wifi ) {
24
+ BlocProvider .of <CounterCubit >(context).increment ();
25
+ } else if (state is InternetConnected &&
26
+ state.connectionType == ConnectionType .Mobile ) {
27
+ BlocProvider .of <CounterCubit >(context).decrement ();
28
+ }
29
+ },
30
+ child: Scaffold (
31
+ appBar: AppBar (
32
+ title: Text (widget.title),
33
+ backgroundColor: widget.color,
34
+ ),
35
+ body: Center (
36
+ child: Column (
37
+ mainAxisAlignment: MainAxisAlignment .center,
38
+ children: < Widget > [
39
+ BlocBuilder <InternetCubit , InternetState >(
40
+ builder: (context, state) {
41
+ if (state is InternetConnected &&
42
+ state.connectionType == ConnectionType .Wifi ) {
43
+ return const Text ('Wifi' );
44
+ } else if (state is InternetConnected &&
45
+ state.connectionType == ConnectionType .Mobile ) {
46
+ return const Text ('Mobile' );
47
+ } else if (state is InternetDisconnected ) {
48
+ return const Text ('Disconnected' );
49
+ }
50
+ return const CircularProgressIndicator ();
51
+ },
52
+ ),
53
+ const Text ('You have pushed the button this many times:' ),
54
+ BlocConsumer <CounterCubit , CounterState >(
55
+ listener: (context, state) {
56
+ if (state.wasIncremented == true ) {
57
+ ScaffoldMessenger .of (context).showSnackBar (
58
+ const SnackBar (content: Text ('Incremented' )));
59
+ } else {
60
+ ScaffoldMessenger .of (context).showSnackBar (
61
+ const SnackBar (content: Text ('Decremented' )));
62
+ }
63
+ },
64
+ builder: (context, state) {
65
+ return Text (
66
+ '${state .countValue }' ,
67
+ style: Theme .of (context).textTheme.headline4,
68
+ );
69
+ },
70
+ ),
71
+ const SizedBox (height: 12 ),
72
+ Row (
73
+ mainAxisAlignment: MainAxisAlignment .spaceAround,
74
+ children: [
75
+ FloatingActionButton (
76
+ onPressed: () {
77
+ BlocProvider .of <CounterCubit >(context).increment ();
78
+ },
79
+ tooltip: 'Increment' ,
80
+ backgroundColor: widget.color,
81
+ child: const Icon (Icons .add),
82
+ ),
83
+ FloatingActionButton (
84
+ onPressed: () {
85
+ BlocProvider .of <CounterCubit >(context).decrement ();
86
+ },
87
+ tooltip: 'Decrement' ,
88
+ backgroundColor: widget.color,
89
+ child: const Icon (Icons .remove),
90
+ ),
91
+ ],
92
+ ),
93
+ const SizedBox (height: 24 ),
94
+ MaterialButton (
95
+ onPressed: () {
96
+ Navigator .of (context).pushNamed ('/second' );
97
+ },
98
+ color: widget.color,
99
+ child: const Text ('Go to Second Screen' ),
100
+ ),
101
+ const SizedBox (height: 24 ),
102
+ MaterialButton (
103
+ onPressed: () {
104
+ Navigator .of (context).pushNamed ('/third' );
105
+ },
106
+ color: widget.color,
107
+ child: const Text ('Go to Third Screen' ),
108
+ ),
109
+ ],
110
+ ),
100
111
),
101
112
),
102
113
);
0 commit comments