Unverified Commit 42f3709a authored by Michael Goderbauer's avatar Michael Goderbauer Committed by GitHub

Sound null safety for framework and flutter_test (#68642)

parent 955e0746
......@@ -528,7 +528,8 @@ Future<void> _runAddToAppLifeCycleTests() async {
Future<void> _runFrameworkTests() async {
final bq.BigqueryApi bigqueryApi = await _getBigqueryApi();
final List<String> nullSafetyOptions = <String>['--null-assertions', '--no-sound-null-safety'];
final List<String> soundNullSafetyOptions = <String>['--enable-experiment=non-nullable', '--null-assertions', '--sound-null-safety'];
final List<String> mixedModeNullSafetyOptions = <String>['--enable-experiment=non-nullable', '--null-assertions', '--no-sound-null-safety'];
final List<String> trackWidgetCreationAlternatives = <String>['--track-widget-creation', '--no-track-widget-creation'];
Future<void> runWidgets() async {
......@@ -536,7 +537,7 @@ Future<void> _runFrameworkTests() async {
for (final String trackWidgetCreationOption in trackWidgetCreationAlternatives) {
await _runFlutterTest(
path.join(flutterRoot, 'packages', 'flutter'),
options: <String>[trackWidgetCreationOption, ...nullSafetyOptions],
options: <String>[trackWidgetCreationOption, ...soundNullSafetyOptions],
tableData: bigqueryApi?.tabledata,
tests: <String>[ path.join('test', 'widgets') + path.separator ],
);
......@@ -562,7 +563,7 @@ Future<void> _runFrameworkTests() async {
for (final String trackWidgetCreationOption in trackWidgetCreationAlternatives) {
await _runFlutterTest(
path.join(flutterRoot, 'packages', 'flutter'),
options: <String>[trackWidgetCreationOption, ...nullSafetyOptions],
options: <String>[trackWidgetCreationOption, ...soundNullSafetyOptions],
tableData: bigqueryApi?.tabledata,
tests: tests,
);
......@@ -613,14 +614,14 @@ Future<void> _runFrameworkTests() async {
await _runFlutterTest(path.join(flutterRoot, 'dev', 'manual_tests'), tableData: bigqueryApi?.tabledata);
await _runFlutterTest(path.join(flutterRoot, 'dev', 'tools', 'vitool'), tableData: bigqueryApi?.tabledata);
await _runFlutterTest(path.join(flutterRoot, 'examples', 'hello_world'), tableData: bigqueryApi?.tabledata);
await _runFlutterTest(path.join(flutterRoot, 'examples', 'layers'), tableData: bigqueryApi?.tabledata);
await _runFlutterTest(path.join(flutterRoot, 'examples', 'layers'), tableData: bigqueryApi?.tabledata, options: mixedModeNullSafetyOptions);
await _runFlutterTest(path.join(flutterRoot, 'dev', 'benchmarks', 'test_apps', 'stocks'), tableData: bigqueryApi?.tabledata);
await _runFlutterTest(path.join(flutterRoot, 'packages', 'flutter_driver'), tableData: bigqueryApi?.tabledata, tests: <String>[path.join('test', 'src', 'real_tests')]);
await _runFlutterTest(path.join(flutterRoot, 'packages', 'flutter_goldens'), tableData: bigqueryApi?.tabledata);
await _runFlutterTest(path.join(flutterRoot, 'packages', 'flutter_localizations'), tableData: bigqueryApi?.tabledata);
await _runFlutterTest(path.join(flutterRoot, 'packages', 'flutter_test'), tableData: bigqueryApi?.tabledata, options: nullSafetyOptions);
await _runFlutterTest(path.join(flutterRoot, 'packages', 'flutter_test'), tableData: bigqueryApi?.tabledata, options: soundNullSafetyOptions);
await _runFlutterTest(path.join(flutterRoot, 'packages', 'fuchsia_remote_debug_protocol'), tableData: bigqueryApi?.tabledata);
await _runFlutterTest(path.join(flutterRoot, 'dev', 'integration_tests', 'non_nullable'), options: nullSafetyOptions);
await _runFlutterTest(path.join(flutterRoot, 'dev', 'integration_tests', 'non_nullable'), options: mixedModeNullSafetyOptions);
await _runFlutterTest(
path.join(flutterRoot, 'dev', 'tracing_tests'),
options: <String>['--enable-vmservice'],
......
# Use the parent analysis options settings and enable null-experiment.
include: ../../analysis_options.yaml
analyzer:
enable-experiment:
- non-nullable
errors:
always_require_non_null_named_parameters: false # not needed with nnbd
type_init_formals: false # https://github.com/dart-lang/linter/issues/2192
unrelated_type_equality_checks: false # https://github.com/dart-lang/linter/issues/2196
void_checks: false # https://github.com/dart-lang/linter/issues/2185
unnecessary_null_comparison: false # Turned off until null-safe rollout is complete.
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
// @dart = 2.10
// This example shows how to build a render tree with a non-cartesian coordinate
// system. Most of the guts of this examples are in src/sector_layout.dart.
......
......@@ -731,7 +731,7 @@ class _ContextMenuRoute<T> extends PopupRoute<T> {
}
@override
bool didPop(T result) {
bool didPop(T? result) {
_updateTweenRects();
return super.didPop(result);
}
......
......@@ -1049,7 +1049,7 @@ class _CupertinoModalPopupRoute<T> extends PopupRoute<T> {
/// * [CupertinoActionSheet], which is the widget usually returned by the
/// `builder` argument to [showCupertinoModalPopup].
/// * <https://developer.apple.com/design/human-interface-guidelines/ios/views/action-sheets/>
Future<T> showCupertinoModalPopup<T>({
Future<T?> showCupertinoModalPopup<T>({
required BuildContext context,
required WidgetBuilder builder,
ImageFilter? filter,
......@@ -1134,7 +1134,7 @@ Widget _buildCupertinoDialogTransitions(BuildContext context, Animation<double>
/// * [showDialog], which displays a Material-style dialog.
/// * [showGeneralDialog], which allows for customization of the dialog popup.
/// * <https://developer.apple.com/ios/human-interface-guidelines/views/alerts/>
Future<T> showCupertinoDialog<T>({
Future<T?> showCupertinoDialog<T>({
required BuildContext context,
required WidgetBuilder builder,
bool useRootNavigator = true,
......
......@@ -619,8 +619,9 @@ class RestorableCupertinoTabController extends RestorableChangeNotifier<Cupertin
}
@override
CupertinoTabController fromPrimitives(Object data) {
return CupertinoTabController(initialIndex: data as int);
CupertinoTabController fromPrimitives(Object? data) {
assert(data != null);
return CupertinoTabController(initialIndex: data! as int);
}
@override
......
......@@ -781,7 +781,7 @@ class _CupertinoTextSelectionToolbarItemsElement extends RenderObjectElement {
}
if (slot is IndexedSlot) {
assert(renderObject.debugValidateChild(child));
renderObject.insert(child as RenderBox, after: slot.value?.renderObject as RenderBox);
renderObject.insert(child as RenderBox, after: slot.value?.renderObject as RenderBox?);
return;
}
assert(false, 'slot must be _CupertinoTextSelectionToolbarItemsSlot or IndexedSlot');
......@@ -1255,4 +1255,4 @@ class _NullElement extends Element {
class _NullWidget extends Widget {
@override
Element createElement() => throw UnimplementedError();
}
\ No newline at end of file
}
......@@ -166,7 +166,7 @@ void mergeSort<T>(
final int firstLength = middle - start;
final int secondLength = end - middle;
// secondLength is always the same as firstLength, or one greater.
final List<T?> scratchSpace = List<T?>.filled(secondLength, null, growable: false);
final List<T> scratchSpace = List<T>.filled(secondLength, list[start]);
_mergeSort<T>(list, compare, middle, end, scratchSpace, 0);
final int firstTarget = end - firstLength;
_mergeSort<T>(list, compare, start, middle, list, firstTarget);
......@@ -273,7 +273,7 @@ void _mergeSort<T>(
int Function(T, T) compare,
int start,
int end,
List<T?> target,
List<T> target,
int targetOffset,
) {
final int length = end - start;
......@@ -316,10 +316,10 @@ void _merge<T>(
List<T> firstList,
int firstStart,
int firstEnd,
List<T?> secondList,
List<T> secondList,
int secondStart,
int secondEnd,
List<T?> target,
List<T> target,
int targetOffset,
) {
// No empty lists reaches here.
......@@ -328,7 +328,7 @@ void _merge<T>(
int cursor1 = firstStart;
int cursor2 = secondStart;
T firstElement = firstList[cursor1++];
T secondElement = secondList[cursor2++] as T;
T secondElement = secondList[cursor2++];
while (true) {
if (compare(firstElement, secondElement) <= 0) {
target[targetOffset++] = firstElement;
......@@ -340,7 +340,7 @@ void _merge<T>(
} else {
target[targetOffset++] = secondElement;
if (cursor2 != secondEnd) {
secondElement = secondList[cursor2++] as T;
secondElement = secondList[cursor2++];
continue;
}
// Second list empties first. Flushing first list here.
......
......@@ -644,7 +644,7 @@ class _BottomSheetSuspendedCurve extends ParametricCurve<double> {
/// * [DraggableScrollableSheet], which allows you to create a bottom sheet
/// that grows and then becomes scrollable once it reaches its maximum size.
/// * <https://material.io/design/components/sheets-bottom.html#modal-bottom-sheet>
Future<T> showModalBottomSheet<T>({
Future<T?> showModalBottomSheet<T>({
required BuildContext context,
required WidgetBuilder builder,
Color? backgroundColor,
......
......@@ -955,7 +955,7 @@ Widget _buildMaterialDialogTransitions(BuildContext context, Animation<double> a
/// * [showCupertinoDialog], which displays an iOS-style dialog.
/// * [showGeneralDialog], which allows for customization of the dialog popup.
/// * <https://material.io/design/components/dialogs.html>
Future<T> showDialog<T>({
Future<T?> showDialog<T>({
required BuildContext context,
WidgetBuilder? builder,
bool barrierDismissible = true,
......
......@@ -120,7 +120,7 @@ typedef MaterialPropertyResolver<T> = T Function(Set<MaterialState> states);
/// }
/// ```
/// {@end-tool}
abstract class MaterialStateColor extends Color implements MaterialStateProperty<Color?> {
abstract class MaterialStateColor extends Color implements MaterialStateProperty<Color> {
/// Creates a [MaterialStateColor].
const MaterialStateColor(int defaultValue) : super(defaultValue);
......
......@@ -99,7 +99,7 @@ const double _inputFormLandscapeHeight = 108.0;
/// * [CalendarDatePicker], which provides the calendar grid used by the date picker dialog.
/// * [InputDatePickerFormField], which provides a text input field for entering dates.
///
Future<DateTime> showDatePicker({
Future<DateTime?> showDatePicker({
required BuildContext context,
required DateTime initialDate,
required DateTime firstDate,
......
......@@ -105,7 +105,7 @@ const double _inputFormLandscapeHeight = 108.0;
/// select a single date.
/// * [DateTimeRange], which is used to describe a date range.
///
Future<DateTimeRange> showDateRangePicker({
Future<DateTimeRange?> showDateRangePicker({
required BuildContext context,
DateTimeRange? initialDateRange,
required DateTime firstDate,
......
......@@ -829,7 +829,7 @@ class _PopupMenuRoute<T> extends PopupRoute<T> {
/// calling this method automatically.
/// * [SemanticsConfiguration.namesRoute], for a description of edge triggered
/// semantics.
Future<T> showMenu<T>({
Future<T?> showMenu<T>({
required BuildContext context,
required RelativeRect position,
required List<PopupMenuEntry<T>> items,
......@@ -1088,7 +1088,7 @@ class PopupMenuButtonState<T> extends State<PopupMenuButton<T>> {
final List<PopupMenuEntry<T>> items = widget.itemBuilder(context);
// Only show the menu if there is something to show
if (items.isNotEmpty) {
showMenu<T>(
showMenu<T?>(
context: context,
elevation: widget.elevation ?? popupMenuTheme.elevation,
items: items,
......@@ -1098,7 +1098,7 @@ class PopupMenuButtonState<T> extends State<PopupMenuButton<T>> {
color: widget.color ?? popupMenuTheme.color,
captureInheritedThemes: widget.captureInheritedThemes,
)
.then<void>((T newValue) {
.then<void>((T? newValue) {
if (!mounted)
return null;
if (newValue == null) {
......
......@@ -49,7 +49,7 @@ import 'theme.dart';
/// See also:
///
/// * [SearchDelegate] to define the content of the search page.
Future<T> showSearch<T>({
Future<T?> showSearch<T>({
required BuildContext context,
required SearchDelegate<T> delegate,
String? query = '',
......@@ -387,7 +387,7 @@ class _SearchPageRoute<T> extends PageRoute<T> {
}
@override
void didComplete(T result) {
void didComplete(T? result) {
super.didComplete(result);
assert(delegate._route == this);
delegate._route = null;
......
......@@ -2175,7 +2175,7 @@ class _TimePickerDialogState extends State<_TimePickerDialog> {
/// date picker.
/// * [TimePickerThemeData], which allows you to customize the colors,
/// typography, and shape of the time picker.
Future<TimeOfDay> showTimePicker({
Future<TimeOfDay?> showTimePicker({
required BuildContext context,
required TimeOfDay initialTime,
TransitionBuilder? builder,
......
......@@ -379,12 +379,12 @@ abstract class ImageProvider<T extends Object> {
/// [FlutterError.onError], and the method will return null.
///
/// A completed return value of null indicates that an error has occurred.
Future<ImageCacheStatus> obtainCacheStatus({
Future<ImageCacheStatus?> obtainCacheStatus({
required ImageConfiguration configuration,
ImageErrorListener? handleError,
}) {
assert(configuration != null);
final Completer<ImageCacheStatus> completer = Completer<ImageCacheStatus>();
final Completer<ImageCacheStatus?> completer = Completer<ImageCacheStatus?>();
_createErrorHandlerAndKey(
configuration,
(T key, ImageErrorListener innerHandleError) {
......
......@@ -390,7 +390,7 @@ class RenderTable extends RenderBox {
_textBaseline = textBaseline,
_defaultVerticalAlignment = defaultVerticalAlignment,
_configuration = configuration {
_children = <RenderBox>[]..length = _columns * _rows;
_children = <RenderBox?>[]..length = _columns * _rows;
this.rowDecorations = rowDecorations; // must use setter to initialize box painters array
children?.forEach(addRow);
}
......@@ -645,7 +645,7 @@ class RenderTable extends RenderBox {
// update our internal values
_columns = columns;
_rows = cells.length ~/ columns;
_children = cells.toList();
_children = List<RenderBox?>.from(cells);
assert(_children.length == rows * columns);
markNeedsLayout();
}
......
......@@ -151,13 +151,13 @@ class RestorationManager extends ChangeNotifier {
return SynchronousFuture<RestorationBucket?>(_rootBucket);
}
if (_pendingRootBucket == null) {
_pendingRootBucket = Completer<RestorationBucket>();
_pendingRootBucket = Completer<RestorationBucket?>();
_getRootBucketFromEngine();
}
return _pendingRootBucket!.future;
}
RestorationBucket? _rootBucket; // May be null to indicate that restoration is turned off.
Completer<RestorationBucket>? _pendingRootBucket;
Completer<RestorationBucket?>? _pendingRootBucket;
bool _rootBucketIsValid = false;
/// Returns true for the frame after [rootBucket] has been replaced with a
......@@ -186,7 +186,7 @@ class RestorationManager extends ChangeNotifier {
void _parseAndHandleRestorationUpdateFromEngine(Map<dynamic, dynamic>? update) {
handleRestorationUpdateFromEngine(
enabled: update != null && update['enabled'] as bool,
data: update == null ? null : update['data'] as Uint8List,
data: update == null ? null : update['data'] as Uint8List?,
);
}
......@@ -580,10 +580,10 @@ class RestorationBucket {
/// * [remove], which removes a value from the bucket.
/// * [contains], which checks whether any value is stored under a given
/// restoration ID.
P read<P>(String restorationId) {
P? read<P>(String restorationId) {
assert(_debugAssertNotDisposed());
assert(restorationId != null);
return _rawValues[restorationId] as P;
return _rawValues[restorationId] as P?;
}
/// Stores the provided `value` of type `P` under the provided `restorationId`
......@@ -624,11 +624,11 @@ class RestorationBucket {
/// * [write], which stores a value in the bucket.
/// * [contains], which checks whether any value is stored under a given
/// restoration ID.
P remove<P>(String restorationId) {
P? remove<P>(String restorationId) {
assert(_debugAssertNotDisposed());
assert(restorationId != null);
final bool needsUpdate = _rawValues.containsKey(restorationId);
final P result = _rawValues.remove(restorationId) as P;
final P? result = _rawValues.remove(restorationId) as P?;
if (_rawValues.isEmpty) {
_rawData.remove(_valuesMapKey);
}
......
......@@ -28,7 +28,7 @@ typedef DismissDirectionCallback = void Function(DismissDirection direction);
/// confirm or veto a dismiss gesture.
///
/// Used by [Dismissible.confirmDismiss].
typedef ConfirmDismissCallback = Future<bool> Function(DismissDirection direction);
typedef ConfirmDismissCallback = Future<bool?> Function(DismissDirection direction);
/// The direction in which a [Dismissible] can be dismissed.
enum DismissDirection {
......@@ -120,7 +120,7 @@ class Dismissible extends StatefulWidget {
/// If the returned Future<bool> completes true, then this widget will be
/// dismissed, otherwise it will be moved back to its original location.
///
/// If the returned Future<bool> completes to false or null the [onResize]
/// If the returned Future<bool?> completes to false or null the [onResize]
/// and [onDismissed] callbacks will not run.
final ConfirmDismissCallback? confirmDismiss;
......@@ -458,7 +458,7 @@ class _DismissibleState extends State<Dismissible> with TickerProviderStateMixin
updateKeepAlive();
}
Future<bool> _confirmStartResizeAnimation() async {
Future<bool?> _confirmStartResizeAnimation() async {
if (widget.confirmDismiss != null) {
final DismissDirection direction = _dismissDirection!;
assert(direction != null);
......
......@@ -300,7 +300,7 @@ class Hero extends StatefulWidget {
// the Hero is inside a nested Navigator and should only be
// considered for animation if it is part of the top-most route in
// that nested Navigator and if that route is also a PageRoute.
final ModalRoute<Object>? heroRoute = ModalRoute.of(hero);
final ModalRoute<Object?>? heroRoute = ModalRoute.of(hero);
if (heroRoute != null && heroRoute is PageRoute && heroRoute.isCurrent) {
inviteHero(hero, tag);
}
......
......@@ -450,7 +450,7 @@ class Localizations extends StatefulWidget {
assert(context != null);
assert(type != null);
final _LocalizationsScope? scope = context.dependOnInheritedWidgetOfExactType<_LocalizationsScope>();
return scope?.localizationsState.resourcesFor<T>(type);
return scope?.localizationsState.resourcesFor<T?>(type);
}
@override
......
......@@ -159,7 +159,7 @@ class AnimatedModalBarrier extends AnimatedWidget {
///
/// * [ModalRoute.barrierColor], which controls this property for the
/// [AnimatedModalBarrier] built by [ModalRoute] pages.
Animation<Color> get color => listenable as Animation<Color>;
Animation<Color?> get color => listenable as Animation<Color?>;
/// Whether touching the barrier will pop the current route off the [Navigator].
///
......
......@@ -425,7 +425,7 @@ abstract class RestorableProperty<T> extends ChangeNotifier {
/// [RestorableProperty]. Whenever new restoration data has been provided to
/// the [RestorationMixin] the property is registered to, either this method
/// or [createDefaultValue] is called before [initWithValue] is invoked.
T fromPrimitives(Object data);
T fromPrimitives(Object? data);
/// Called by the [RestorationMixin] with the `value` returned by either
/// [createDefaultValue] or [fromPrimitives] to set the value that this
......@@ -884,7 +884,7 @@ mixin RestorationMixin<S extends StatefulWidget> on State<S> {
/// restore the internal state of a [State] object, it may be removed from the
/// restoration data by calling this method.
@protected
void unregisterFromRestoration(RestorableProperty<Object> property) {
void unregisterFromRestoration(RestorableProperty<Object?> property) {
assert(property != null);
assert(property._owner == this);
_bucket?.remove<Object?>(property._restorationId!);
......
......@@ -173,9 +173,9 @@ class _RestorablePrimitiveValue<T extends Object> extends RestorableValue<T> {
}
@override
T fromPrimitives(Object serialized) {
T fromPrimitives(Object? serialized) {
assert(serialized != null);
return serialized as T;
return serialized! as T;
}
@override
......@@ -360,8 +360,8 @@ class RestorableTextEditingController extends RestorableChangeNotifier<TextEditi
}
@override
TextEditingController fromPrimitives(Object data) {
return TextEditingController(text: data as String);
TextEditingController fromPrimitives(Object? data) {
return TextEditingController(text: data! as String);
}
@override
......
......@@ -62,7 +62,7 @@ abstract class OverlayRoute<T> extends Route<T> {
bool get finishedWhenPopped => true;
@override
bool didPop(T result) {
bool didPop(T? result) {
final bool returnValue = super.didPop(result);
assert(returnValue);
if (finishedWhenPopped)
......@@ -90,8 +90,8 @@ abstract class TransitionRoute<T> extends OverlayRoute<T> {
/// This future completes once the animation has been dismissed. That will be
/// after [popped], because [popped] typically completes before the animation
/// even starts, as soon as the route is popped.
Future<T> get completed => _transitionCompleter.future;
final Completer<T> _transitionCompleter = Completer<T>();
Future<T?> get completed => _transitionCompleter.future;
final Completer<T?> _transitionCompleter = Completer<T?>();
/// {@template flutter.widgets.transitionRoute.transitionDuration}
/// The duration the transition going forwards.
......@@ -235,7 +235,7 @@ abstract class TransitionRoute<T> extends OverlayRoute<T> {
}
@override
bool didPop(T result) {
bool didPop(T? result) {
assert(_controller != null, '$runtimeType.didPop called before calling install() or after calling dispose().');
assert(!_transitionCompleter.isCompleted, 'Cannot reuse a $runtimeType after disposing it.');
_result = result;
......@@ -631,7 +631,7 @@ mixin LocalHistoryRoute<T> on Route<T> {
}
@override
bool didPop(T result) {
bool didPop(T? result) {
if (_localHistory != null && _localHistory!.isNotEmpty) {
final LocalHistoryEntry entry = _localHistory!.removeLast();
assert(entry._owner == this);
......@@ -1818,7 +1818,7 @@ class _DialogRoute<T> extends PopupRoute<T> {
///
/// * [showDialog], which displays a Material-style dialog.
/// * [showCupertinoDialog], which displays an iOS-style dialog.
Future<T> showGeneralDialog<T extends Object?>({
Future<T?> showGeneralDialog<T extends Object?>({
required BuildContext context,
required RoutePageBuilder pageBuilder,
bool barrierDismissible = false,
......
......@@ -1084,8 +1084,8 @@ class _RestorableScrollOffset extends RestorableValue<double?> {
}
@override
double fromPrimitives(Object data) {
return data as double;
double fromPrimitives(Object? data) {
return data! as double;
}
@override
......
......@@ -303,16 +303,16 @@ class _TableElement extends RenderObjectElement {
}
@override
void insertRenderObjectChild(RenderObject child, IndexedSlot<Element>? slot) {
void insertRenderObjectChild(RenderObject child, dynamic slot) {
renderObject.setupParentData(child);
}
@override
void moveRenderObjectChild(RenderObject child, IndexedSlot<Element>? oldSlot, IndexedSlot<Element>? newSlot) {
void moveRenderObjectChild(RenderObject child, dynamic oldSlot, dynamic newSlot) {
}
@override
void removeRenderObjectChild(RenderObject child, IndexedSlot<Element>? slot) {
void removeRenderObjectChild(RenderObject child, dynamic slot) {
final TableCellParentData childParentData = child.parentData! as TableCellParentData;
renderObject.setChild(childParentData.x!, childParentData.y!, null);
}
......
......@@ -111,7 +111,7 @@ void main() {
test('Notifies onBytesReceived with gzipped numbers', () async {
response.contentLength = gzipped.length;
final List<int?> records = <int>[];
final List<int?> records = <int?>[];
await consolidateHttpClientResponseBytes(
response,
onBytesReceived: (int cumulative, int? total) {
......
......@@ -76,7 +76,7 @@ void main() {
test('subtreeDepth 1', () {
final Map<String, Object?> result = testTree.toDiagnosticsNode().toJsonMap(const DiagnosticsSerializationDelegate(subtreeDepth: 1));
expect(result.containsKey('properties'), isFalse);
final List<Map<String, Object>> children = result['children']! as List<Map<String, Object>>;
final List<Map<String, Object?>> children = result['children']! as List<Map<String, Object?>>;
expect(children[0].containsKey('children'), isFalse);
expect(children[1].containsKey('children'), isFalse);
expect(children[2].containsKey('children'), isFalse);
......@@ -85,7 +85,7 @@ void main() {
test('subtreeDepth 5', () {
final Map<String, Object?> result = testTree.toDiagnosticsNode().toJsonMap(const DiagnosticsSerializationDelegate(subtreeDepth: 5));
expect(result.containsKey('properties'), isFalse);
final List<Map<String, Object>> children = result['children']! as List<Map<String, Object>>;
final List<Map<String, Object?>> children = result['children']! as List<Map<String, Object?>>;
expect(children[0]['children'], hasLength(0));
expect(children[1]['children'], hasLength(3));
expect(children[2]['children'], hasLength(0));
......@@ -103,7 +103,7 @@ void main() {
subtreeDepth: 1,
));
expect(result['properties'], hasLength(7));
final List<Map<String, Object>> children = result['children']! as List<Map<String, Object>>;
final List<Map<String, Object?>> children = result['children']! as List<Map<String, Object?>>;
expect(children, hasLength(3));
expect(children[0]['properties'], hasLength(0));
expect(children[1]['properties'], hasLength(2));
......@@ -119,13 +119,13 @@ void main() {
},
));
expect(result['foo'], isTrue);
final List<Map<String, Object>> properties = result['properties']! as List<Map<String, Object>>;
final List<Map<String, Object?>> properties = result['properties']! as List<Map<String, Object?>>;
expect(properties, hasLength(7));
expect(properties.every((Map<String, Object> property) => property['foo'] == true), isTrue);
expect(properties.every((Map<String, Object?> property) => property['foo'] == true), isTrue);
final List<Map<String, Object>> children = result['children']! as List<Map<String, Object>>;
final List<Map<String, Object?>> children = result['children']! as List<Map<String, Object?>>;
expect(children, hasLength(3));
expect(children.every((Map<String, Object> child) => child['foo'] == true), isTrue);
expect(children.every((Map<String, Object?> child) => child['foo'] == true), isTrue);
});
test('filterProperties - sublist', () {
......@@ -135,9 +135,9 @@ void main() {
return nodes.whereType<StringProperty>().toList();
},
));
final List<Map<String, Object>> properties = result['properties']! as List<Map<String, Object>>;
final List<Map<String, Object?>> properties = result['properties']! as List<Map<String, Object?>>;
expect(properties, hasLength(3));
expect(properties.every((Map<String, Object> property) => property['type'] == 'StringProperty'), isTrue);
expect(properties.every((Map<String, Object?> property) => property['type'] == 'StringProperty'), isTrue);
});
test('filterProperties - replace', () {
......@@ -154,7 +154,7 @@ void main() {
];
},
));
final List<Map<String, Object>> properties = result['properties']! as List<Map<String, Object>>;
final List<Map<String, Object?>> properties = result['properties']! as List<Map<String, Object?>>;
expect(properties, hasLength(1));
expect(properties.single['name'], 'foo');
});
......@@ -166,7 +166,7 @@ void main() {
return nodes.where((DiagnosticsNode node) => node.getProperties().isEmpty).toList();
},
));
final List<Map<String, Object>> children = result['children']! as List<Map<String, Object>>;
final List<Map<String, Object?>> children = result['children']! as List<Map<String, Object?>>;
expect(children, hasLength(1));
});
......@@ -177,7 +177,7 @@ void main() {
return nodes.expand((DiagnosticsNode node) => node.getChildren()).toList();
},
));
final List<Map<String, Object>> children = result['children']! as List<Map<String, Object>>;
final List<Map<String, Object?>> children = result['children']! as List<Map<String, Object?>>;
expect(children, hasLength(3));
expect(children.first['name'], 'child node B1');
});
......@@ -190,11 +190,11 @@ void main() {
return nodes.take(2).toList();
},
));
final List<Map<String, Object>> children = result['children']! as List<Map<String, Object>>;
final List<Map<String, Object?>> children = result['children']! as List<Map<String, Object?>>;
expect(children, hasLength(3));
expect(children.last['truncated'], isTrue);
final List<Map<String, Object>> properties = result['properties']! as List<Map<String, Object>>;
final List<Map<String, Object?>> properties = result['properties']! as List<Map<String, Object?>>;
expect(properties, hasLength(3));
expect(properties.last['truncated'], isTrue);
});
......@@ -207,13 +207,13 @@ void main() {
return delegate.copyWith(includeProperties: false);
},
));
final List<Map<String, Object>> properties = result['properties']! as List<Map<String, Object>>;
final List<Map<String, Object?>> properties = result['properties']! as List<Map<String, Object?>>;
expect(properties, hasLength(7));
expect(properties.every((Map<String, Object> property) => !property.containsKey('properties')), isTrue);
expect(properties.every((Map<String, Object?> property) => !property.containsKey('properties')), isTrue);
final List<Map<String, Object>> children = result['children']! as List<Map<String, Object>>;
final List<Map<String, Object?>> children = result['children']! as List<Map<String, Object?>>;
expect(children, hasLength(3));
expect(children.every((Map<String, Object> child) => !child.containsKey('properties')), isTrue);
expect(children.every((Map<String, Object?> child) => !child.containsKey('properties')), isTrue);
});
});
}
......
......@@ -47,15 +47,15 @@ enum ExampleEnum {
/// Encode and decode to JSON to make sure all objects in the JSON for the
/// [DiagnosticsNode] are valid JSON.
Map<String, Object> simulateJsonSerialization(DiagnosticsNode node) {
return json.decode(json.encode(node.toJsonMap(const DiagnosticsSerializationDelegate()))) as Map<String, Object>;
Map<String, Object?> simulateJsonSerialization(DiagnosticsNode node) {
return json.decode(json.encode(node.toJsonMap(const DiagnosticsSerializationDelegate()))) as Map<String, Object?>;
}
void validateNodeJsonSerialization(DiagnosticsNode node) {
validateNodeJsonSerializationHelper(simulateJsonSerialization(node), node);
}
void validateNodeJsonSerializationHelper(Map<String, Object> json, DiagnosticsNode node) {
void validateNodeJsonSerializationHelper(Map<String, Object?> json, DiagnosticsNode node) {
expect(json['name'], equals(node.name));
expect(json['showSeparator'] ?? true, equals(node.showSeparator));
expect(json['description'], equals(node.toDescription()));
......@@ -67,18 +67,18 @@ void validateNodeJsonSerializationHelper(Map<String, Object> json, DiagnosticsNo
expect(json['hasChildren'] ?? false, equals(node.getChildren().isNotEmpty));
}
void validatePropertyJsonSerialization(DiagnosticsProperty<Object> property) {
void validatePropertyJsonSerialization(DiagnosticsProperty<Object?> property) {
validatePropertyJsonSerializationHelper(simulateJsonSerialization(property), property);
}
void validateStringPropertyJsonSerialization(StringProperty property) {
final Map<String, Object> json = simulateJsonSerialization(property);
final Map<String, Object?> json = simulateJsonSerialization(property);
expect(json['quoted'], equals(property.quoted));
validatePropertyJsonSerializationHelper(json, property);
}
void validateFlagPropertyJsonSerialization(FlagProperty property) {
final Map<String, Object> json = simulateJsonSerialization(property);
final Map<String, Object?> json = simulateJsonSerialization(property);
expect(json['ifTrue'], equals(property.ifTrue));
if (property.ifTrue != null) {
......@@ -96,7 +96,7 @@ void validateFlagPropertyJsonSerialization(FlagProperty property) {
}
void validateDoublePropertyJsonSerialization(DoubleProperty property) {
final Map<String, Object> json = simulateJsonSerialization(property);
final Map<String, Object?> json = simulateJsonSerialization(property);
if (property.unit != null) {
expect(json['unit'], equals(property.unit));
} else {
......@@ -109,7 +109,7 @@ void validateDoublePropertyJsonSerialization(DoubleProperty property) {
}
void validateObjectFlagPropertyJsonSerialization(ObjectFlagProperty<Object> property) {
final Map<String, Object> json = simulateJsonSerialization(property);
final Map<String, Object?> json = simulateJsonSerialization(property);
if (property.ifPresent != null) {
expect(json['ifPresent'], equals(property.ifPresent));
} else {
......@@ -120,7 +120,7 @@ void validateObjectFlagPropertyJsonSerialization(ObjectFlagProperty<Object> prop
}
void validateIterableFlagsPropertyJsonSerialization(FlagsSummary<Object?> property) {
final Map<String, Object> json = simulateJsonSerialization(property);
final Map<String, Object?> json = simulateJsonSerialization(property);
if (property.value.isNotEmpty) {
expect(json['values'], equals(
property.value.entries
......@@ -135,9 +135,9 @@ void validateIterableFlagsPropertyJsonSerialization(FlagsSummary<Object?> proper
}
void validateIterablePropertyJsonSerialization(IterableProperty<Object> property) {
final Map<String, Object> json = simulateJsonSerialization(property);
final Map<String, Object?> json = simulateJsonSerialization(property);
if (property.value != null) {
final List<Object> valuesJson = json['values']! as List<Object>;
final List<Object?> valuesJson = json['values']! as List<Object?>;
final List<String> expectedValues = property.value!.map<String>((Object value) => value.toString()).toList();
expect(listEquals(valuesJson, expectedValues), isTrue);
} else {
......@@ -147,7 +147,7 @@ void validateIterablePropertyJsonSerialization(IterableProperty<Object> property
validatePropertyJsonSerializationHelper(json, property);
}
void validatePropertyJsonSerializationHelper(final Map<String, Object> json, DiagnosticsProperty<Object> property) {
void validatePropertyJsonSerializationHelper(final Map<String, Object?> json, DiagnosticsProperty<Object?> property) {
if (property.defaultValue != kNoDefaultValue) {
expect(json['defaultValue'], equals(property.defaultValue.toString()));
} else {
......@@ -1919,7 +1919,7 @@ void main() {
expect(messageProperty.name, equals('diagnostics'));
expect(messageProperty.value, isNull);
expect(messageProperty.showName, isTrue);
validatePropertyJsonSerialization(messageProperty as DiagnosticsProperty<Object>);
validatePropertyJsonSerialization(messageProperty as DiagnosticsProperty<Object?>);
});
test('error message style wrap test', () {
......@@ -2246,7 +2246,7 @@ void main() {
test('DiagnosticsProperty for basic types has value in json', () {
DiagnosticsProperty<int> intProperty = DiagnosticsProperty<int>('int1', 10);
Map<String, Object> json = simulateJsonSerialization(intProperty);
Map<String, Object?> json = simulateJsonSerialization(intProperty);
expect(json['name'], 'int1');
expect(json['value'], 10);
......
......@@ -249,7 +249,7 @@ void main() {
});
testWidgets('Return value from pop is correct', (WidgetTester tester) async {
late Future<Object> result;
late Future<Object?> result;
await tester.pumpWidget(
MaterialApp(
home: Builder(
......@@ -258,7 +258,7 @@ void main() {
child: ElevatedButton(
child: const Text('X'),
onPressed: () async {
result = Navigator.of(context)!.pushNamed('/a');
result = Navigator.of(context)!.pushNamed<Object?>('/a');
},
),
);
......
......@@ -233,7 +233,7 @@ void main() {
final BuildContext context = tester.element(find.text('Go'));
final Future<int> result = showDialog<int>(
final Future<int?> result = showDialog<int>(
context: context,
builder: (BuildContext context) {
return SimpleDialog(
......@@ -273,7 +273,7 @@ void main() {
),
);
final Future<int> result = showDialog<int>(
final Future<int?> result = showDialog<int>(
context: navigator.currentContext!,
builder: (BuildContext context) {
return SimpleDialog(
......@@ -1382,7 +1382,7 @@ void main() {
final List<int> dismissedItems = <int>[];
// Dismiss is confirmed IFF confirmDismiss() returns true.
Future<bool> confirmDismiss (DismissDirection dismissDirection) {
Future<bool?> confirmDismiss (DismissDirection dismissDirection) async {
return showDialog<bool>(
context: _scaffoldKey.currentContext!,
barrierDismissible: true, // showDialog() returns null if tapped outside the dialog
......@@ -1762,7 +1762,7 @@ void main() {
final BuildContext context = tester.element(find.text('Go'));
const RouteSettings exampleSetting = RouteSettings(name: 'simple');
final Future<int> result = showDialog<int>(
final Future<int?> result = showDialog<int>(
context: context,
builder: (BuildContext context) {
return SimpleDialog(
......
......@@ -465,7 +465,7 @@ void main() {
final WidgetPredicate popupMenu = (Widget widget) {
final String widgetType = widget.runtimeType.toString();
// TODO(mraleph): Remove the old case below.
return widgetType == '_PopupMenu<int>' // normal case
return widgetType == '_PopupMenu<int?>' // normal case
|| widgetType == '_PopupMenu'; // for old versions of Dart that don't reify method type arguments
};
......@@ -794,7 +794,7 @@ void main() {
await tester.pumpAndSettle();
// The position is different than the offset because the default position isn't at the origin.
expect(tester.getTopLeft(find.byWidgetPredicate((Widget w) => '${w.runtimeType}' == '_PopupMenu<int>')), const Offset(364.0, 324.0));
expect(tester.getTopLeft(find.byWidgetPredicate((Widget w) => '${w.runtimeType}' == '_PopupMenu<int?>')), const Offset(364.0, 324.0));
});
testWidgets('open PopupMenu has correct semantics', (WidgetTester tester) async {
......
......@@ -80,7 +80,7 @@ void main() {
// regression test for https://github.com/flutter/flutter/issues/18145
final _TestSearchDelegate delegate = _TestSearchDelegate();
final List<String> selectedResults = <String>[];
final List<String?> selectedResults = <String?>[];
await tester.pumpWidget(TestHomePage(
delegate: delegate,
......@@ -105,7 +105,7 @@ void main() {
await ServicesBinding.instance!.defaultBinaryMessenger.handlePlatformMessage('flutter/navigation', message, (_) { });
await tester.pumpAndSettle();
expect(selectedResults, <void>[null]);
expect(selectedResults, <String?>[null]);
// We are on the homepage again
expect(find.text('HomeBody'), findsOneWidget);
......@@ -374,7 +374,7 @@ void main() {
});
testWidgets('Closing nested search returns to search', (WidgetTester tester) async {
final List<String> nestedSearchResults = <String>[];
final List<String?> nestedSearchResults = <String?>[];
final _TestSearchDelegate nestedSearchDelegate = _TestSearchDelegate(
suggestions: 'Nested Suggestions',
result: 'Nested Result',
......@@ -389,7 +389,7 @@ void main() {
tooltip: 'Nested Search',
icon: const Icon(Icons.search),
onPressed: () async {
final String result = await showSearch(
final String? result = await showSearch(
context: context,
delegate: nestedSearchDelegate,
);
......@@ -467,7 +467,7 @@ void main() {
tooltip: 'Nested Search',
icon: const Icon(Icons.search),
onPressed: () async {
final String result = await showSearch(
final String? result = await showSearch(
context: context,
delegate: nestedSearchDelegate,
);
......@@ -702,7 +702,7 @@ class TestHomePage extends StatelessWidget {
this.initialQuery,
}) : super(key: key);
final List<String>? results;
final List<String?>? results;
final SearchDelegate<String> delegate;
final bool passInInitialQuery;
final String? initialQuery;
......@@ -719,7 +719,7 @@ class TestHomePage extends StatelessWidget {
tooltip: 'Search',
icon: const Icon(Icons.search),
onPressed: () async {
String selectedResult;
String? selectedResult;
if (passInInitialQuery) {
selectedResult = await showSearch<String>(
context: context,
......
......@@ -222,8 +222,8 @@ void main() {
});
testWidgets('Form.willPop callbacks do not accumulate', (WidgetTester tester) async {
Future<bool> showYesNoAlert(BuildContext context) {
return showDialog<bool>(
Future<bool> showYesNoAlert(BuildContext context) async {
return (await showDialog<bool>(
context: context,
builder: (BuildContext context) {
return AlertDialog(
......@@ -239,7 +239,7 @@ void main() {
],
);
},
);
))!;
}
Widget buildFrame() {
......
......@@ -823,7 +823,6 @@ class _TestRecordingCanvasPatternMatcher extends _TestRecordingCanvasMatcher imp
while (predicate.moveNext()) {
predicate.current.match(call);
}
assert(predicate.current == null);
// We allow painting more than expected.
} on _MismatchedCall catch (data) {
description.writeln(data.message);
......
......@@ -174,11 +174,11 @@ class FakeAndroidPlatformViewsController {
final Map<dynamic, dynamic> args = call.arguments as Map<dynamic, dynamic>;
final int id = args['id'] as int;
final String viewType = args['viewType'] as String;
final double width = args['width'] as double;
final double height = args['height'] as double;
final double? width = args['width'] as double?;
final double? height = args['height'] as double?;
final int layoutDirection = args['direction'] as int;
final bool hybrid = args['hybrid'] as bool;
final Uint8List creationParams = args['params'] as Uint8List;
final bool? hybrid = args['hybrid'] as bool?;
final Uint8List? creationParams = args['params'] as Uint8List?;
if (_views.containsKey(id))
throw PlatformException(
......@@ -197,7 +197,7 @@ class FakeAndroidPlatformViewsController {
}
_views[id] = FakeAndroidPlatformView(id, viewType,
width != null || height != null ? Size(width, height) : null,
width != null && height != null ? Size(width, height) : null,
layoutDirection,
hybrid,
creationParams,
......@@ -344,7 +344,7 @@ class FakeIosPlatformViewsController {
final Map<dynamic, dynamic> args = call.arguments as Map<dynamic, dynamic>;
final int id = args['id'] as int;
final String viewType = args['viewType'] as String;
final Uint8List creationParams = args['params'] as Uint8List;
final Uint8List? creationParams = args['params'] as Uint8List?;
if (_views.containsKey(id)) {
throw PlatformException(
......
......@@ -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 'package:flutter/painting.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart' show TestWidgetsFlutterBinding;
......
......@@ -58,7 +58,7 @@ class MockPaintingContext extends Fake implements PaintingContext {
void main() {
testWidgets('Control test for custom painting', (WidgetTester tester) async {
final List<String> log = <String>[];
final List<String?> log = <String?>[];
await tester.pumpWidget(CustomPaint(
painter: TestCustomPainter(
log: log,
......@@ -82,7 +82,7 @@ void main() {
testWidgets('Throws FlutterError on custom painter incorrect restore/save calls', (
WidgetTester tester) async {
final GlobalKey target = GlobalKey();
final List<String> log = <String>[];
final List<String?> log = <String?>[];
await tester.pumpWidget(CustomPaint(
key: target,
isComplex: true,
......@@ -174,7 +174,7 @@ void main() {
testWidgets('Raster cache hints', (WidgetTester tester) async {
final GlobalKey target = GlobalKey();
final List<String> log = <String>[];
final List<String?> log = <String?>[];
await tester.pumpWidget(CustomPaint(
key: target,
isComplex: true,
......
......@@ -18,7 +18,7 @@ const double crossAxisEndOffset = 0.5;
Widget buildTest({
double? startToEndThreshold,
TextDirection textDirection = TextDirection.ltr,
Future<bool> Function(BuildContext context, DismissDirection direction)? confirmDismiss,
Future<bool?> Function(BuildContext context, DismissDirection direction)? confirmDismiss,
}) {
return Directionality(
textDirection: textDirection,
......@@ -679,7 +679,7 @@ void main() {
return buildTest(
confirmDismiss: (BuildContext context, DismissDirection dismissDirection) {
confirmDismissDirection = dismissDirection;
return Future<bool>.value(confirmDismissValue);
return Future<bool?>.value(confirmDismissValue);
}
);
}
......
......@@ -1516,7 +1516,7 @@ void main() {
expect(imageCache!.liveImageCount, 1);
expect(imageCache!.containsKey(provider), false);
final ImageCacheStatus providerLocation = await provider.obtainCacheStatus(configuration: ImageConfiguration.empty);
final ImageCacheStatus providerLocation = (await provider.obtainCacheStatus(configuration: ImageConfiguration.empty))!;
expect(providerLocation, isNotNull);
expect(providerLocation.live, true);
......
......@@ -957,7 +957,7 @@ void main() {
});
testWidgets('replaceNamed returned value', (WidgetTester tester) async {
late Future<String> value;
late Future<String?> value;
final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{
'/' : (BuildContext context) => OnTapPage(id: '/', onTap: () { Navigator.pushNamed(context, '/A'); }),
......@@ -1001,7 +1001,7 @@ void main() {
expect(find.text('A'), findsNothing);
expect(find.text('B'), findsNothing);
final String replaceNamedValue = await value; // replaceNamed result was 'B'
final String? replaceNamedValue = await value; // replaceNamed result was 'B'
expect(replaceNamedValue, 'B');
});
......@@ -1092,7 +1092,7 @@ void main() {
});
testWidgets('remove a route whose value is awaited', (WidgetTester tester) async {
late Future<String> pageValue;
late Future<String?> pageValue;
final Map<String, WidgetBuilder> pageBuilders = <String, WidgetBuilder>{
'/': (BuildContext context) => OnTapPage(id: '/', onTap: () { pageValue = Navigator.pushNamed(context, '/A'); }),
'/A': (BuildContext context) => OnTapPage(id: 'A', onTap: () { Navigator.pop(context, 'A'); }),
......@@ -1113,7 +1113,7 @@ void main() {
await tester.tap(find.text('/')); // pushNamed('/A'), stack becomes /, /A
await tester.pumpAndSettle();
pageValue.then((String value) { assert(false); });
pageValue.then((String? value) { assert(false); });
final NavigatorState navigator = tester.state<NavigatorState>(find.byType(Navigator));
navigator.removeRoute(routes['/A']!); // stack becomes /, pageValue will not complete
......
......@@ -285,7 +285,7 @@ void main() {
});
}
class _TestRestorableValue extends RestorableValue<Object> {
class _TestRestorableValue extends RestorableValue<Object?> {
@override
Object createDefaultValue() {
return 55;
......@@ -300,12 +300,12 @@ class _TestRestorableValue extends RestorableValue<Object> {
}
@override
Object fromPrimitives(Object data) {
Object? fromPrimitives(Object? data) {
return data;
}
@override
Object toPrimitives() {
Object? toPrimitives() {
return value;
}
}
......
......@@ -632,7 +632,7 @@ void main() {
});
test('RestorableProperty throws after disposed', () {
final RestorableProperty<Object> property = _TestRestorableProperty(10);
final RestorableProperty<Object?> property = _TestRestorableProperty(10);
property.dispose();
expect(() => property.dispose(), throwsFlutterError);
});
......@@ -660,8 +660,8 @@ class _TestRestorableWidgetState extends State<_TestRestorableWidget> with Resto
_TestRestorableProperty? additionalProperty;
bool _rerigisterAdditionalProperty = false;
final List<RestorationBucket?> restoreStateLog = <RestorationBucket>[];
final List<RestorationBucket?> toggleBucketLog = <RestorationBucket>[];
final List<RestorationBucket?> restoreStateLog = <RestorationBucket?>[];
final List<RestorationBucket?> toggleBucketLog = <RestorationBucket?>[];
@override
void restoreState(RestorationBucket? oldBucket, bool initialRestore) {
......@@ -737,7 +737,7 @@ Map<String, dynamic> _createRawDataSet() {
};
}
class _TestRestorableProperty extends RestorableProperty<Object> {
class _TestRestorableProperty extends RestorableProperty<Object?> {
_TestRestorableProperty(this._value);
List<String> log = <String>[];
......@@ -751,35 +751,35 @@ class _TestRestorableProperty extends RestorableProperty<Object> {
}
@override
Object createDefaultValue() {
Object? createDefaultValue() {
log.add('createDefaultValue');
return _value;
}
@override
Object fromPrimitives(Object data) {
Object? fromPrimitives(Object? data) {
log.add('fromPrimitives');
return data;
}
Object get value {
Object? get value {
assert(isRegistered);
return _value;
}
Object _value;
set value(Object value) {
Object? _value;
set value(Object? value) {
_value = value;
notifyListeners();
}
@override
void initWithValue(Object v) {
void initWithValue(Object? v) {
log.add('initWithValue');
_value = v;
}
@override
Object toPrimitives() {
Object? toPrimitives() {
log.add('toPrimitives');
return _value;
}
......
......@@ -209,7 +209,7 @@ class TestWidget extends StatefulWidget {
}
class TestWidgetState extends State<TestWidget> with RestorationMixin {
List<RestorationBucket?> buckets = <RestorationBucket>[];
List<RestorationBucket?> buckets = <RestorationBucket?>[];
List<bool> flags = <bool>[];
@override
......
......@@ -302,7 +302,7 @@ void main() {
});
testWidgets('injects null when rootBucket is null', (WidgetTester tester) async {
final Completer<RestorationBucket> completer = Completer<RestorationBucket>();
final Completer<RestorationBucket?> completer = Completer<RestorationBucket?>();
binding.restorationManager.rootBucket = completer.future;
await tester.pumpWidget(
......
......@@ -1319,28 +1319,28 @@ void main() {
final Finder animatedModalBarrier = find.byType(AnimatedModalBarrier);
expect(animatedModalBarrier, findsOneWidget);
Animation<Color> modalBarrierAnimation;
Animation<Color?> modalBarrierAnimation;
modalBarrierAnimation = tester.widget<AnimatedModalBarrier>(animatedModalBarrier).color;
expect(modalBarrierAnimation.value, Colors.transparent);
await tester.pump(const Duration(milliseconds: 25));
modalBarrierAnimation = tester.widget<AnimatedModalBarrier>(animatedModalBarrier).color;
expect(
modalBarrierAnimation.value.alpha,
modalBarrierAnimation.value!.alpha,
closeTo(_getExpectedBarrierTweenAlphaValue(0.25), 1),
);
await tester.pump(const Duration(milliseconds: 25));
modalBarrierAnimation = tester.widget<AnimatedModalBarrier>(animatedModalBarrier).color;
expect(
modalBarrierAnimation.value.alpha,
modalBarrierAnimation.value!.alpha,
closeTo(_getExpectedBarrierTweenAlphaValue(0.50), 1),
);
await tester.pump(const Duration(milliseconds: 25));
modalBarrierAnimation = tester.widget<AnimatedModalBarrier>(animatedModalBarrier).color;
expect(
modalBarrierAnimation.value.alpha,
modalBarrierAnimation.value!.alpha,
closeTo(_getExpectedBarrierTweenAlphaValue(0.75), 1),
);
......@@ -1382,28 +1382,28 @@ void main() {
final Finder animatedModalBarrier = find.byType(AnimatedModalBarrier);
expect(animatedModalBarrier, findsOneWidget);
Animation<Color> modalBarrierAnimation;
Animation<Color?> modalBarrierAnimation;
modalBarrierAnimation = tester.widget<AnimatedModalBarrier>(animatedModalBarrier).color;
expect(modalBarrierAnimation.value, Colors.transparent);
await tester.pump(const Duration(milliseconds: 25));
modalBarrierAnimation = tester.widget<AnimatedModalBarrier>(animatedModalBarrier).color;
expect(
modalBarrierAnimation.value.alpha,
modalBarrierAnimation.value!.alpha,
closeTo(_getExpectedBarrierTweenAlphaValue(0.25), 1),
);
await tester.pump(const Duration(milliseconds: 25));
modalBarrierAnimation = tester.widget<AnimatedModalBarrier>(animatedModalBarrier).color;
expect(
modalBarrierAnimation.value.alpha,
modalBarrierAnimation.value!.alpha,
closeTo(_getExpectedBarrierTweenAlphaValue(0.50), 1),
);
await tester.pump(const Duration(milliseconds: 25));
modalBarrierAnimation = tester.widget<AnimatedModalBarrier>(animatedModalBarrier).color;
expect(
modalBarrierAnimation.value.alpha,
modalBarrierAnimation.value!.alpha,
closeTo(_getExpectedBarrierTweenAlphaValue(0.75), 1),
);
......
......@@ -49,27 +49,31 @@ class MatchesGoldenFile extends AsyncMatcher {
@override
Future<String?> matchAsync(dynamic item) async {
Future<ui.Image> imageFuture;
if (item is Future<ui.Image>) {
Future<ui.Image?> imageFuture;
if (item is Future<ui.Image?>) {
imageFuture = item;
} else if (item is ui.Image) {
imageFuture = Future<ui.Image>.value(item);
} else {
final Finder finder = item as Finder;
final Iterable<Element> elements = finder.evaluate();
} else if (item is Finder) {
final Iterable<Element> elements = item.evaluate();
if (elements.isEmpty) {
return 'could not be rendered because no widget was found';
} else if (elements.length > 1) {
return 'matched too many widgets';
}
imageFuture = captureImage(elements.single);
} else {
throw 'must provide a Finder, Image, or Future<Image>';
}
final Uri testNameUri = goldenFileComparator.getTestUri(key, version);
final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.ensureInitialized() as TestWidgetsFlutterBinding;
return binding.runAsync<String?>(() async {
final ui.Image image = await imageFuture;
final ui.Image? image = await imageFuture;
if (image == null) {
throw 'Future<Image> completed to null';
}
final ByteData? bytes = await image.toByteData(format: ui.ImageByteFormat.png);
if (bytes == null)
return 'could not encode screenshot.';
......
......@@ -1011,17 +1011,19 @@ class AutomatedTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
addTime(additionalTime);
return realAsyncZone.run<Future<T>>(() {
return realAsyncZone.run<Future<T?>>(() async {
_pendingAsyncTasks = Completer<void>();
return callback().catchError((Object exception, StackTrace stack) {
T? result;
try {
result = await callback();
} catch (exception, stack) {
FlutterError.reportError(FlutterErrorDetails(
exception: exception,
stack: stack,
library: 'Flutter test framework',
context: ErrorDescription('while running async test code'),
));
return null;
}).whenComplete(() {
} finally {
// We complete the _pendingAsyncTasks future successfully regardless of
// whether an exception occurred because in the case of an exception,
// we already reported the exception to FlutterError. Moreover,
......@@ -1029,7 +1031,8 @@ class AutomatedTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
// exception due to zone error boundaries.
_pendingAsyncTasks!.complete();
_pendingAsyncTasks = null;
});
}
return result;
});
}
......
......@@ -11,7 +11,7 @@ void testConfig(
String? expectedStringValue, {
Map<Type, dynamic> otherExpectedValues = const <Type, dynamic>{int: isNull},
}) {
final String actualStringValue = Zone.current[String] as String;
final String? actualStringValue = Zone.current[String] as String?;
final Map<Type, dynamic> otherActualValues = otherExpectedValues.map<Type, dynamic>(
(Type key, dynamic value) {
return MapEntry<Type, dynamic>(key, Zone.current[key]);
......
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