Unverified Commit 93395b48 authored by Ian Hickson's avatar Ian Hickson Committed by GitHub

Add null safety migration annotations. (#64227)

parent 2f2130a8
......@@ -591,7 +591,7 @@ class CupertinoTextField extends StatefulWidget {
/// {@macro flutter.widgets.editableText.scrollPhysics}
final ScrollPhysics scrollPhysics;
/// {@macro flutter.rendering.editable.selectionEnabled}
/// {@macro flutter.widgets.editableText.selectionEnabled}
bool get selectionEnabled => enableInteractiveSelection;
/// {@macro flutter.material.textfield.onTap}
......
......@@ -391,11 +391,8 @@ class SelectableText extends StatefulWidget {
/// If not set, select all and copy will be enabled by default.
final ToolbarOptions toolbarOptions;
/// True if interactive selection is enabled based on the values of
/// [enableInteractiveSelection].
bool get selectionEnabled {
return enableInteractiveSelection;
}
/// {@macro flutter.widgets.editableText.selectionEnabled}
bool get selectionEnabled => enableInteractiveSelection;
/// Called when the user taps on this selectable text.
///
......
......@@ -702,7 +702,7 @@ class TextField extends StatefulWidget {
/// {@macro flutter.widgets.scrollable.dragStartBehavior}
final DragStartBehavior dragStartBehavior;
/// {@macro flutter.rendering.editable.selectionEnabled}
/// {@macro flutter.widgets.editableText.selectionEnabled}
bool get selectionEnabled => enableInteractiveSelection;
/// {@template flutter.material.textfield.onTap}
......
......@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:math' show min, max;
import 'dart:ui' as ui show Paragraph, ParagraphBuilder, ParagraphConstraints, ParagraphStyle, PlaceholderAlignment, LineMetrics, TextHeightBehavior, BoxHeightStyle, BoxWidthStyle;
......
......@@ -19,7 +19,7 @@ import 'object.dart';
class _DebugSize extends Size {
_DebugSize(Size source, this._owner, this._canBeUsedByParent) : super.copy(source);
final RenderBox _owner;
final bool _canBeUsedByParent;
final bool/*!*/ _canBeUsedByParent;
}
/// Immutable layout constraints for [RenderBox] layout.
......@@ -92,10 +92,10 @@ class BoxConstraints extends Constraints {
this.maxWidth = double.infinity,
this.minHeight = 0.0,
this.maxHeight = double.infinity,
}) : assert (minWidth != null),
assert (maxWidth != null),
assert (minHeight != null),
assert (maxHeight != null);
}) : assert(minWidth != null),
assert(maxWidth != null),
assert(minHeight != null),
assert(maxHeight != null);
/// Creates box constraints that is respected only by the given size.
BoxConstraints.tight(Size size)
......@@ -468,7 +468,7 @@ class BoxConstraints extends Constraints {
/// object whose fields are all set to 0.0.
///
/// {@macro dart.ui.shadow.lerp}
static BoxConstraints lerp(BoxConstraints a, BoxConstraints b, double t) {
static BoxConstraints lerp(BoxConstraints/*?*/ a, BoxConstraints/*?*/ b, double t) {
assert(t != null);
if (a == null && b == null)
return null;
......@@ -1294,9 +1294,9 @@ abstract class RenderBox extends RenderObject {
child.parentData = BoxParentData();
}
Map<_IntrinsicDimensionsCacheEntry, double> _cachedIntrinsicDimensions;
Map<_IntrinsicDimensionsCacheEntry, double/*!*/> _cachedIntrinsicDimensions;
double _computeIntrinsicDimension(_IntrinsicDimension dimension, double argument, double computer(double argument)) {
double/*!*/ _computeIntrinsicDimension(_IntrinsicDimension dimension, double argument, double/*!*/ computer(double argument)) {
assert(RenderObject.debugCheckingIntrinsics || !debugDoingThisResize); // performResize should not depend on anything except the incoming constraints
bool shouldCache = true;
assert(() {
......@@ -1332,7 +1332,7 @@ abstract class RenderBox extends RenderObject {
///
/// Do not override this method. Instead, implement [computeMinIntrinsicWidth].
@mustCallSuper
double getMinIntrinsicWidth(double height) {
double getMinIntrinsicWidth(double/*!*/ height) {
assert(() {
if (height == null) {
throw FlutterError.fromParts(<DiagnosticsNode>[
......@@ -1455,7 +1455,7 @@ abstract class RenderBox extends RenderObject {
/// * [computeMaxIntrinsicWidth], which computes the smallest width beyond
/// which increasing the width never decreases the preferred height.
@protected
double computeMinIntrinsicWidth(double height) {
double/*!*/ computeMinIntrinsicWidth(double/*!*/ height) {
return 0.0;
}
......@@ -1477,7 +1477,7 @@ abstract class RenderBox extends RenderObject {
/// Do not override this method. Instead, implement
/// [computeMaxIntrinsicWidth].
@mustCallSuper
double getMaxIntrinsicWidth(double height) {
double getMaxIntrinsicWidth(double/*!*/ height) {
assert(() {
if (height == null) {
throw FlutterError.fromParts(<DiagnosticsNode>[
......@@ -1535,7 +1535,7 @@ abstract class RenderBox extends RenderObject {
///
/// * [computeMinIntrinsicWidth], which has usage examples.
@protected
double computeMaxIntrinsicWidth(double height) {
double/*!*/ computeMaxIntrinsicWidth(double/*!*/ height) {
return 0.0;
}
......@@ -1556,7 +1556,7 @@ abstract class RenderBox extends RenderObject {
/// Do not override this method. Instead, implement
/// [computeMinIntrinsicHeight].
@mustCallSuper
double getMinIntrinsicHeight(double width) {
double getMinIntrinsicHeight(double/*!*/ width) {
assert(() {
if (width == null) {
throw FlutterError.fromParts(<DiagnosticsNode>[
......@@ -1612,7 +1612,7 @@ abstract class RenderBox extends RenderObject {
/// * [computeMaxIntrinsicHeight], which computes the smallest height beyond
/// which increasing the height never decreases the preferred width.
@protected
double computeMinIntrinsicHeight(double width) {
double/*!*/ computeMinIntrinsicHeight(double/*!*/ width) {
return 0.0;
}
......@@ -1634,7 +1634,7 @@ abstract class RenderBox extends RenderObject {
/// Do not override this method. Instead, implement
/// [computeMaxIntrinsicHeight].
@mustCallSuper
double getMaxIntrinsicHeight(double width) {
double getMaxIntrinsicHeight(double/*!*/ width) {
assert(() {
if (width == null) {
throw FlutterError.fromParts(<DiagnosticsNode>[
......@@ -1692,7 +1692,7 @@ abstract class RenderBox extends RenderObject {
///
/// * [computeMinIntrinsicWidth], which has usage examples.
@protected
double computeMaxIntrinsicHeight(double width) {
double/*!*/ computeMaxIntrinsicHeight(double/*!*/ width) {
return 0.0;
}
......@@ -1709,7 +1709,7 @@ abstract class RenderBox extends RenderObject {
/// [performResize] functions. If you wish to change the size of a box outside
/// of those functions, call [markNeedsLayout] instead to schedule a layout of
/// the box.
Size get size {
Size/*!*/ get size {
assert(hasSize, 'RenderBox was not laid out: ${toString()}');
assert(() {
final Size _size = this._size;
......@@ -1733,12 +1733,12 @@ abstract class RenderBox extends RenderObject {
}());
return _size;
}
Size _size;
/*late*/ Size/*!*/ _size;
/// Setting the size, in checked mode, triggers some analysis of the render box,
/// as implemented by [debugAssertDoesMeetConstraints], including calling the intrinsic
/// sizing methods and checking that they meet certain invariants.
@protected
set size(Size value) {
set size(Size/*!*/ value) {
assert(!(debugDoingThisResize && debugDoingThisLayout));
assert(sizedByParent || !debugDoingThisResize);
assert(() {
......@@ -1852,7 +1852,7 @@ abstract class RenderBox extends RenderObject {
size = size;
}
Map<TextBaseline, double> _cachedBaselines;
Map<TextBaseline/*!*/, double> _cachedBaselines;
static bool _debugDoingBaseline = false;
static bool _debugSetDoingBaseline(bool value) {
_debugDoingBaseline = value;
......@@ -1875,7 +1875,7 @@ abstract class RenderBox extends RenderObject {
///
/// When implementing a [RenderBox] subclass, to override the baseline
/// computation, override [computeDistanceToActualBaseline].
double getDistanceToBaseline(TextBaseline baseline, { bool onlyReal = false }) {
double getDistanceToBaseline(TextBaseline/*!*/ baseline, { bool onlyReal = false }) {
assert(!_debugDoingBaseline, 'Please see the documentation for computeDistanceToActualBaseline for the required calling conventions of this method.');
assert(!debugNeedsLayout);
assert(() {
......@@ -1903,7 +1903,7 @@ abstract class RenderBox extends RenderObject {
/// outside those two methods.
@protected
@mustCallSuper
double getDistanceToActualBaseline(TextBaseline baseline) {
double getDistanceToActualBaseline(TextBaseline/*!*/ baseline) {
assert(_debugDoingBaseline, 'Please see the documentation for computeDistanceToActualBaseline for the required calling conventions of this method.');
_cachedBaselines ??= <TextBaseline, double>{};
_cachedBaselines.putIfAbsent(baseline, () => computeDistanceToActualBaseline(baseline));
......
......@@ -124,8 +124,9 @@ abstract class MultiChildLayoutDelegate {
final Listenable _relayout;
Map<Object, RenderBox> _idToChild;
Set<RenderBox> _debugChildrenNeedingLayout;
// TODO(ianh): make these late final
/*late*/ Map<Object/*!*/, RenderBox>/*!*/ _idToChild;
/*late*/ Set<RenderBox/*!*/>/*!*/ _debugChildrenNeedingLayout;
/// True if a non-null LayoutChild was provided for the specified id.
///
......@@ -140,7 +141,7 @@ abstract class MultiChildLayoutDelegate {
/// Call this from your [performLayout] function to lay out each
/// child. Every child must be laid out using this function exactly
/// once each time the [performLayout] function is called.
Size layoutChild(Object childId, BoxConstraints constraints) {
Size/*!*/ layoutChild(Object childId, BoxConstraints constraints) {
final RenderBox child = _idToChild[childId];
assert(() {
if (child == null) {
......@@ -211,7 +212,8 @@ abstract class MultiChildLayoutDelegate {
// we return.
final Map<Object, RenderBox> previousIdToChild = _idToChild;
Set<RenderBox> debugPreviousChildrenNeedingLayout;
// TODO(ianh): make the next line final
/*late*/ Set<RenderBox>/*!*/ debugPreviousChildrenNeedingLayout;
assert(() {
debugPreviousChildrenNeedingLayout = _debugChildrenNeedingLayout;
_debugChildrenNeedingLayout = <RenderBox>{};
......
......@@ -521,8 +521,9 @@ class RenderCustomPaint extends RenderProxyBox {
markNeedsSemanticsUpdate();
}
void _paintWithPainter(Canvas canvas, Offset offset, CustomPainter painter) {
int debugPreviousCanvasSaveCount;
void _paintWithPainter(Canvas canvas, Offset offset, CustomPainter/*!*/ painter) {
// TODO(ianh): make the next line final
/*late*/ int/*!*/ debugPreviousCanvasSaveCount;
canvas.save();
assert(() {
debugPreviousCanvasSaveCount = canvas.getSaveCount();
......@@ -603,10 +604,10 @@ class RenderCustomPaint extends RenderProxyBox {
}
/// Describe the semantics of the picture painted by the [painter].
List<SemanticsNode> _backgroundSemanticsNodes;
List<SemanticsNode/*!*/> _backgroundSemanticsNodes;
/// Describe the semantics of the picture painted by the [foregroundPainter].
List<SemanticsNode> _foregroundSemanticsNodes;
List<SemanticsNode/*!*/> _foregroundSemanticsNodes;
@override
void assembleSemanticsNode(
......@@ -675,7 +676,7 @@ class RenderCustomPaint extends RenderProxyBox {
/// considered because there is only one type of [SemanticsNode]. There is no
/// concept of a "forgotten" node in semantics, deactivated nodes, or global
/// keys.
static List<SemanticsNode> _updateSemanticsChildren(
static List<SemanticsNode/*!*/> _updateSemanticsChildren(
List<SemanticsNode> oldSemantics,
List<CustomPainterSemantics> newChildSemantics,
) {
......@@ -683,7 +684,7 @@ class RenderCustomPaint extends RenderProxyBox {
newChildSemantics = newChildSemantics ?? const <CustomPainterSemantics>[];
assert(() {
final Map<Key, int> keys = HashMap<Key, int>();
final Map<Key/*!*/, int> keys = HashMap<Key/*!*/, int>();
final List<DiagnosticsNode> information = <DiagnosticsNode>[];
for (int i = 0; i < newChildSemantics.length; i += 1) {
final CustomPainterSemantics child = newChildSemantics[i];
......@@ -708,7 +709,7 @@ class RenderCustomPaint extends RenderProxyBox {
int newChildrenBottom = newChildSemantics.length - 1;
int oldChildrenBottom = oldSemantics.length - 1;
final List<SemanticsNode> newChildren = List<SemanticsNode>(newChildSemantics.length);
final List<SemanticsNode/*!*/> newChildren = List<SemanticsNode/*!*/>(newChildSemantics.length);
// Update the top of the list.
while ((oldChildrenTop <= oldChildrenBottom) && (newChildrenTop <= newChildrenBottom)) {
......@@ -734,7 +735,7 @@ class RenderCustomPaint extends RenderProxyBox {
// Scan the old children in the middle of the list.
final bool haveOldChildren = oldChildrenTop <= oldChildrenBottom;
Map<Key, SemanticsNode> oldKeyedChildren;
Map<Key/*!*/, SemanticsNode> oldKeyedChildren;
if (haveOldChildren) {
oldKeyedChildren = <Key, SemanticsNode>{};
while (oldChildrenTop <= oldChildrenBottom) {
......
......@@ -174,7 +174,7 @@ bool debugProfileLayoutsEnabled = false;
bool debugProfilePaintsEnabled = false;
/// Signature for [debugOnProfilePaint] implementations.
typedef ProfilePaintCallback = void Function(RenderObject renderObject);
typedef ProfilePaintCallback = void Function(RenderObject/*!*/ renderObject);
/// Callback invoked for every [RenderObject] painted each frame.
///
......
......@@ -47,6 +47,8 @@ class RenderErrorBox extends RenderBox {
builder.pushStyle(textStyle);
builder.addText(message);
_paragraph = builder.build();
} else {
_paragraph = null;
}
} catch (error) {
// Intentionally left empty.
......@@ -56,7 +58,8 @@ class RenderErrorBox extends RenderBox {
/// The message to attempt to display at paint time.
final String message;
ui.Paragraph _paragraph;
// TODO(ianh): should be final
/*late*/ ui.Paragraph/*?*/ _paragraph;
@override
double computeMaxIntrinsicWidth(double height) {
......
......@@ -198,7 +198,7 @@ enum CrossAxisAlignment {
baseline,
}
bool _startIsTopLeft(Axis direction, TextDirection textDirection, VerticalDirection verticalDirection) {
bool/*?*/ _startIsTopLeft(Axis direction, TextDirection textDirection, VerticalDirection verticalDirection) {
assert(direction != null);
// If the relevant value of textDirection or verticalDirection is null, this returns null too.
switch (direction) {
......@@ -508,9 +508,9 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl
}
double _getIntrinsicSize({
Axis sizingDirection,
double extent, // the extent in the direction that isn't the sizing direction
_ChildSizingFunction childSize, // a method to find the size in the sizing direction
@required Axis sizingDirection,
@required double extent, // the extent in the direction that isn't the sizing direction
@required _ChildSizingFunction childSize, // a method to find the size in the sizing direction
}) {
if (_direction == sizingDirection) {
// INTRINSIC MAIN SIZE
......@@ -548,8 +548,9 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl
while (child != null) {
final int flex = _getFlex(child);
totalFlex += flex;
double mainSize;
double crossSize;
// TODO(ianh): these should be late final
/*late*/ double/*!*/ mainSize;
/*late*/ double/*!*/ crossSize;
if (flex == 0) {
switch (_direction) {
case Axis.horizontal:
......@@ -789,7 +790,8 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl
final int flex = _getFlex(child);
if (flex > 0) {
final double maxChildExtent = canFlex ? (child == lastFlexChild ? (freeSpace - allocatedFlexSpace) : spacePerFlex * flex) : double.infinity;
double minChildExtent;
// TODO(ianh): this should be late final
/*late*/ double/*!*/ minChildExtent;
switch (_getFit(child)) {
case FlexFit.tight:
assert(maxChildExtent < double.infinity);
......@@ -865,7 +867,6 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl
// Align items along the main axis.
final double idealSize = canFlex && mainAxisSize == MainAxisSize.max ? maxMainSize : allocatedSize;
double actualSize;
double actualSizeDelta;
switch (_direction) {
case Axis.horizontal:
size = constraints.constrain(Size(idealSize, crossSize));
......@@ -878,11 +879,12 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl
crossSize = size.width;
break;
}
actualSizeDelta = actualSize - allocatedSize;
final double actualSizeDelta = actualSize - allocatedSize;
_overflow = math.max(0.0, -actualSizeDelta);
final double remainingSpace = math.max(0.0, actualSizeDelta);
double leadingSpace;
double betweenSpace;
// TODO(ianh): these should be late final
/*late*/ double/*!*/ leadingSpace;
/*late*/ double/*!*/ betweenSpace;
// flipMainAxis is used to decide whether to lay out left-to-right/top-to-bottom (false), or
// right-to-left/bottom-to-top (true). The _startIsTopLeft will return null if there's only
// one child and the relevant direction is null, in which case we arbitrarily decide not to
......
......@@ -1456,8 +1456,15 @@ abstract class RenderObject extends AbstractNode with DiagnosticableTreeMixin im
bool _doingThisLayoutWithCallback = false;
/// The layout constraints most recently supplied by the parent.
///
/// If layout has not yet happened, accessing this getter will
/// throw a [StateError] exception.
@protected
Constraints get constraints => _constraints;
Constraints/*!*/ get constraints {
if (_constraints == null)
throw StateError('A RenderObject does not have any constraints before it has been laid out.');
return _constraints/*!*/;
}
Constraints _constraints;
/// Verify that the object's constraints are being met. Override
......@@ -2492,7 +2499,7 @@ abstract class RenderObject extends AbstractNode with DiagnosticableTreeMixin im
/// ```
/// {@end-tool}
@protected
void describeSemanticsConfiguration(SemanticsConfiguration config) {
void describeSemanticsConfiguration(SemanticsConfiguration/*!*/ config) {
// Nothing to do by default.
}
......@@ -2890,7 +2897,7 @@ abstract class RenderObject extends AbstractNode with DiagnosticableTreeMixin im
properties.add(FlagProperty('needsCompositing', value: _needsCompositing, ifTrue: 'needs compositing'));
properties.add(DiagnosticsProperty<dynamic>('creator', debugCreator, defaultValue: null, level: DiagnosticLevel.debug));
properties.add(DiagnosticsProperty<ParentData>('parentData', parentData, tooltip: _debugCanParentUseSize == true ? 'can use size' : null, missingIfNull: true));
properties.add(DiagnosticsProperty<Constraints>('constraints', constraints, missingIfNull: true));
properties.add(DiagnosticsProperty<Constraints>('constraints', _constraints, missingIfNull: true));
// don't access it via the "layer" getter since that's only valid when we don't need paint
properties.add(DiagnosticsProperty<ContainerLayer>('layer', _layer, defaultValue: null));
properties.add(DiagnosticsProperty<SemanticsNode>('semantics node', _semantics, defaultValue: null));
......
......@@ -62,22 +62,22 @@ class RelativeRect {
/// Distance from the left side of the container to the left side of this rectangle.
///
/// May be negative if the left side of the rectangle is outside of the container.
final double left;
final double/*!*/ left;
/// Distance from the top side of the container to the top side of this rectangle.
///
/// May be negative if the top side of the rectangle is outside of the container.
final double top;
final double/*!*/ top;
/// Distance from the right side of the container to the right side of this rectangle.
///
/// May be positive if the right side of the rectangle is outside of the container.
final double right;
final double/*!*/ right;
/// Distance from the bottom side of the container to the bottom side of this rectangle.
///
/// May be positive if the bottom side of the rectangle is outside of the container.
final double bottom;
final double/*!*/ bottom;
/// Returns whether any of the values are greater than zero.
///
......@@ -134,7 +134,7 @@ class RelativeRect {
/// If either rect is null, this function interpolates from [RelativeRect.fill].
///
/// {@macro dart.ui.shadow.lerp}
static RelativeRect lerp(RelativeRect a, RelativeRect b, double t) {
static RelativeRect lerp(RelativeRect/*?*/ a, RelativeRect/*?*/ b, double t) {
assert(t != null);
if (a == null && b == null)
return null;
......@@ -492,7 +492,8 @@ class RenderStack extends RenderBox
child.layout(childConstraints, parentUsesSize: true);
double x;
// TODO(ianh): x should be late final
/*late*/ double/*!*/ x;
if (childParentData.left != null) {
x = childParentData.left;
} else if (childParentData.right != null) {
......@@ -504,7 +505,8 @@ class RenderStack extends RenderBox
if (x < 0.0 || x + child.size.width > size.width)
hasVisualOverflow = true;
double y;
// TODO(ianh): y should be late final
/*late*/ double/*!*/ y;
if (childParentData.top != null) {
y = childParentData.top;
} else if (childParentData.bottom != null) {
......
......@@ -1145,13 +1145,16 @@ class EditableText extends StatefulWidget {
final EdgeInsets scrollPadding;
/// {@template flutter.widgets.editableText.enableInteractiveSelection}
/// If true, then long-pressing this TextField will select text and show the
/// cut/copy/paste menu, and tapping will move the text caret.
/// Whether to enable user interface affordances for changing the
/// text selection.
///
/// True by default.
/// For example, setting this to true will enable features such as
/// long-pressing the TextField to select text and show the
/// cut/copy/paste menu, and tapping to move the text caret.
///
/// If false, most of the accessibility support for selecting text, copy
/// and paste, and moving the caret will be disabled.
/// When this is false, the text selection cannot be adjusted by
/// the user, text cannot be copied, and the user cannot paste into
/// the text field from the clipboard.
/// {@endtemplate}
final bool enableInteractiveSelection;
......@@ -1186,7 +1189,12 @@ class EditableText extends StatefulWidget {
/// {@endtemplate}
final ScrollPhysics scrollPhysics;
/// {@macro flutter.rendering.editable.selectionEnabled}
/// {@template flutter.widgets.editableText.selectionEnabled}
/// Same as [enableInteractiveSelection].
///
/// This getter exists primarily for consistency with
/// [RenderEditable.selectionEnabled].
/// {@endtemplate}
bool get selectionEnabled => enableInteractiveSelection;
/// {@template flutter.widgets.editableText.autofillHints}
......
......@@ -630,7 +630,7 @@ void main() {
);
});
testWidgets('_RenderButtonBarRow.constraints works before layout', (WidgetTester tester) async {
testWidgets('_RenderButtonBarRow.constraints does not work before layout', (WidgetTester tester) async {
await tester.pumpWidget(
const MaterialApp(home: ButtonBar()),
Duration.zero,
......@@ -641,6 +641,6 @@ void main() {
final RenderBox renderButtonBar = tester.renderObject(buttonBar) as RenderBox;
expect(renderButtonBar.debugNeedsLayout, isTrue);
expect(renderButtonBar.constraints, isNull);
expect(() => renderButtonBar.constraints, throwsStateError);
});
}
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