diff --git a/packages/devtools_app/lib/src/primitives/custom_pointer_scroll_view.dart b/packages/devtools_app/lib/src/primitives/custom_pointer_scroll_view.dart index 09efaebf13c..ff07ae4f529 100644 --- a/packages/devtools_app/lib/src/primitives/custom_pointer_scroll_view.dart +++ b/packages/devtools_app/lib/src/primitives/custom_pointer_scroll_view.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart=2.9 - import 'dart:async'; import 'dart:math' as math; import 'dart:ui'; @@ -24,16 +22,16 @@ abstract class CustomPointerScrollView extends BoxScrollView { /// /// If the [primary] argument is true, the [controller] must be null. const CustomPointerScrollView({ - Key key, + Key? key, Axis scrollDirection = Axis.vertical, bool reverse = false, - ScrollController controller, - bool primary, - ScrollPhysics physics, + ScrollController? controller, + bool? primary, + ScrollPhysics? physics, bool shrinkWrap = false, - EdgeInsetsGeometry padding, - double cacheExtent, - int semanticChildCount, + EdgeInsetsGeometry? padding, + double? cacheExtent, + int? semanticChildCount, DragStartBehavior dragStartBehavior = DragStartBehavior.start, this.customPointerSignalHandler, }) : super( @@ -50,14 +48,14 @@ abstract class CustomPointerScrollView extends BoxScrollView { dragStartBehavior: dragStartBehavior, ); - final void Function(PointerSignalEvent event) customPointerSignalHandler; + final void Function(PointerSignalEvent event)? customPointerSignalHandler; @override Widget build(BuildContext context) { final List slivers = buildSlivers(context); final AxisDirection axisDirection = getDirection(context); - final ScrollController scrollController = + final ScrollController? scrollController = primary ? PrimaryScrollController.of(context) : controller; final CustomPointerScrollable scrollable = CustomPointerScrollable( dragStartBehavior: dragStartBehavior, @@ -82,21 +80,17 @@ abstract class CustomPointerScrollView extends BoxScrollView { /// pointer signal event handling via [customPointerSignalHandler]. class CustomPointerScrollable extends StatefulWidget { const CustomPointerScrollable({ - Key key, + Key? key, this.axisDirection = AxisDirection.down, this.controller, this.physics, - @required this.viewportBuilder, + required this.viewportBuilder, this.incrementCalculator, this.excludeFromSemantics = false, this.semanticChildCount, this.dragStartBehavior = DragStartBehavior.start, this.customPointerSignalHandler, - }) : assert(axisDirection != null), - assert(dragStartBehavior != null), - assert(viewportBuilder != null), - assert(excludeFromSemantics != null), - assert(semanticChildCount == null || semanticChildCount >= 0), + }) : assert(semanticChildCount == null || semanticChildCount >= 0), super(key: key); /// The direction in which this widget scrolls. @@ -126,7 +120,7 @@ class CustomPointerScrollable extends StatefulWidget { /// /// * [ensureVisible], which animates the scroll position to reveal a given /// [BuildContext]. - final ScrollController controller; + final ScrollController? controller; /// How the widgets should respond to user input. /// @@ -149,7 +143,7 @@ class CustomPointerScrollable extends StatefulWidget { /// * [AlwaysScrollableScrollPhysics], which can be used to indicate that the /// scrollable should react to scroll requests (and possible overscroll) /// even if the scrollable's contents fit without scrolling being necessary. - final ScrollPhysics physics; + final ScrollPhysics? physics; /// Builds the viewport through which the scrollable content is displayed. /// @@ -174,7 +168,7 @@ class CustomPointerScrollable extends StatefulWidget { /// If [incrementCalculator] is null, the default for /// [ScrollIncrementType.page] is 80% of the size of the scroll window, and /// for [ScrollIncrementType.line], 50 logical pixels. - final ScrollIncrementCalculator incrementCalculator; + final ScrollIncrementCalculator? incrementCalculator; /// Whether the scroll actions introduced by this [Scrollable] are exposed /// in the semantics tree. @@ -204,7 +198,7 @@ class CustomPointerScrollable extends StatefulWidget { /// /// * [CustomScrollView], for an explanation of scroll semantics. /// * [SemanticsConfiguration.scrollChildCount], the corresponding semantics property. - final int semanticChildCount; + final int? semanticChildCount; // TODO(jslavitz): Set the DragStartBehavior default to be start across all widgets. /// {@template flutter.widgets.scrollable.dragStartBehavior} @@ -233,7 +227,7 @@ class CustomPointerScrollable extends StatefulWidget { /// Determined by the [axisDirection]. Axis get axis => axisDirectionToAxis(axisDirection); - final void Function(PointerSignalEvent event) customPointerSignalHandler; + final void Function(PointerSignalEvent event)? customPointerSignalHandler; @override _CustomPointerScrollableState createState() => @@ -256,8 +250,8 @@ class CustomPointerScrollable extends StatefulWidget { /// /// Calling this method will create a dependency on the closest [Scrollable] /// in the [context], if there is one. - static _CustomPointerScrollableState of(BuildContext context) { - final _ScrollableScope widget = + static _CustomPointerScrollableState? of(BuildContext context) { + final _ScrollableScope? widget = context.dependOnInheritedWidgetOfExactType<_ScrollableScope>(); return widget?.scrollable; } @@ -276,9 +270,9 @@ class CustomPointerScrollable extends StatefulWidget { /// If there is no [Scrollable] in the widget tree above the [context], this /// method returns false. static bool recommendDeferredLoadingForContext(BuildContext context) { - final _ScrollableScope widget = context + final _ScrollableScope? widget = context .getElementForInheritedWidgetOfExactType<_ScrollableScope>() - ?.widget as _ScrollableScope; + ?.widget as _ScrollableScope?; if (widget == null) { return false; } @@ -297,11 +291,11 @@ class CustomPointerScrollable extends StatefulWidget { }) { final List> futures = >[]; - _CustomPointerScrollableState scrollable = + _CustomPointerScrollableState? scrollable = CustomPointerScrollable.of(context); while (scrollable != null) { - futures.add(scrollable.position.ensureVisible( - context.findRenderObject(), + futures.add(scrollable.position!.ensureVisible( + context.findRenderObject()!, alignment: alignment, duration: duration, curve: curve, @@ -332,22 +326,22 @@ class _CustomPointerScrollableState extends State /// To control what kind of [ScrollPosition] is created for a [Scrollable], /// provide it with custom [ScrollController] that creates the appropriate /// [ScrollPosition] in its [ScrollController.createScrollPosition] method. - ScrollPosition get position => _position; - ScrollPosition _position; + ScrollPosition? get position => _position; + ScrollPosition? _position; @override AxisDirection get axisDirection => widget.axisDirection; - ScrollBehavior _configuration; - ScrollPhysics _physics; + late ScrollBehavior _configuration; + ScrollPhysics? _physics; // Only call this from places that will definitely trigger a rebuild. void _updatePosition() { _configuration = ScrollConfiguration.of(context); _physics = _configuration.getScrollPhysics(context); - if (widget.physics != null) _physics = widget.physics.applyTo(_physics); - final ScrollController controller = widget.controller; - final ScrollPosition oldPosition = position; + if (widget.physics != null) _physics = widget.physics!.applyTo(_physics); + final ScrollController? controller = widget.controller; + final ScrollPosition? oldPosition = position; if (oldPosition != null) { controller?.detach(oldPosition); // It's important that we not dispose the old position until after the @@ -356,11 +350,12 @@ class _CustomPointerScrollableState extends State scheduleMicrotask(oldPosition.dispose); } - _position = controller?.createScrollPosition(_physics, this, oldPosition) ?? - ScrollPositionWithSingleContext( - physics: _physics, context: this, oldPosition: oldPosition); + _position = + controller?.createScrollPosition(_physics!, this, oldPosition) ?? + ScrollPositionWithSingleContext( + physics: _physics!, context: this, oldPosition: oldPosition); assert(position != null); - controller?.attach(position); + controller?.attach(position!); } @override @@ -376,8 +371,8 @@ class _CustomPointerScrollableState extends State } bool _shouldUpdatePosition(CustomPointerScrollable oldWidget) { - ScrollPhysics newPhysics = widget.physics; - ScrollPhysics oldPhysics = oldWidget.physics; + ScrollPhysics? newPhysics = widget.physics; + ScrollPhysics? oldPhysics = oldWidget.physics; do { if (newPhysics?.runtimeType != oldPhysics?.runtimeType) return true; newPhysics = newPhysics?.parent; @@ -392,8 +387,8 @@ class _CustomPointerScrollableState extends State super.didUpdateWidget(oldWidget); if (widget.controller != oldWidget.controller) { - oldWidget.controller?.detach(position); - widget.controller?.attach(position); + oldWidget.controller?.detach(position!); + widget.controller?.attach(position!); } if (_shouldUpdatePosition(oldWidget)) _updatePosition(); @@ -401,8 +396,8 @@ class _CustomPointerScrollableState extends State @override void dispose() { - widget.controller?.detach(position); - position.dispose(); + widget.controller?.detach(position!); + position!.dispose(); super.dispose(); } @@ -414,7 +409,7 @@ class _CustomPointerScrollableState extends State @protected void setSemanticsActions(Set actions) { if (_gestureDetectorKey.currentState != null) { - _gestureDetectorKey.currentState.replaceSemanticsActions(actions); + _gestureDetectorKey.currentState!.replaceSemanticsActions(actions); } } @@ -429,8 +424,8 @@ class _CustomPointerScrollableState extends State const {}; bool _shouldIgnorePointer = false; - bool _lastCanDrag; - Axis _lastAxisDirection; + bool? _lastCanDrag; + Axis? _lastAxisDirection; @override @protected @@ -487,7 +482,7 @@ class _CustomPointerScrollableState extends State _lastCanDrag = canDrag; _lastAxisDirection = widget.axis; if (_gestureDetectorKey.currentState != null) { - _gestureDetectorKey.currentState + _gestureDetectorKey.currentState! .replaceGestureRecognizers(_gestureRecognizers); } } @@ -501,27 +496,27 @@ class _CustomPointerScrollableState extends State if (_shouldIgnorePointer == value) return; _shouldIgnorePointer = value; if (_ignorePointerKey.currentContext != null) { - final RenderIgnorePointer renderBox = _ignorePointerKey.currentContext + final RenderIgnorePointer renderBox = _ignorePointerKey.currentContext! .findRenderObject() as RenderIgnorePointer; renderBox.ignoring = _shouldIgnorePointer; } } @override - BuildContext get notificationContext => _gestureDetectorKey.currentContext; + BuildContext? get notificationContext => _gestureDetectorKey.currentContext; @override BuildContext get storageContext => context; // TOUCH HANDLERS - Drag _drag; - ScrollHoldController _hold; + Drag? _drag; + ScrollHoldController? _hold; void _handleDragDown(DragDownDetails details) { assert(_drag == null); assert(_hold == null); - _hold = position.hold(_disposeHold); + _hold = position!.hold(_disposeHold); } void _handleDragStart(DragStartDetails details) { @@ -529,7 +524,7 @@ class _CustomPointerScrollableState extends State // _handleDragStart, for example if some user code calls jumpTo or otherwise // triggers a new activity to begin. assert(_drag == null); - _drag = position.drag(details, _disposeDrag); + _drag = position!.drag(details, _disposeDrag); assert(_drag != null); assert(_hold == null); } @@ -578,8 +573,9 @@ class _CustomPointerScrollableState extends State delta *= -1; } - return math.min(math.max(position.pixels + delta, position.minScrollExtent), - position.maxScrollExtent); + return math.min( + math.max(position!.pixels + delta, position!.minScrollExtent), + position!.maxScrollExtent); } void _receivedPointerSignal(PointerSignalEvent event) { @@ -587,8 +583,8 @@ class _CustomPointerScrollableState extends State final double targetScrollOffset = _targetScrollOffsetForPointerScroll(event); // Only express interest in the event if it would actually result in a scroll. - if (targetScrollOffset != position.pixels) { - GestureBinding.instance.pointerSignalResolver + if (targetScrollOffset != position!.pixels) { + GestureBinding.instance!.pointerSignalResolver .register(event, _handlePointerScroll); } } @@ -596,13 +592,13 @@ class _CustomPointerScrollableState extends State void _handlePointerScroll(PointerEvent event) { assert(event is PointerScrollEvent); - if (_physics != null && !_physics.shouldAcceptUserOffset(position)) { + if (_physics != null && !_physics!.shouldAcceptUserOffset(position!)) { return; } final double targetScrollOffset = _targetScrollOffsetForPointerScroll(event as PointerScrollEvent); - if (targetScrollOffset != position.pixels) { - position.jumpTo(targetScrollOffset); + if (targetScrollOffset != position!.pixels) { + position!.jumpTo(targetScrollOffset); } } @@ -622,7 +618,7 @@ class _CustomPointerScrollableState extends State // must be placed above the widget using it: RawGestureDetector Widget result = _ScrollableScope( scrollable: this, - position: position, + position: position!, // TODO(ianh): Having all these global keys is sad. child: Listener( onPointerSignal: @@ -638,7 +634,7 @@ class _CustomPointerScrollableState extends State key: _ignorePointerKey, ignoring: _shouldIgnorePointer, ignoringSemantics: false, - child: widget.viewportBuilder(context, position), + child: widget.viewportBuilder(context, position!), ), ), ), @@ -649,9 +645,9 @@ class _CustomPointerScrollableState extends State result = _ScrollSemantics( key: _scrollSemanticsKey, child: result, - position: position, - allowImplicitScrolling: widget?.physics?.allowImplicitScrolling ?? - _physics.allowImplicitScrolling, + position: position!, + allowImplicitScrolling: widget.physics?.allowImplicitScrolling ?? + _physics!.allowImplicitScrolling, semanticChildCount: widget.semanticChildCount, ); } @@ -662,7 +658,7 @@ class _CustomPointerScrollableState extends State context, result, ScrollableDetails( - controller: widget.controller, direction: axisDirection)); + controller: widget.controller!, direction: axisDirection)); } @override @@ -681,13 +677,11 @@ class _CustomPointerScrollableState extends State // _ScrollableScope. class _ScrollableScope extends InheritedWidget { const _ScrollableScope({ - Key key, - @required this.scrollable, - @required this.position, - @required Widget child, - }) : assert(scrollable != null), - assert(child != null), - super(key: key, child: child); + Key? key, + required this.scrollable, + required this.position, + required Widget child, + }) : super(key: key, child: child); final _CustomPointerScrollableState scrollable; final ScrollPosition position; @@ -714,18 +708,17 @@ class _ScrollableScope extends InheritedWidget { /// scrollable children. class _ScrollSemantics extends SingleChildRenderObjectWidget { const _ScrollSemantics({ - Key key, - @required this.position, - @required this.allowImplicitScrolling, - @required this.semanticChildCount, - Widget child, - }) : assert(position != null), - assert(semanticChildCount == null || semanticChildCount >= 0), + Key? key, + required this.position, + required this.allowImplicitScrolling, + required this.semanticChildCount, + Widget? child, + }) : assert(semanticChildCount == null || semanticChildCount >= 0), super(key: key, child: child); final ScrollPosition position; final bool allowImplicitScrolling; - final int semanticChildCount; + final int? semanticChildCount; @override _RenderScrollSemantics createRenderObject(BuildContext context) { @@ -748,14 +741,13 @@ class _ScrollSemantics extends SingleChildRenderObjectWidget { class _RenderScrollSemantics extends RenderProxyBox { _RenderScrollSemantics({ - @required ScrollPosition position, - @required bool allowImplicitScrolling, - @required int semanticChildCount, - RenderBox child, + required ScrollPosition position, + required bool allowImplicitScrolling, + required int? semanticChildCount, + RenderBox? child, }) : _position = position, _allowImplicitScrolling = allowImplicitScrolling, _semanticChildCount = semanticChildCount, - assert(position != null), super(child) { position.addListener(markNeedsSemanticsUpdate); } @@ -764,7 +756,6 @@ class _RenderScrollSemantics extends RenderProxyBox { ScrollPosition get position => _position; ScrollPosition _position; set position(ScrollPosition value) { - assert(value != null); if (value == _position) return; _position.removeListener(markNeedsSemanticsUpdate); _position = value; @@ -781,9 +772,9 @@ class _RenderScrollSemantics extends RenderProxyBox { markNeedsSemanticsUpdate(); } - int get semanticChildCount => _semanticChildCount; - int _semanticChildCount; - set semanticChildCount(int value) { + int? get semanticChildCount => _semanticChildCount; + int? _semanticChildCount; + set semanticChildCount(int? value) { if (value == semanticChildCount) return; _semanticChildCount = value; markNeedsSemanticsUpdate(); @@ -803,7 +794,7 @@ class _RenderScrollSemantics extends RenderProxyBox { } } - SemanticsNode _innerNode; + SemanticsNode? _innerNode; @override void assembleSemanticsNode(SemanticsNode node, SemanticsConfiguration config, @@ -815,12 +806,12 @@ class _RenderScrollSemantics extends RenderProxyBox { } _innerNode ??= SemanticsNode(showOnScreen: showOnScreen); - _innerNode + _innerNode! ..isMergedIntoParent = node.isPartOfNodeMerging ..rect = Offset.zero & node.rect.size; - int firstVisibleIndex; - final List excluded = [_innerNode]; + int? firstVisibleIndex; + final List excluded = [_innerNode!]; final List included = []; for (final SemanticsNode child in children) { assert(child.isTagged(RenderViewport.useTwoPaneSemantics)); @@ -835,8 +826,8 @@ class _RenderScrollSemantics extends RenderProxyBox { } config.scrollIndex = firstVisibleIndex; node.updateWith(config: null, childrenInInversePaintOrder: excluded); - _innerNode.updateWith( - config: config, childrenInInversePaintOrder: included); + _innerNode! + .updateWith(config: config, childrenInInversePaintOrder: included); } @override diff --git a/packages/devtools_app/lib/src/primitives/enum_utils.dart b/packages/devtools_app/lib/src/primitives/enum_utils.dart index 3e00a2963f3..e8921feb0c1 100644 --- a/packages/devtools_app/lib/src/primitives/enum_utils.dart +++ b/packages/devtools_app/lib/src/primitives/enum_utils.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart=2.9 - import 'package:flutter/foundation.dart'; /// Class that converts enum value names to enum entries and vice versa. @@ -20,7 +18,7 @@ import 'package:flutter/foundation.dart'; class EnumUtils { EnumUtils(List enumValues) { for (var val in enumValues) { - final enumDescription = describeEnum(val); + final enumDescription = describeEnum(val!); _lookupTable[enumDescription] = val; _reverseLookupTable[val] = enumDescription; } @@ -29,7 +27,7 @@ class EnumUtils { final Map _lookupTable = {}; final Map _reverseLookupTable = {}; - T enumEntry(String enumName) => _lookupTable[enumName]; + T? enumEntry(String enumName) => _lookupTable[enumName]; - String name(T enumEntry) => _reverseLookupTable[enumEntry]; + String? name(T enumEntry) => _reverseLookupTable[enumEntry]; } diff --git a/packages/devtools_app/lib/src/primitives/extent_delegate_list.dart b/packages/devtools_app/lib/src/primitives/extent_delegate_list.dart index 75bab672df7..45740d7e0d7 100644 --- a/packages/devtools_app/lib/src/primitives/extent_delegate_list.dart +++ b/packages/devtools_app/lib/src/primitives/extent_delegate_list.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart=2.9 - import 'dart:math' as math; import 'package:collection/collection.dart' as collection; @@ -34,7 +32,7 @@ abstract class ExtentDelegate { double itemExtent(int index); /// The layout offset for the child with the given index. - double layoutOffset(int index); + double layoutOffset(int? index); /// The minimum child index that is visible at the given scroll offset. /// @@ -65,7 +63,7 @@ abstract class FixedExtentDelegateBase extends ExtentDelegate { // The _offsets list is intentionally one element larger than the length of // the list as it includes an offset at the end that is the offset after all // items in the list. - List _offsets; + late List _offsets; @override int get length => _offsets.length - 1; @@ -103,8 +101,8 @@ abstract class FixedExtentDelegateBase extends ExtentDelegate { } @override - double layoutOffset(int index) { - if (index >= _offsets.length) return _offsets.last; + double layoutOffset(int? index) { + if (index! >= _offsets.length) return _offsets.last; return _offsets[index]; } @@ -132,8 +130,8 @@ abstract class FixedExtentDelegateBase extends ExtentDelegate { class FixedExtentDelegate extends FixedExtentDelegateBase { FixedExtentDelegate({ - @required double Function(int index) computeExtent, - @required int Function() computeLength, + required double Function(int index) computeExtent, + required int Function() computeLength, }) : _computeExtent = computeExtent, _computeLength = computeLength { recompute(); @@ -164,20 +162,19 @@ class FixedExtentDelegate extends FixedExtentDelegateBase { /// screen need to be animated. class ExtentDelegateListView extends CustomPointerScrollView { const ExtentDelegateListView({ - Key key, + Key? key, Axis scrollDirection = Axis.vertical, bool reverse = false, - ScrollController controller, - bool primary, - ScrollPhysics physics, + ScrollController? controller, + bool? primary, + ScrollPhysics? physics, bool shrinkWrap = false, - EdgeInsetsGeometry padding, - @required this.childrenDelegate, - @required this.extentDelegate, - int semanticChildCount, - Function(PointerSignalEvent event) customPointerSignalHandler, - }) : assert(childrenDelegate != null), - super( + EdgeInsetsGeometry? padding, + required this.childrenDelegate, + required this.extentDelegate, + int? semanticChildCount, + Function(PointerSignalEvent event)? customPointerSignalHandler, + }) : super( key: key, scrollDirection: scrollDirection, reverse: reverse, @@ -195,7 +192,7 @@ class ExtentDelegateListView extends CustomPointerScrollView { /// A delegate that provides item extents for the children of the /// [ExtentDelegateListView]. - final ExtentDelegate extentDelegate; + final ExtentDelegate? extentDelegate; @override Widget buildChildLayout(BuildContext context) { @@ -216,18 +213,19 @@ class SliverExtentDelegateList extends SliverMultiBoxAdaptorWidget { /// Creates a sliver that places box children with the same main axis extent /// in a linear array. const SliverExtentDelegateList({ - Key key, - @required SliverChildDelegate delegate, - @required this.extentDelegate, + Key? key, + required SliverChildDelegate delegate, + required this.extentDelegate, }) : super(key: key, delegate: delegate); /// The extent the children are forced to have in the main axis. - final ExtentDelegate extentDelegate; + final ExtentDelegate? extentDelegate; @override RenderSliverExtentDelegateBoxAdaptor createRenderObject( BuildContext context) { - final SliverMultiBoxAdaptorElement element = context; + final SliverMultiBoxAdaptorElement element = + context as SliverMultiBoxAdaptorElement; return RenderSliverExtentDelegateBoxAdaptor( childManager: element, extentDelegate: extentDelegate, @@ -253,29 +251,29 @@ class RenderSliverExtentDelegateBoxAdaptor extends RenderSliverMultiBoxAdaptor { /// /// The [childManager] argument must not be null. RenderSliverExtentDelegateBoxAdaptor({ - @required RenderSliverBoxChildManager childManager, - @required ExtentDelegate extentDelegate, + required RenderSliverBoxChildManager childManager, + required ExtentDelegate? extentDelegate, }) : super(childManager: childManager) { _markNeedsLayout = markNeedsLayout; this.extentDelegate = extentDelegate; } - set extentDelegate(ExtentDelegate delegate) { + set extentDelegate(ExtentDelegate? delegate) { if (delegate == _extentDelegate) return; assert(_markNeedsLayout != null); // Unregister from the previous delegate if there was one. if (_extentDelegate != null) { - _extentDelegate.layoutDirty.removeListener(_markNeedsLayout); + _extentDelegate!.layoutDirty.removeListener(_markNeedsLayout!); } // We need to listen for when the delegate changes its layout. - delegate.layoutDirty.addListener(_markNeedsLayout); + delegate!.layoutDirty.addListener(_markNeedsLayout!); _extentDelegate = delegate; } - ExtentDelegate _extentDelegate; - VoidCallback _markNeedsLayout; + ExtentDelegate? _extentDelegate; + VoidCallback? _markNeedsLayout; /// Called to estimate the total scrollable extents of this object. /// @@ -287,10 +285,10 @@ class RenderSliverExtentDelegateBoxAdaptor extends RenderSliverMultiBoxAdaptor { @protected double estimateMaxScrollOffset( SliverConstraints constraints, { - int firstIndex, - int lastIndex, - double leadingScrollOffset, - double trailingScrollOffset, + int? firstIndex, + int? lastIndex, + double? leadingScrollOffset, + double? trailingScrollOffset, }) { return childManager.estimateMaxScrollOffset( constraints, @@ -302,7 +300,7 @@ class RenderSliverExtentDelegateBoxAdaptor extends RenderSliverMultiBoxAdaptor { } int _calculateLeadingGarbage(int firstIndex) { - RenderBox walker = firstChild; + RenderBox? walker = firstChild; int leadingGarbage = 0; while (walker != null && indexOf(walker) < firstIndex) { leadingGarbage += 1; @@ -311,10 +309,10 @@ class RenderSliverExtentDelegateBoxAdaptor extends RenderSliverMultiBoxAdaptor { return leadingGarbage; } - int _calculateTrailingGarbage(int targetLastIndex) { - RenderBox walker = lastChild; + int _calculateTrailingGarbage(int? targetLastIndex) { + RenderBox? walker = lastChild; int trailingGarbage = 0; - while (walker != null && indexOf(walker) > targetLastIndex) { + while (walker != null && indexOf(walker) > targetLastIndex!) { trailingGarbage += 1; walker = childBefore(walker); } @@ -322,7 +320,7 @@ class RenderSliverExtentDelegateBoxAdaptor extends RenderSliverMultiBoxAdaptor { } BoxConstraints buildChildConstraints(int index) { - final currentItemExtent = _extentDelegate.itemExtent(index); + final currentItemExtent = _extentDelegate!.itemExtent(index); assert(currentItemExtent >= 0); return constraints.asBoxConstraints( minExtent: currentItemExtent, @@ -346,9 +344,9 @@ class RenderSliverExtentDelegateBoxAdaptor extends RenderSliverMultiBoxAdaptor { final double targetEndScrollOffset = scrollOffset + remainingExtent; final int firstIndex = - _extentDelegate.minChildIndexForScrollOffset(scrollOffset); - final int targetLastIndex = targetEndScrollOffset.isFinite - ? _extentDelegate.maxChildIndexForScrollOffset(targetEndScrollOffset) + _extentDelegate!.minChildIndexForScrollOffset(scrollOffset); + final int? targetLastIndex = targetEndScrollOffset.isFinite + ? _extentDelegate!.maxChildIndexForScrollOffset(targetEndScrollOffset) : null; if (firstChild != null) { @@ -362,34 +360,15 @@ class RenderSliverExtentDelegateBoxAdaptor extends RenderSliverMultiBoxAdaptor { if (firstChild == null) { if (!addInitialChild( index: firstIndex, - layoutOffset: _extentDelegate.layoutOffset(firstIndex), + layoutOffset: _extentDelegate!.layoutOffset(firstIndex), )) { // There are either no children, or we are past the end of all our children. // If it is the latter, we will need to find the first available child. - double max; - if (childManager.childCount != null) { - // TODO(jacobr): is this correct? - // This matches the logic from sliver_fixed_extent_list but it seems - // a little odd. This is only right if the childManager contains all - // children added to the list view. - max = _extentDelegate.layoutOffset(childManager.childCount); - } else if (firstIndex <= 0) { - max = 0.0; - } else { - // We will have to find it manually. - int possibleFirstIndex = firstIndex - 1; - while (possibleFirstIndex > 0 && - !addInitialChild( - index: possibleFirstIndex, - layoutOffset: _extentDelegate.layoutOffset(possibleFirstIndex), - )) { - possibleFirstIndex -= 1; - } - max = _extentDelegate.layoutOffset(possibleFirstIndex); - } + final double max = + _extentDelegate!.layoutOffset(childManager.childCount); assert(max >= 0.0); geometry = SliverGeometry( - scrollExtent: _extentDelegate.layoutOffset(_extentDelegate.length), + scrollExtent: _extentDelegate!.layoutOffset(_extentDelegate!.length), maxPaintExtent: max, ); childManager.didFinishLayout(); @@ -397,40 +376,41 @@ class RenderSliverExtentDelegateBoxAdaptor extends RenderSliverMultiBoxAdaptor { } } - RenderBox trailingChildWithLayout; + RenderBox? trailingChildWithLayout; - for (int index = indexOf(firstChild) - 1; index >= firstIndex; --index) { - final RenderBox child = + for (int index = indexOf(firstChild!) - 1; index >= firstIndex; --index) { + final RenderBox? child = insertAndLayoutLeadingChild(buildChildConstraints(index)); if (child == null) { // Items before the previously first child are no longer present. // Reset the scroll offset to offset all items prior and up to the // missing item. Let parent re-layout everything. geometry = SliverGeometry( - scrollOffsetCorrection: _extentDelegate.layoutOffset(index), + scrollOffsetCorrection: _extentDelegate!.layoutOffset(index), ); return; } - final SliverMultiBoxAdaptorParentData childParentData = child.parentData; - childParentData.layoutOffset = _extentDelegate.layoutOffset(index); + final SliverMultiBoxAdaptorParentData childParentData = + child.parentData as SliverMultiBoxAdaptorParentData; + childParentData.layoutOffset = _extentDelegate!.layoutOffset(index); assert(childParentData.index == index); trailingChildWithLayout ??= child; } if (trailingChildWithLayout == null) { - firstChild.layout(buildChildConstraints(firstIndex)); + firstChild!.layout(buildChildConstraints(firstIndex)); final SliverMultiBoxAdaptorParentData childParentData = - firstChild.parentData; - childParentData.layoutOffset = _extentDelegate.layoutOffset(firstIndex); + firstChild!.parentData as SliverMultiBoxAdaptorParentData; + childParentData.layoutOffset = _extentDelegate!.layoutOffset(firstIndex); trailingChildWithLayout = firstChild; } double estimatedMaxScrollOffset = - _extentDelegate.layoutOffset(_extentDelegate.length); - for (int index = indexOf(trailingChildWithLayout) + 1; + _extentDelegate!.layoutOffset(_extentDelegate!.length); + for (int index = indexOf(trailingChildWithLayout!) + 1; targetLastIndex == null || index <= targetLastIndex; ++index) { - RenderBox child = childAfter(trailingChildWithLayout); + RenderBox? child = childAfter(trailingChildWithLayout!); if (child == null || indexOf(child) != index) { child = insertAndLayoutChild( buildChildConstraints(index), @@ -438,30 +418,31 @@ class RenderSliverExtentDelegateBoxAdaptor extends RenderSliverMultiBoxAdaptor { ); if (child == null) { // We have run out of children. - estimatedMaxScrollOffset = _extentDelegate.layoutOffset(index + 1); + estimatedMaxScrollOffset = _extentDelegate!.layoutOffset(index + 1); break; } } else { child.layout(buildChildConstraints(index)); } trailingChildWithLayout = child; - assert(child != null); - final SliverMultiBoxAdaptorParentData childParentData = child.parentData; + final SliverMultiBoxAdaptorParentData childParentData = + child.parentData as SliverMultiBoxAdaptorParentData; assert(childParentData.index == index); childParentData.layoutOffset = - _extentDelegate.layoutOffset(childParentData.index); + _extentDelegate!.layoutOffset(childParentData.index); } - final int lastIndex = indexOf(lastChild); - final double leadingScrollOffset = _extentDelegate.layoutOffset(firstIndex); + final int lastIndex = indexOf(lastChild!); + final double leadingScrollOffset = + _extentDelegate!.layoutOffset(firstIndex); final double trailingScrollOffset = - _extentDelegate.layoutOffset(lastIndex + 1); + _extentDelegate!.layoutOffset(lastIndex + 1); assert(firstIndex == 0 || - childScrollOffset(firstChild) - scrollOffset <= + childScrollOffset(firstChild!)! - scrollOffset <= precisionErrorTolerance); assert(debugAssertChildListIsNonEmptyAndContiguous()); - assert(indexOf(firstChild) == firstIndex); + assert(indexOf(firstChild!) == firstIndex); assert(targetLastIndex == null || lastIndex <= targetLastIndex); estimatedMaxScrollOffset = math.min( @@ -489,13 +470,13 @@ class RenderSliverExtentDelegateBoxAdaptor extends RenderSliverMultiBoxAdaptor { final double targetEndScrollOffsetForPaint = constraints.scrollOffset + constraints.remainingPaintExtent; - final int targetLastIndexForPaint = targetEndScrollOffsetForPaint.isFinite - ? _extentDelegate + final int? targetLastIndexForPaint = targetEndScrollOffsetForPaint.isFinite + ? _extentDelegate! .maxChildIndexForScrollOffset(targetEndScrollOffsetForPaint) : null; assert(paintExtent <= estimatedMaxScrollOffset); geometry = SliverGeometry( - scrollExtent: _extentDelegate.layoutOffset(_extentDelegate.length), + scrollExtent: _extentDelegate!.layoutOffset(_extentDelegate!.length), paintExtent: paintExtent, cacheExtent: cacheExtent, maxPaintExtent: estimatedMaxScrollOffset, diff --git a/packages/devtools_app/lib/src/primitives/geometry.dart b/packages/devtools_app/lib/src/primitives/geometry.dart index dd474aa9e05..4199daca68b 100644 --- a/packages/devtools_app/lib/src/primitives/geometry.dart +++ b/packages/devtools_app/lib/src/primitives/geometry.dart @@ -2,14 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart=2.9 - import 'package:flutter/material.dart'; // TODO(kenz): consolidate the logic between [VerticalLineSegment] and // [HorizontalLineSegment] by using [LineSegment] and switching on the main axis abstract class LineSegment { - LineSegment(this.start, this.end, {@required this.opacity}); + LineSegment(this.start, this.end, {required this.opacity}); final Offset start; final Offset end; @@ -31,16 +29,16 @@ abstract class LineSegment { } LineSegment toZoomed({ - @required double zoom, - @required double unzoomableOffsetLineStart, - @required double unzoomableOffsetLineEnd, + required double zoom, + required double unzoomableOffsetLineStart, + required double unzoomableOffsetLineEnd, }); @visibleForTesting static double zoomedXPosition({ - @required double x, - @required double zoom, - @required double unzoomableOffset, + required double x, + required double zoom, + required double unzoomableOffset, }) { assert(x >= unzoomableOffset); return (x - unzoomableOffset) * zoom + unzoomableOffset; @@ -75,9 +73,9 @@ class HorizontalLineSegment extends LineSegment @override HorizontalLineSegment toZoomed({ - @required double zoom, - @required double unzoomableOffsetLineStart, - @required double unzoomableOffsetLineEnd, + required double zoom, + required double unzoomableOffsetLineStart, + required double unzoomableOffsetLineEnd, }) { final zoomedLineStartX = LineSegment.zoomedXPosition( x: start.dx, @@ -125,9 +123,9 @@ class VerticalLineSegment extends LineSegment @override VerticalLineSegment toZoomed({ - @required double zoom, - @required double unzoomableOffsetLineStart, - @required double unzoomableOffsetLineEnd, + required double zoom, + required double unzoomableOffsetLineStart, + required double unzoomableOffsetLineEnd, }) { final zoomedLineStartX = LineSegment.zoomedXPosition( x: start.dx, diff --git a/packages/devtools_app/lib/src/primitives/history_manager.dart b/packages/devtools_app/lib/src/primitives/history_manager.dart index ed8d4f96e4e..2ebef359ac1 100644 --- a/packages/devtools_app/lib/src/primitives/history_manager.dart +++ b/packages/devtools_app/lib/src/primitives/history_manager.dart @@ -2,17 +2,15 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart=2.9 - import 'package:flutter/foundation.dart'; class HistoryManager { /// The currently selected historical item. /// /// Returns null if there is no historical items. - ValueListenable get current => _current; + ValueListenable get current => _current; - final _current = ValueNotifier(null); + final _current = ValueNotifier(null); final _history = []; int _historyIndex = -1; @@ -56,7 +54,7 @@ class HistoryManager { /// Return the next value. /// /// Returns null if there is no next value. - T peekNext() => hasNext ? _history[_historyIndex + 1] : null; + T? peekNext() => hasNext ? _history[_historyIndex + 1] : null; /// Remove the most recent historical item on the stack. /// diff --git a/packages/devtools_app/test/extent_delegate_list_view_test.dart b/packages/devtools_app/test/extent_delegate_list_view_test.dart index e9ae735da1a..cedeb5043f2 100644 --- a/packages/devtools_app/test/extent_delegate_list_view_test.dart +++ b/packages/devtools_app/test/extent_delegate_list_view_test.dart @@ -80,24 +80,5 @@ void main() { ); expect(pointerSignalEventCount, equals(1)); }); - - testWidgets('throws for null childrenDelegate', (tester) async { - expect( - () async { - await pumpList( - tester, - ExtentDelegateListView( - controller: ScrollController(), - extentDelegate: FixedExtentDelegate( - computeLength: () => children.length, - computeExtent: (index) => children[index], - ), - childrenDelegate: null, - ), - ); - }, - throwsAssertionError, - ); - }); }); }