jpnurmi / item_selector

Compare db578b8 ... +1 ... 3e69e94

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.


@@ -61,9 +61,9 @@
Loading
61 61
  final Widget child;
62 62
  final ItemSelection _selection;
63 63
  final ItemSelectionMode _selectionMode;
64 -
  final ItemSelectionActionCallback _onSelectionStart;
65 -
  final ItemSelectionActionCallback _onSelectionUpdate;
66 -
  final ItemSelectionActionCallback _onSelectionEnd;
64 +
  final ItemSelectionActionCallback? _onSelectionStart;
65 +
  final ItemSelectionActionCallback? _onSelectionUpdate;
66 +
  final ItemSelectionActionCallback? _onSelectionEnd;
67 67
  final EdgeInsets _scrollInsets;
68 68
  final Duration _scrollDuration;
69 69
@@ -95,15 +95,15 @@
Loading
95 95
  /// outside the viewport, [scrollInsets] and [scrollDuration] may be specified
96 96
  /// to control auto-scrolling. The defaults are _48 px_ and _125 ms_.
97 97
  ItemSelectionController(
98 -
      {Key key,
99 -
      @required this.child,
100 -
      ItemSelection selection,
101 -
      ItemSelectionMode selectionMode,
102 -
      ItemSelectionActionCallback onSelectionStart,
103 -
      ItemSelectionActionCallback onSelectionUpdate,
104 -
      ItemSelectionActionCallback onSelectionEnd,
105 -
      EdgeInsets scrollInsets,
106 -
      Duration scrollDuration})
98 +
      {Key? key,
99 +
      required this.child,
100 +
      ItemSelection? selection,
101 +
      ItemSelectionMode? selectionMode,
102 +
      ItemSelectionActionCallback? onSelectionStart,
103 +
      ItemSelectionActionCallback? onSelectionUpdate,
104 +
      ItemSelectionActionCallback? onSelectionEnd,
105 +
      EdgeInsets? scrollInsets,
106 +
      Duration? scrollDuration})
107 107
      : _selection = selection ?? ItemSelection(),
108 108
        _selectionMode = selectionMode ?? ItemSelectionMode.multi,
109 109
        _scrollInsets = scrollInsets ?? const EdgeInsets.all(48),
@@ -118,23 +118,23 @@
Loading
118 118
119 119
  bool _startSelection(int start, int end) {
120 120
    if (_onSelectionStart == null) return false;
121 -
    return _onSelectionStart(start, end);
121 +
    return _onSelectionStart!(start, end);
122 122
  }
123 123
124 124
  bool _updateSelection(int start, int end) {
125 125
    if (_onSelectionUpdate == null) return false;
126 -
    return _onSelectionUpdate(start, end);
126 +
    return _onSelectionUpdate!(start, end);
127 127
  }
128 128
129 129
  bool _endSelection(int start, int end) {
130 130
    if (_onSelectionEnd == null) return false;
131 -
    return _onSelectionEnd(start, end);
131 +
    return _onSelectionEnd!(start, end);
132 132
  }
133 133
134 134
  /// Returns an ItemSelectionController instance for the given build [context],
135 135
  /// or `null` if not found.
136 -
  static ItemSelectionController of(BuildContext context) {
137 -
    final _ItemSelectionScope scope =
136 +
  static ItemSelectionController? of(BuildContext context) {
137 +
    final _ItemSelectionScope? scope =
138 138
        context.dependOnInheritedWidgetOfExactType<_ItemSelectionScope>();
139 139
    return scope?.controller;
140 140
  }
@@ -189,7 +189,7 @@
Loading
189 189
  }
