Skip to content

Commit 9ac3529

Browse files
authored
Upgrade connectivity plugin version #27
fixes #24
2 parents 629afd4 + b11600f commit 9ac3529

15 files changed

Lines changed: 132 additions & 110 deletions

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ script:
1313
# abort on error
1414
- set -e
1515
- flutter packages get
16-
- flutter format --set-exit-if-changed lib example
16+
- flutter format --set-exit-if-changed -l lib -l 120 example
1717
- flutter analyze lib example
1818
- flutter test --no-pub --coverage
1919
# export coverage

README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,9 @@ A tidy utility to handle offline/online connectivity like a Boss. It provides su
88

99
```yaml
1010
dependencies:
11-
flutter_offline: "^0.2.4"
11+
flutter_offline: "^0.3.0"
1212
```
1313
14-
#### Note for AndroidX Apps
15-
16-
Make sure to point to `0.2.4+1`
17-
1814
### ⚡️ Import
1915
2016
```dart

example/lib/demo_page.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ class DemoPage extends StatelessWidget {
1010

1111
@override
1212
Widget build(BuildContext context) {
13-
return new Scaffold(
14-
appBar: new AppBar(
15-
title: new Text("Offline Demo"),
13+
return Scaffold(
14+
appBar: AppBar(
15+
title: Text("Offline Demo"),
1616
),
1717
body: child,
1818
);

example/lib/main.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ import './widgets/demo_1.dart';
55
import './widgets/demo_2.dart';
66
import './widgets/demo_3.dart';
77

8-
void main() => runApp(new MyApp());
8+
void main() => runApp(MyApp());
99

1010
class MyApp extends StatelessWidget {
1111
@override
1212
Widget build(BuildContext context) {
13-
return new MaterialApp(
13+
return MaterialApp(
1414
title: 'Offline Demo',
15-
theme: new ThemeData.dark(),
15+
theme: ThemeData.dark(),
1616
home: Builder(
1717
builder: (BuildContext context) {
1818
return Column(

example/lib/widgets/demo_1.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ class Demo1 extends StatelessWidget {
3636
height: 12.0,
3737
child: CircularProgressIndicator(
3838
strokeWidth: 2.0,
39-
valueColor:
40-
AlwaysStoppedAnimation<Color>(Colors.white),
39+
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
4140
),
4241
),
4342
],
@@ -51,10 +50,10 @@ class Demo1 extends StatelessWidget {
5150
child: Column(
5251
mainAxisAlignment: MainAxisAlignment.center,
5352
children: <Widget>[
54-
new Text(
53+
Text(
5554
'There are no bottons to push :)',
5655
),
57-
new Text(
56+
Text(
5857
'Just turn off your internet.',
5958
),
6059
],

example/lib/widgets/demo_2.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ class Demo2 extends StatelessWidget {
2626
},
2727
builder: (BuildContext context) {
2828
return Center(
29-
child: new Column(
29+
child: Column(
3030
mainAxisAlignment: MainAxisAlignment.center,
3131
children: <Widget>[
32-
new Text(
32+
Text(
3333
'There are no bottons to push :)',
3434
),
35-
new Text(
35+
Text(
3636
'Just turn off your internet.',
3737
),
3838
],

example/lib/widgets/demo_3.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ class Demo3 extends StatelessWidget {
2525
return child;
2626
},
2727
child: Center(
28-
child: new Column(
28+
child: Column(
2929
mainAxisAlignment: MainAxisAlignment.center,
3030
children: <Widget>[
31-
new Text(
31+
Text(
3232
'There are no bottons to push :)',
3333
),
34-
new Text(
34+
Text(
3535
'Just turn off your internet.',
3636
),
37-
new Text(
37+
Text(
3838
'This one has a bit of a delay.',
3939
),
4040
],

flutter_offline.iml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
<excludeFolder url="file://$MODULE_DIR$/.idea" />
1010
<excludeFolder url="file://$MODULE_DIR$/.pub" />
1111
<excludeFolder url="file://$MODULE_DIR$/build" />
12+
<excludeFolder url="file://$MODULE_DIR$/example/.dart_tool" />
13+
<excludeFolder url="file://$MODULE_DIR$/example/.pub" />
14+
<excludeFolder url="file://$MODULE_DIR$/example/build" />
1215
</content>
1316
<orderEntry type="jdk" jdkName="Android API 25 Platform" jdkType="Android SDK" />
1417
<orderEntry type="sourceFolder" forTests="false" />

lib/src/main.dart

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,12 @@ import 'package:connectivity/connectivity.dart';
44
import 'package:flutter/widgets.dart';
55
import 'package:flutter_offline/src/utils.dart';
66

7-
const kOfflineDebounceDuration = const Duration(seconds: 3);
8-
9-
typedef Widget ConnectivityBuilder(
10-
BuildContext context, ConnectivityResult connectivity, Widget child);
7+
const kOfflineDebounceDuration = Duration(seconds: 3);
118

129
class OfflineBuilder extends StatefulWidget {
1310
factory OfflineBuilder({
1411
Key key,
15-
@required ConnectivityBuilder connectivityBuilder,
12+
@required ValueWidgetBuilder<ConnectivityResult> connectivityBuilder,
1613
Duration debounceDuration = kOfflineDebounceDuration,
1714
WidgetBuilder builder,
1815
Widget child,
@@ -38,14 +35,10 @@ class OfflineBuilder extends StatefulWidget {
3835
this.builder,
3936
this.child,
4037
this.errorBuilder,
41-
}) : assert(
42-
connectivityBuilder != null, 'connectivityBuilder cannot be null'),
38+
}) : assert(connectivityBuilder != null, 'connectivityBuilder cannot be null'),
4339
assert(debounceDuration != null, 'debounceDuration cannot be null'),
44-
assert(
45-
connectivityService != null, 'connectivityService cannot be null'),
46-
assert(
47-
!(builder is WidgetBuilder && child is Widget) &&
48-
!(builder == null && child == null),
40+
assert(connectivityService != null, 'connectivityService cannot be null'),
41+
assert(!(builder is WidgetBuilder && child is Widget) && !(builder == null && child == null),
4942
'You should specify either a builder or a child'),
5043
super(key: key);
5144

@@ -56,7 +49,7 @@ class OfflineBuilder extends StatefulWidget {
5649
final Duration debounceDuration;
5750

5851
/// Used for building the Offline and/or Online UI
59-
final ConnectivityBuilder connectivityBuilder;
52+
final ValueWidgetBuilder<ConnectivityResult> connectivityBuilder;
6053

6154
/// Used for building the child widget
6255
final WidgetBuilder builder;
@@ -78,37 +71,28 @@ class OfflineBuilderState extends State<OfflineBuilder> {
7871
void initState() {
7972
super.initState();
8073

81-
_connectivityStream = Stream.fromFuture(
82-
widget.connectivityService.checkConnectivity(),
83-
).asyncExpand(
84-
(ConnectivityResult data) {
85-
return widget.connectivityService.onConnectivityChanged.transform(
86-
startsWith(data),
87-
);
88-
},
89-
).transform(
90-
debounce(widget.debounceDuration),
91-
);
74+
_connectivityStream = Stream.fromFuture(widget.connectivityService.checkConnectivity())
75+
.asyncExpand((data) => widget.connectivityService.onConnectivityChanged.transform(startsWith(data)))
76+
.transform(debounce(widget.debounceDuration));
9277
}
9378

9479
@override
9580
Widget build(BuildContext context) {
9681
return StreamBuilder<ConnectivityResult>(
9782
stream: _connectivityStream,
98-
builder: (
99-
BuildContext context,
100-
AsyncSnapshot<ConnectivityResult> snapshot,
101-
) {
102-
final child = widget.child ?? widget.builder(context);
83+
builder: (BuildContext context, AsyncSnapshot<ConnectivityResult> snapshot) {
10384
if (!snapshot.hasData && !snapshot.hasError) {
10485
return const SizedBox();
105-
} else if (snapshot.hasError) {
86+
}
87+
88+
if (snapshot.hasError) {
10689
if (widget.errorBuilder != null) {
10790
return widget.errorBuilder(context);
10891
}
10992
throw OfflineBuilderError(snapshot.error);
11093
}
111-
return widget.connectivityBuilder(context, snapshot.data, child);
94+
95+
return widget.connectivityBuilder(context, snapshot.data, widget.child ?? widget.builder(context));
11296
},
11397
);
11498
}

lib/src/utils.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ StreamTransformer<ConnectivityResult, ConnectivityResult> startsWith(
3939
controller = StreamController<ConnectivityResult>(
4040
sync: true,
4141
onListen: () => controller?.add(data),
42-
onPause: ([Future<dynamic> resumeSignal]) =>
43-
subscription.pause(resumeSignal),
42+
onPause: ([Future<dynamic> resumeSignal]) => subscription.pause(resumeSignal),
4443
onResume: () => subscription.resume(),
4544
onCancel: () => subscription.cancel(),
4645
);

0 commit comments

Comments
 (0)