@@ -5,12 +5,8 @@ class Demo1 extends StatelessWidget {
55 @override
66 Widget build (BuildContext context) {
77 return OfflineBuilder (
8- connectivityBuilder: (
9- BuildContext context,
10- ConnectivityResult connectivity,
11- Widget child,
12- ) {
13- final bool connected = connectivity != ConnectivityResult .none;
8+ connectivityBuilder: (BuildContext context, ConnectivityResult connectivity, Widget child) {
9+ final bool isConnected = connectivity != ConnectivityResult .none;
1410 return Stack (
1511 fit: StackFit .expand,
1612 children: [
@@ -21,26 +17,10 @@ class Demo1 extends StatelessWidget {
2117 right: 0.0 ,
2218 child: AnimatedContainer (
2319 duration: const Duration (milliseconds: 350 ),
24- color: connected ? Color (0xFF00EE44 ) : Color (0xFFEE4400 ),
20+ color: isConnected ? Color (0xFF00EE44 ) : Color (0xFFEE4400 ),
2521 child: AnimatedSwitcher (
2622 duration: const Duration (milliseconds: 350 ),
27- child: connected
28- ? Text ('ONLINE' )
29- : Row (
30- mainAxisAlignment: MainAxisAlignment .center,
31- children: < Widget > [
32- Text ('OFFLINE' ),
33- SizedBox (width: 8.0 ),
34- SizedBox (
35- width: 12.0 ,
36- height: 12.0 ,
37- child: CircularProgressIndicator (
38- strokeWidth: 2.0 ,
39- valueColor: AlwaysStoppedAnimation <Color >(Colors .white),
40- ),
41- ),
42- ],
43- ),
23+ child: isConnected ? Text ('ONLINE' ) : _OfflineWidget (),
4424 ),
4525 ),
4626 ),
@@ -50,14 +30,30 @@ class Demo1 extends StatelessWidget {
5030 child: Column (
5131 mainAxisAlignment: MainAxisAlignment .center,
5232 children: < Widget > [
53- Text (
54- 'There are no bottons to push :)' ,
55- ),
56- Text (
57- 'Just turn off your internet.' ,
58- ),
33+ Text ('There are no bottons to push :)' ),
34+ Text ('Just turn off your internet.' ),
5935 ],
6036 ),
6137 );
6238 }
6339}
40+
41+ class _OfflineWidget extends StatelessWidget {
42+ const _OfflineWidget ({Key key}) : super (key: key);
43+
44+ @override
45+ Widget build (BuildContext context) {
46+ return Row (
47+ mainAxisAlignment: MainAxisAlignment .center,
48+ children: < Widget > [
49+ Text ('OFFLINE' ),
50+ SizedBox (width: 8.0 ),
51+ SizedBox (
52+ width: 12.0 ,
53+ height: 12.0 ,
54+ child: CircularProgressIndicator (strokeWidth: 2.0 , valueColor: AlwaysStoppedAnimation <Color >(Colors .white)),
55+ ),
56+ ],
57+ );
58+ }
59+ }
0 commit comments