190 190
191 191
  int _hitTestAt(Offset position) {
192 -
    final RenderItemSelectionHitTester hitTester = context.findRenderObject();
192 +
    final RenderItemSelectionHitTester? hitTester = context.findRenderObject() as RenderItemSelectionHitTester?;
193 193
    return hitTester?.hitTestAt(
194 194
            position, widget._scrollInsets, widget._scrollDuration) ??
195 195
        -1;
@@ -220,11 +220,11 @@
Loading
220 220
}
221 221
222 222
class _ItemSelectionScope extends InheritedWidget {
223 -
  final ItemSelectionController controller;
223 +
  final ItemSelectionController? controller;
224 224
225 225
  const _ItemSelectionScope({
226 -
    Key key,
227 -
    Widget child,
226 +
    Key? key,
227 +
    required Widget child,
228 228
    this.controller,
229 229
  }) : super(key: key, child: child);
230 230

@@ -59,5 +59,5 @@
Loading
59 59
60 60
class ItemSelectionMetaData {
61 61
  final int index;
62 -
  ItemSelectionMetaData({@required this.index});
62 +
  ItemSelectionMetaData({required this.index});
63 63
}

@@ -39,29 +39,29 @@
Loading
39 39
  /// Adds a [listener] callback for selection changes at any index.
40 40
  void addListener(ItemSelectionChangeCallback listener) {
41 41
    assert(_debugAssertNotDisposed());
42 -
    _listeners.add(listener);
42 +
    _listeners!.add(listener);
43 43
  }
44 44
45 45
  /// Removes a [listener] callback for selection changes at any index.
46 46
  void removeListener(ItemSelectionChangeCallback listener) {
47 47
    assert(_debugAssertNotDisposed());
48 -
    _listeners.remove(listener);
48 +
    _listeners!.remove(listener);
49 49
  }
50 50
51 51
  /// Adds a [listener] callback for selection changes at a specific [index] only.
52 52
  void addIndexListener(int index, ItemSelectionChangeCallback listener) {
53 53
    assert(_debugAssertNotDisposed());
54 -
    if (!_indexListeners.containsKey(index)) {
55 -
      _indexListeners[index] = ObserverList<ItemSelectionChangeCallback>();
54 +
    if (!_indexListeners!.containsKey(index)) {
55 +
      _indexListeners![index] = ObserverList<ItemSelectionChangeCallback>();
56 56
    }
57 -
    _indexListeners[index].add(listener);
57 +
    _indexListeners![index]!.add(listener);
58 58
  }
59 59
60 60
  /// Removes a [listener] callback for selection changes at a specific [index] only.
61 61
  void removeIndexListener(int index, ItemSelectionChangeCallback listener) {
62 62
    assert(_debugAssertNotDisposed());
63 -
    if (_indexListeners.containsKey(index)) {
64 -
      _indexListeners[index].remove(listener);
63 +
    if (_indexListeners!.containsKey(index)) {
64 +
      _indexListeners![index]!.remove(listener);
65 65
    }
66 66
  }
67 67
@@ -71,7 +71,7 @@
Loading
71 71
    assert(_debugAssertNotDisposed());
72 72
    if (_listeners != null) {
73 73
      final allListeners = List<ItemSelectionChangeCallback>.from(
74 -
          [..._listeners, ...?_indexListeners[index]]);
74 +
          [..._listeners!, ...?_indexListeners![index]]);
75 75
      for (final listener in allListeners) {
76 76
        try {
77 77
          listener(index, selected);
@@ -121,8 +121,8 @@
Loading
121 121
    return true;
122 122
  }
123 123
124 -
  ObserverList<ItemSelectionChangeCallback> _listeners =
124 +
  ObserverList<ItemSelectionChangeCallback>? _listeners =
125 125
      ObserverList<ItemSelectionChangeCallback>();
126 -
  HashMap<int, ObserverList<ItemSelectionChangeCallback>> _indexListeners =
126 +
  HashMap<int, ObserverList<ItemSelectionChangeCallback>>? _indexListeners =
127 127
      HashMap<int, ObserverList<ItemSelectionChangeCallback>>();
128 128
}

@@ -38,8 +38,8 @@
Loading
38 38
39 39
class ItemSelectionHitTester extends SingleChildRenderObjectWidget {
40 40
  ItemSelectionHitTester({
41 -
    Key key,
42 -
    @required Widget child,
41 +
    Key? key,
42 +
    required Widget child,
43 43
  }) : super(key: key, child: child);
44 44
45 45
  @override

@@ -65,10 +65,10 @@
Loading
65 65
///         // ...
66 66
///       );
67 67
///     }
68 -
class ItemSelection extends ItemSelectionNotifier with IterableMixin<int> {
68 +
class ItemSelection extends ItemSelectionNotifier with IterableMixin<int?> {
69 69
  /// Creates a selection, optionally with an initial selection range from
70 70
  /// [start] to [end].
71 -
  ItemSelection([int start, int end]) {
71 +
  ItemSelection([int? start, int? end]) {
72 72
    if (start != null) {
73 73
      _tree.add([start, end ?? start]);
74 74
    }
@@ -85,21 +85,21 @@
Loading
85 85
  bool get isNotEmpty => _tree.isNotEmpty;
86 86
87 87
  /// Returns the first index in this selection.
88 -
  int get first => _tree.first?.start;
88 +
  int get first => _tree.first.start;
89 89
90 90
  /// Returns the last index in this selection.
91 -
  int get last => _tree.last?.end;
91 +
  int get last => _tree.last.end;
92 92
93 93
  /// Returns an iterator for iterating the indexes this selection.
94 -
  Iterator<int> get iterator => _ItemSelectionIterator(_tree.iterator);
94 +
  Iterator<int?> get iterator => _ItemSelectionIterator(_tree.iterator);
95 95
96 96
  /// Returns `true` if this selection contains the specified [index].
97 -
  bool contains(covariant int index) {
97 +
  bool contains(covariant int? index) {
98 98
    return _tree.contains([index, index]);
99 99
  }
100 100
101 101
  /// Adds a selection range from [start] to [end].
102 -
  void add(int start, [int end]) {
102 +
  void add(int start, [int? end]) {
103 103
    end ??= start;
104 104
    final addition = IntervalTree([start, end]);
105 105
    addition.removeAll(_tree.intersection(addition));
@@ -120,7 +120,7 @@
Loading
120 120
  }
121 121
122 122
  /// Removes the selection range from [start] to [end].
123 -
  void remove(int start, [int end]) {
123 +
  void remove(int start, [int? end]) {
124 124
    if (_tree.isEmpty) return;
125 125
    start = max(start, first);
126 126
    end = min(end ?? start, last);
@@ -149,7 +149,7 @@
Loading
149 149
150 150
  /// Replaces the existing selection with a selection range from [start] to
151 151
  /// [end] so that no changes are notified for the overlapping range.
152 -
  void replace(int start, [int end]) {
152 +
  void replace(int start, [int? end]) {
153 153
    end ??= start;
154 154
155 155
    final newTree = IntervalTree([start, end]);
@@ -191,12 +191,12 @@
Loading
191 191
  IntervalTree _tree = IntervalTree();
192 192
}
193 193
194 -
class _ItemSelectionIterator extends Iterator<int> {
194 +
class _ItemSelectionIterator extends Iterator<int?> {
195 195
  _ItemSelectionIterator(this._ranges);
196 196
197 197
  /// Returns the current value.
198 198
  @override
199 -
  int get current => _current;
199 +
  int? get current => _current;
200 200
201 201
  /// Iterates to the next value and returns `true` on success, or `false`
202 202
  /// otherwise.
@@ -206,7 +206,7 @@
Loading
206 206
      if (!_ranges.moveNext()) return false;
207 207
      _current = _ranges.current.start;
208 208
    } else {
209 -
      ++_current;
209 +
      _current = _current! + 1;
210 210
    }
211 211
    if (!_ranges.current.contains(Interval(_current, _current))) {
212 212
      if (!_ranges.moveNext()) {
@@ -218,6 +218,6 @@
Loading
218 218
    return true;
219 219
  }
220 220
221 -
  int _current;
221 +
  int? _current;
222 222
  Iterator<Interval> _ranges;
223 223
}

Click to load this diff.
Loading diff...

Learn more Showing 1 files with coverage changes found.

Changes in lib/src/item_selection_types.dart
-3
Loading file...
Files Coverage
lib/src -0.06% 95.45%
Project Totals (6 files) 95.45%
Loading