Unverified Commit 304e2c57 authored by Alexandre Ardhuin's avatar Alexandre Ardhuin Committed by GitHub

fix nullability issues (#67306)

parent c14ab91f
......@@ -495,7 +495,7 @@ class TrainHoppingAnimation extends Animation<double>
: 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<double>
_currentTrain!
..removeStatusListener(_statusChangeHandler)
..removeListener(_valueChangeHandler);
_currentTrain = _nextTrain!;
_currentTrain = _nextTrain;
_nextTrain = null;
_currentTrain!.addStatusListener(_statusChangeHandler);
_statusChangeHandler(_currentTrain!.status);
......
......@@ -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<int> onSelectedItemChanged;
final ValueChanged<int>? onSelectedItemChanged;
/// A delegate that lazily instantiates children.
final ListWheelChildDelegate childDelegate;
......@@ -247,7 +247,7 @@ class _CupertinoPickerState extends State<CupertinoPicker> {
}
if (widget.onSelectedItemChanged != null) {
widget.onSelectedItemChanged(index);
widget.onSelectedItemChanged!(index);
}
}
......
......@@ -172,7 +172,7 @@ class _CupertinoTabViewState extends State<CupertinoTabView> {
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];
......
......@@ -46,7 +46,7 @@ class TextParentData extends ContainerBoxParentData<RenderBox> {
@override
String toString() {
final List<String> values = <String>[
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;
}
......
......@@ -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),
......
......@@ -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);
......
......@@ -510,15 +510,7 @@ class _SemanticsDiagnosticableNode extends DiagnosticableNode<SemanticsNode> {
final DebugSemanticsDumpOrder childOrder;
@override
List<DiagnosticsNode> 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 <DiagnosticsNode>[]; // ignore: dead_code
}
List<DiagnosticsNode> 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 ??= <SemanticsTag>{};
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(
......
......@@ -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);
}
......
......@@ -105,12 +105,7 @@ class DecoratedBox extends SingleChildRenderObjectWidget {
break;
}
properties.add(EnumProperty<DecorationPosition>('position', position, level: DiagnosticLevel.hidden));
properties.add(DiagnosticsProperty<Decoration>(
label,
decoration,
ifNull: 'no decoration',
showName: decoration != null,
));
properties.add(DiagnosticsProperty<Decoration>(label, decoration));
}
}
......
......@@ -527,9 +527,7 @@ class _FocusState extends State<Focus> {
// _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<Focus> {
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);
......
......@@ -116,23 +116,21 @@ class _LayoutBuilderElement<ConstraintType extends Constraints> 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);
......
......@@ -3603,11 +3603,11 @@ class NavigatorState extends State<Navigator> 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<Navigator> with TickerProviderStateMixin, Res
assert(previousOldPageRouteEntry != null);
final List<_RouteEntry> pagelessRoutes = pageRouteToPagelessRoutes
.putIfAbsent(
previousOldPageRouteEntry!,
previousOldPageRouteEntry,
() => <_RouteEntry>[]
);
pagelessRoutes.add(oldEntry);
......
......@@ -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;
......
......@@ -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.
......
......@@ -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<WidgetInspector>
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.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment