diff --git a/packages/flutter/lib/src/animation/animations.dart b/packages/flutter/lib/src/animation/animations.dart index fa7767d336..eb4aae3577 100644 --- a/packages/flutter/lib/src/animation/animations.dart +++ b/packages/flutter/lib/src/animation/animations.dart @@ -495,7 +495,7 @@ class TrainHoppingAnimation extends Animation : assert(_currentTrain != null) { if (_nextTrain != null) { if (_currentTrain!.value == _nextTrain!.value) { - _currentTrain = _nextTrain!; + _currentTrain = _nextTrain; _nextTrain = null; } else if (_currentTrain!.value > _nextTrain!.value) { _mode = _TrainHoppingMode.maximize; @@ -557,7 +557,7 @@ class TrainHoppingAnimation extends Animation _currentTrain! ..removeStatusListener(_statusChangeHandler) ..removeListener(_valueChangeHandler); - _currentTrain = _nextTrain!; + _currentTrain = _nextTrain; _nextTrain = null; _currentTrain!.addStatusListener(_statusChangeHandler); _statusChangeHandler(_currentTrain!.status); diff --git a/packages/flutter/lib/src/cupertino/picker.dart b/packages/flutter/lib/src/cupertino/picker.dart index 37bd495b78..d0390a2747 100644 --- a/packages/flutter/lib/src/cupertino/picker.dart +++ b/packages/flutter/lib/src/cupertino/picker.dart @@ -186,7 +186,7 @@ class CupertinoPicker extends StatefulWidget { /// This can be called during scrolls and during ballistic flings. To get the /// value only when the scrolling settles, use a [NotificationListener], /// listen for [ScrollEndNotification] and read its [FixedExtentMetrics]. - final ValueChanged onSelectedItemChanged; + final ValueChanged? onSelectedItemChanged; /// A delegate that lazily instantiates children. final ListWheelChildDelegate childDelegate; @@ -247,7 +247,7 @@ class _CupertinoPickerState extends State { } if (widget.onSelectedItemChanged != null) { - widget.onSelectedItemChanged(index); + widget.onSelectedItemChanged!(index); } } diff --git a/packages/flutter/lib/src/cupertino/tab_view.dart b/packages/flutter/lib/src/cupertino/tab_view.dart index 98031d363a..7c47829626 100644 --- a/packages/flutter/lib/src/cupertino/tab_view.dart +++ b/packages/flutter/lib/src/cupertino/tab_view.dart @@ -172,7 +172,7 @@ class _CupertinoTabViewState extends State { WidgetBuilder? routeBuilder; String? title; if (name == Navigator.defaultRouteName && widget.builder != null) { - routeBuilder = widget.builder!; + routeBuilder = widget.builder; title = widget.defaultTitle; } else if (widget.routes != null) { routeBuilder = widget.routes![name]; diff --git a/packages/flutter/lib/src/rendering/paragraph.dart b/packages/flutter/lib/src/rendering/paragraph.dart index a8d2faa229..7231b6aa81 100644 --- a/packages/flutter/lib/src/rendering/paragraph.dart +++ b/packages/flutter/lib/src/rendering/paragraph.dart @@ -46,7 +46,7 @@ class TextParentData extends ContainerBoxParentData { @override String toString() { final List values = [ - if (offset != null) 'offset=$offset', + 'offset=$offset', if (scale != null) 'scale=$scale', super.toString(), ]; @@ -819,14 +819,12 @@ class RenderParagraph extends RenderBox String? workingLabel; for (final InlineSpanSemanticsInformation info in _semanticsInfo!) { if (info.requiresOwnNode) { - if (workingText != null) { - combined.add(InlineSpanSemanticsInformation( - workingText, - semanticsLabel: workingLabel ?? workingText, - )); - workingText = ''; - workingLabel = null; - } + combined.add(InlineSpanSemanticsInformation( + workingText, + semanticsLabel: workingLabel ?? workingText, + )); + workingText = ''; + workingLabel = null; combined.add(info); } else { workingText += info.text; @@ -838,14 +836,10 @@ class RenderParagraph extends RenderBox } } } - if (workingText != null) { - combined.add(InlineSpanSemanticsInformation( - workingText, - semanticsLabel: workingLabel, - )); - } else { // ignore: dead_code - assert(workingLabel != null); - } + combined.add(InlineSpanSemanticsInformation( + workingText, + semanticsLabel: workingLabel, + )); return combined; } diff --git a/packages/flutter/lib/src/rendering/proxy_box.dart b/packages/flutter/lib/src/rendering/proxy_box.dart index ddc2fe7d5a..5b1ad79a80 100644 --- a/packages/flutter/lib/src/rendering/proxy_box.dart +++ b/packages/flutter/lib/src/rendering/proxy_box.dart @@ -4481,8 +4481,7 @@ class RenderSemanticsAnnotations extends RenderProxyBox { void describeSemanticsConfiguration(SemanticsConfiguration config) { super.describeSemanticsConfiguration(config); config.isSemanticBoundary = container; - if (explicitChildNodes != null) - config.explicitChildNodes = explicitChildNodes; + config.explicitChildNodes = explicitChildNodes; assert((scopesRoute == true && explicitChildNodes == true) || scopesRoute != true, 'explicitChildNodes must be set to true if scopes route is true'); assert(!(toggled == true && checked == true), diff --git a/packages/flutter/lib/src/rendering/table.dart b/packages/flutter/lib/src/rendering/table.dart index ee49131992..34f0b93d82 100644 --- a/packages/flutter/lib/src/rendering/table.dart +++ b/packages/flutter/lib/src/rendering/table.dart @@ -1085,8 +1085,7 @@ class RenderTable extends RenderBox { final TableCellParentData childParentData = child.parentData! as TableCellParentData; switch (childParentData.verticalAlignment ?? defaultVerticalAlignment) { case TableCellVerticalAlignment.baseline: - if (baselines[x] != null) - childParentData.offset = Offset(positions[x], rowTop + beforeBaselineDistance - baselines[x]); + childParentData.offset = Offset(positions[x], rowTop + beforeBaselineDistance - baselines[x]); break; case TableCellVerticalAlignment.top: childParentData.offset = Offset(positions[x], rowTop); diff --git a/packages/flutter/lib/src/semantics/semantics.dart b/packages/flutter/lib/src/semantics/semantics.dart index a692605da4..b0c62dc380 100644 --- a/packages/flutter/lib/src/semantics/semantics.dart +++ b/packages/flutter/lib/src/semantics/semantics.dart @@ -510,15 +510,7 @@ class _SemanticsDiagnosticableNode extends DiagnosticableNode { final DebugSemanticsDumpOrder childOrder; @override - List getChildren() { - if (value != null) - return value.debugDescribeChildren(childOrder: childOrder); - - // `value` has a non-nullable return type, but might be null when - // running with weak checking, so we need to null check it above (and - // ignore the warning below that the null-handling logic is dead code). - return const []; // ignore: dead_code - } + List getChildren() => value.debugDescribeChildren(childOrder: childOrder); } /// Provides hint values which override the default hints on supported @@ -1419,11 +1411,9 @@ class SemanticsNode extends AbstractNode with DiagnosticableTreeMixin { for (final SemanticsNode child in _children!) child._dead = true; } - if (newChildren != null) { - for (final SemanticsNode child in newChildren) { - assert(!child.isInvisible, 'Child $child is invisible and should not be added as a child of $this.'); - child._dead = false; - } + for (final SemanticsNode child in newChildren) { + assert(!child.isInvisible, 'Child $child is invisible and should not be added as a child of $this.'); + child._dead = false; } bool sawChange = false; if (_children != null) { @@ -1438,21 +1428,19 @@ class SemanticsNode extends AbstractNode with DiagnosticableTreeMixin { } } } - if (newChildren != null) { - for (final SemanticsNode child in newChildren) { - if (child.parent != this) { - if (child.parent != null) { - // we're rebuilding the tree from the bottom up, so it's possible - // that our child was, in the last pass, a child of one of our - // ancestors. In that case, we drop the child eagerly here. - // TODO(ianh): Find a way to assert that the same node didn't - // actually appear in the tree in two places. - child.parent?.dropChild(child); - } - assert(!child.attached); - adoptChild(child); - sawChange = true; + for (final SemanticsNode child in newChildren) { + if (child.parent != this) { + if (child.parent != null) { + // we're rebuilding the tree from the bottom up, so it's possible + // that our child was, in the last pass, a child of one of our + // ancestors. In that case, we drop the child eagerly here. + // TODO(ianh): Find a way to assert that the same node didn't + // actually appear in the tree in two places. + child.parent?.dropChild(child); } + assert(!child.attached); + adoptChild(child); + sawChange = true; } } if (!sawChange && _children != null) { @@ -1966,10 +1954,8 @@ class SemanticsNode extends AbstractNode with DiagnosticableTreeMixin { mergedTags ??= {}; mergedTags!.addAll(node.tags!); } - if (node._customSemanticsActions != null) { - for (final CustomSemanticsAction action in _customSemanticsActions.keys) - customSemanticsActionIds.add(CustomSemanticsAction.getIdentifier(action)); - } + for (final CustomSemanticsAction action in _customSemanticsActions.keys) + customSemanticsActionIds.add(CustomSemanticsAction.getIdentifier(action)); if (node.hintOverrides != null) { if (node.hintOverrides!.onTapHint != null) { final CustomSemanticsAction action = CustomSemanticsAction.overridingAction( diff --git a/packages/flutter/lib/src/services/text_input.dart b/packages/flutter/lib/src/services/text_input.dart index e84ed0d115..b273db76e0 100644 --- a/packages/flutter/lib/src/services/text_input.dart +++ b/packages/flutter/lib/src/services/text_input.dart @@ -790,7 +790,7 @@ abstract class TextInputClient { const TextInputClient(); /// The current state of the [TextEditingValue] held by this client. - TextEditingValue get currentTextEditingValue; + TextEditingValue? get currentTextEditingValue; /// The [AutofillScope] this [TextInputClient] belongs to, if any. /// @@ -1164,7 +1164,7 @@ class TextInput { if (method == 'TextInputClient.requestExistingInputState') { assert(_currentConnection!._client != null); _attach(_currentConnection!, _currentConfiguration); - final TextEditingValue editingValue = _currentConnection!._client.currentTextEditingValue; + final TextEditingValue? editingValue = _currentConnection!._client.currentTextEditingValue; if (editingValue != null) { _setEditingState(editingValue); } diff --git a/packages/flutter/lib/src/widgets/container.dart b/packages/flutter/lib/src/widgets/container.dart index e1ee8b45cb..14ad931f0f 100644 --- a/packages/flutter/lib/src/widgets/container.dart +++ b/packages/flutter/lib/src/widgets/container.dart @@ -105,12 +105,7 @@ class DecoratedBox extends SingleChildRenderObjectWidget { break; } properties.add(EnumProperty('position', position, level: DiagnosticLevel.hidden)); - properties.add(DiagnosticsProperty( - label, - decoration, - ifNull: 'no decoration', - showName: decoration != null, - )); + properties.add(DiagnosticsProperty(label, decoration)); } } diff --git a/packages/flutter/lib/src/widgets/focus_scope.dart b/packages/flutter/lib/src/widgets/focus_scope.dart index e48ca8a7dd..4a95ab788c 100644 --- a/packages/flutter/lib/src/widgets/focus_scope.dart +++ b/packages/flutter/lib/src/widgets/focus_scope.dart @@ -527,9 +527,7 @@ class _FocusState extends State { // _createNode is overridden in _FocusScopeState. _internalNode ??= _createNode(); } - if (widget.descendantsAreFocusable != null) { - focusNode.descendantsAreFocusable = widget.descendantsAreFocusable; - } + focusNode.descendantsAreFocusable = widget.descendantsAreFocusable; if (widget.skipTraversal != null) { focusNode.skipTraversal = widget.skipTraversal!; } @@ -615,9 +613,7 @@ class _FocusState extends State { if (widget.canRequestFocus != null) { focusNode.canRequestFocus = widget.canRequestFocus!; } - if (widget.descendantsAreFocusable != null) { - focusNode.descendantsAreFocusable = widget.descendantsAreFocusable; - } + focusNode.descendantsAreFocusable = widget.descendantsAreFocusable; } else { _focusAttachment!.detach(); focusNode.removeListener(_handleFocusChanged); diff --git a/packages/flutter/lib/src/widgets/layout_builder.dart b/packages/flutter/lib/src/widgets/layout_builder.dart index 1f44bcd513..6288fa4049 100644 --- a/packages/flutter/lib/src/widgets/layout_builder.dart +++ b/packages/flutter/lib/src/widgets/layout_builder.dart @@ -116,23 +116,21 @@ class _LayoutBuilderElement extends RenderOb void _layout(ConstraintType constraints) { owner!.buildScope(this, () { - Widget? built; - if (widget.builder != null) { - try { - built = widget.builder(this, constraints); - debugWidgetBuilderValue(widget, built); - } catch (e, stack) { - built = ErrorWidget.builder( - _debugReportException( - ErrorDescription('building $widget'), - e, - stack, - informationCollector: () sync* { - yield DiagnosticsDebugCreator(DebugCreator(this)); - }, - ), - ); - } + Widget built; + try { + built = widget.builder(this, constraints); + debugWidgetBuilderValue(widget, built); + } catch (e, stack) { + built = ErrorWidget.builder( + _debugReportException( + ErrorDescription('building $widget'), + e, + stack, + informationCollector: () sync* { + yield DiagnosticsDebugCreator(DebugCreator(this)); + }, + ), + ); } try { _child = updateChild(_child, built, null); diff --git a/packages/flutter/lib/src/widgets/navigator.dart b/packages/flutter/lib/src/widgets/navigator.dart index 4d214ec970..f53588845d 100644 --- a/packages/flutter/lib/src/widgets/navigator.dart +++ b/packages/flutter/lib/src/widgets/navigator.dart @@ -3603,11 +3603,11 @@ class NavigatorState extends State with TickerProviderStateMixin, Res assert(previousOldPageRouteEntry != null); final List<_RouteEntry> pagelessRoutes = pageRouteToPagelessRoutes .putIfAbsent( - previousOldPageRouteEntry!, + previousOldPageRouteEntry, () => <_RouteEntry>[], ); pagelessRoutes.add(potentialEntryToRemove); - if (previousOldPageRouteEntry.isWaitingForExitingDecision) + if (previousOldPageRouteEntry!.isWaitingForExitingDecision) potentialEntryToRemove.markNeedsExitingDecision(); continue; } @@ -3651,7 +3651,7 @@ class NavigatorState extends State with TickerProviderStateMixin, Res assert(previousOldPageRouteEntry != null); final List<_RouteEntry> pagelessRoutes = pageRouteToPagelessRoutes .putIfAbsent( - previousOldPageRouteEntry!, + previousOldPageRouteEntry, () => <_RouteEntry>[] ); pagelessRoutes.add(oldEntry); diff --git a/packages/flutter/lib/src/widgets/nested_scroll_view.dart b/packages/flutter/lib/src/widgets/nested_scroll_view.dart index 3a10a0517c..082ba0e886 100644 --- a/packages/flutter/lib/src/widgets/nested_scroll_view.dart +++ b/packages/flutter/lib/src/widgets/nested_scroll_view.dart @@ -808,10 +808,7 @@ class _NestedScrollCoordinator implements ScrollActivityDelegate, ScrollHoldCont return false; } - void updateShadow() { - if (_onHasScrolledBodyChanged != null) - _onHasScrolledBodyChanged(); - } + void updateShadow() { _onHasScrolledBodyChanged(); } ScrollDirection get userScrollDirection => _userScrollDirection; ScrollDirection _userScrollDirection = ScrollDirection.idle; diff --git a/packages/flutter/lib/src/widgets/sliver.dart b/packages/flutter/lib/src/widgets/sliver.dart index 0c1dff2cfb..c68d34c569 100644 --- a/packages/flutter/lib/src/widgets/sliver.dart +++ b/packages/flutter/lib/src/widgets/sliver.dart @@ -1107,7 +1107,7 @@ class SliverMultiBoxAdaptorElement extends RenderObjectElement implements Render if (childParentData != null) childParentData.layoutOffset = null; - newChildren[newIndex] = _childElements[index]!; + newChildren[newIndex] = _childElements[index]; // We need to make sure the original index gets processed. newChildren.putIfAbsent(index, () => null); // We do not want the remapped child to get deactivated during processElement. diff --git a/packages/flutter/lib/src/widgets/widget_inspector.dart b/packages/flutter/lib/src/widgets/widget_inspector.dart index 4e32e6714e..b7a96a50fa 100644 --- a/packages/flutter/lib/src/widgets/widget_inspector.dart +++ b/packages/flutter/lib/src/widgets/widget_inspector.dart @@ -970,7 +970,7 @@ mixin WidgetInspectorService { void initServiceExtensions(_RegisterServiceExtensionCallback registerServiceExtensionCallback) { _structuredExceptionHandler = _reportError; if (isStructuredErrorsEnabled()) { - FlutterError.onError = _structuredExceptionHandler!; + FlutterError.onError = _structuredExceptionHandler; } _registerServiceExtensionCallback = registerServiceExtensionCallback; assert(!_debugServiceExtensionsRegistered); @@ -2284,10 +2284,8 @@ class _WidgetInspectorState extends State if (_lastPointerLocation != null) { _inspectAt(_lastPointerLocation!); - if (selection != null) { - // Notify debuggers to open an inspector on the object. - developer.inspect(selection.current); - } + // Notify debuggers to open an inspector on the object. + developer.inspect(selection.current); } setState(() { // Only exit select mode if there is a button to return to select mode.