Skip to content

Commit 6f138cb

Browse files
committed
chore(example): code clean up
1 parent de01c29 commit 6f138cb

File tree

5 files changed

+49
-105
lines changed

5 files changed

+49
-105
lines changed

example/lib/demo_page.dart

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
import 'package:flutter/material.dart';
22

33
class DemoPage extends StatelessWidget {
4-
const DemoPage({
5-
Key key,
6-
@required this.child,
7-
}) : super(key: key);
4+
const DemoPage({Key key, @required this.child}) : super(key: key);
85

96
final Widget child;
107

118
@override
129
Widget build(BuildContext context) {
1310
return Scaffold(
14-
appBar: AppBar(
15-
title: Text("Offline Demo"),
16-
),
11+
appBar: AppBar(title: Text("Offline Demo")),
1712
body: child,
1813
);
1914
}

example/lib/main.dart

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,41 +13,17 @@ class MyApp extends StatelessWidget {
1313
return MaterialApp(
1414
title: 'Offline Demo',
1515
theme: ThemeData.dark(),
16-
home: Builder(
17-
builder: (BuildContext context) {
18-
return Column(
19-
mainAxisAlignment: MainAxisAlignment.center,
20-
children: <Widget>[
21-
RaisedButton(
22-
child: Text("Demo 1"),
23-
onPressed: () {
24-
navigate(context, Demo1());
25-
},
26-
),
27-
RaisedButton(
28-
child: Text("Demo 2"),
29-
onPressed: () {
30-
navigate(context, Demo2());
31-
},
32-
),
33-
RaisedButton(
34-
child: Text("Demo 3"),
35-
onPressed: () {
36-
navigate(context, Demo3());
37-
},
38-
),
39-
],
40-
);
41-
},
16+
home: Column(
17+
mainAxisAlignment: MainAxisAlignment.center,
18+
children: <Widget>[
19+
RaisedButton(child: Text("Demo 1"), onPressed: () => navigate(context, Demo1())),
20+
RaisedButton(child: Text("Demo 2"), onPressed: () => navigate(context, Demo2())),
21+
RaisedButton(child: Text("Demo 3"), onPressed: () => navigate(context, Demo3())),
22+
],
4223
),
4324
);
4425
}
4526

46-
void navigate(BuildContext context, Widget widget) {
47-
Navigator.of(context).push<void>(
48-
MaterialPageRoute<void>(
49-
builder: (BuildContext context) => DemoPage(child: widget),
50-
),
51-
);
52-
}
27+
void navigate(BuildContext context, Widget widget) =>
28+
Navigator.of(context).push<void>(MaterialPageRoute<void>(builder: (_) => DemoPage(child: widget)));
5329
}

example/lib/widgets/demo_1.dart

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
}

example/lib/widgets/demo_2.dart

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,25 @@ class Demo2 extends StatelessWidget {
55
@override
66
Widget build(BuildContext context) {
77
return OfflineBuilder(
8-
connectivityBuilder: (
9-
BuildContext context,
10-
ConnectivityResult connectivity,
11-
Widget child,
12-
) {
8+
connectivityBuilder: (BuildContext context, ConnectivityResult connectivity, Widget child) {
139
if (connectivity == ConnectivityResult.none) {
1410
return Container(
1511
color: Colors.white,
1612
child: Center(
17-
child: Text(
18-
"Oops, \n\nNow we are Offline!",
19-
style: TextStyle(color: Colors.black),
20-
),
13+
child: Text("Oops, \n\nNow we are Offline!", style: TextStyle(color: Colors.black)),
2114
),
2215
);
23-
} else {
24-
return child;
2516
}
17+
18+
return child;
2619
},
2720
builder: (BuildContext context) {
2821
return Center(
2922
child: Column(
3023
mainAxisAlignment: MainAxisAlignment.center,
3124
children: <Widget>[
32-
Text(
33-
'There are no bottons to push :)',
34-
),
35-
Text(
36-
'Just turn off your internet.',
37-
),
25+
Text('There are no bottons to push :)'),
26+
Text('Just turn off your internet.'),
3827
],
3928
),
4029
);

example/lib/widgets/demo_3.dart

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,25 @@ class Demo3 extends StatelessWidget {
66
Widget build(BuildContext context) {
77
return OfflineBuilder(
88
debounceDuration: Duration.zero,
9-
connectivityBuilder: (
10-
BuildContext context,
11-
ConnectivityResult connectivity,
12-
Widget child,
13-
) {
9+
connectivityBuilder: (BuildContext context, ConnectivityResult connectivity, Widget child) {
1410
if (connectivity == ConnectivityResult.none) {
1511
return Container(
1612
color: Colors.white70,
1713
child: Center(
18-
child: Text(
19-
"Oops, \n\nWe experienced a Delayed Offline!",
20-
style: TextStyle(color: Colors.black),
21-
),
14+
child: Text("Oops, \n\nWe experienced a Delayed Offline!", style: TextStyle(color: Colors.black)),
2215
),
2316
);
2417
}
18+
2519
return child;
2620
},
2721
child: Center(
2822
child: Column(
2923
mainAxisAlignment: MainAxisAlignment.center,
3024
children: <Widget>[
31-
Text(
32-
'There are no bottons to push :)',
33-
),
34-
Text(
35-
'Just turn off your internet.',
36-
),
37-
Text(
38-
'This one has a bit of a delay.',
39-
),
25+
Text('There are no bottons to push :)'),
26+
Text('Just turn off your internet.'),
27+
Text('This one has a bit of a delay.'),
4028
],
4129
),
4230
),

0 commit comments

Comments
 (0)