jogboms / flutter_offline

Compare 3ebf57a ... +5 ... b11600f

Coverage Reach
main.dart utils.dart

No flags found

Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.

e.g., #unittest #integration

#production #enterprise

#frontend #backend

Learn more about Codecov Flags here.


@@ -4,15 +4,12 @@
Loading
4 4
import 'package:flutter/widgets.dart';
5 5
import 'package:flutter_offline/src/utils.dart';
6 6
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);
11 8
12 9
class OfflineBuilder extends StatefulWidget {
13 10
  factory OfflineBuilder({
14 11
    Key key,
15 -
    @required ConnectivityBuilder connectivityBuilder,
12 +
    @required ValueWidgetBuilder<ConnectivityResult> connectivityBuilder,
16 13
    Duration debounceDuration = kOfflineDebounceDuration,
17 14
    WidgetBuilder builder,
18 15
    Widget child,
@@ -38,14 +35,10 @@
Loading
38 35
    this.builder,
39 36
    this.child,
40 37
    this.errorBuilder,
41 -
  })  : assert(
42 -
            connectivityBuilder != null, 'connectivityBuilder cannot be null'),
38 +
  })  : assert(connectivityBuilder != null, 'connectivityBuilder cannot be null'),
43 39
        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),
49 42
            'You should specify either a builder or a child'),
50 43
        super(key: key);
51 44
@@ -56,7 +49,7 @@
Loading
56 49
  final Duration debounceDuration;
57 50
58 51
  /// Used for building the Offline and/or Online UI
59 -
  final ConnectivityBuilder connectivityBuilder;
52 +
  final ValueWidgetBuilder<ConnectivityResult> connectivityBuilder;
60 53
61 54
  /// Used for building the child widget
62 55
  final WidgetBuilder builder;
@@ -78,37 +71,28 @@
Loading
78 71
  void initState() {
79 72
    super.initState();
80 73
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));
92 77
  }
93 78
94 79
  @override
95 80
  Widget build(BuildContext context) {
96 81
    return StreamBuilder<ConnectivityResult>(
97 82
      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) {
103 84
        if (!snapshot.hasData && !snapshot.hasError) {
104 85
          return const SizedBox();
105 -
        } else if (snapshot.hasError) {
86 +
        }
87 +
88 +
        if (snapshot.hasError) {
106 89
          if (widget.errorBuilder != null) {
107 90
            return widget.errorBuilder(context);
108 91
          }
109 92
          throw OfflineBuilderError(snapshot.error);
110 93
        }
111 -
        return widget.connectivityBuilder(context, snapshot.data, child);
94 +
95 +
        return widget.connectivityBuilder(context, snapshot.data, widget.child ?? widget.builder(context));
112 96
      },
113 97
    );
114 98
  }

@@ -39,8 +39,7 @@
Loading
39 39
      controller = StreamController<ConnectivityResult>(
40 40
        sync: true,
41 41
        onListen: () => controller?.add(data),
42 -
        onPause: ([Future<dynamic> resumeSignal]) =>
43 -
            subscription.pause(resumeSignal),
42 +
        onPause: ([Future<dynamic> resumeSignal]) => subscription.pause(resumeSignal),
44 43
        onResume: () => subscription.resume(),
45 44
        onCancel: () => subscription.cancel(),
46 45
      );

Everything is accounted for!

No changes detected that need to be reviewed.
What changes does Codecov check for?
Lines, not adjusted in diff, that have changed coverage data.
Files that introduced coverage data that had none before.
Files that have missing coverage data that once were tracked.
Files Coverage
lib/src 100.00%
Project Totals (2 files) 100.00%
Loading