Unverified Commit f7ee4402 authored by Darren Austin's avatar Darren Austin Committed by GitHub

Migrate yet even more widget framework tests to null safety. (#67941)

Migrate yet even more widget framework tests to null safety.
parent f5608f2b
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/gestures.dart'; import 'package:flutter/gestures.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
@TestOn('chrome') @TestOn('chrome')
import 'dart:async'; import 'dart:async';
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/gestures.dart'; import 'package:flutter/gestures.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
...@@ -12,11 +10,11 @@ import 'package:flutter_test/flutter_test.dart'; ...@@ -12,11 +10,11 @@ import 'package:flutter_test/flutter_test.dart';
void main() { void main() {
test('IconDataDiagnosticsProperty includes valueProperties in JSON', () { test('IconDataDiagnosticsProperty includes valueProperties in JSON', () {
IconDataProperty property = IconDataProperty('foo', const IconData(101010)); IconDataProperty property = IconDataProperty('foo', const IconData(101010));
final Map<String, Object> valueProperties = property.toJsonMap(const DiagnosticsSerializationDelegate())['valueProperties'] as Map<String, Object>; final Map<String, Object> valueProperties = property.toJsonMap(const DiagnosticsSerializationDelegate())['valueProperties']! as Map<String, Object>;
expect(valueProperties['codePoint'], 101010); expect(valueProperties['codePoint'], 101010);
property = IconDataProperty('foo', null); property = IconDataProperty('foo', null);
final Map<String, Object> json = property.toJsonMap(const DiagnosticsSerializationDelegate()); final Map<String, Object?> json = property.toJsonMap(const DiagnosticsSerializationDelegate());
expect(json.containsKey('valueProperties'), isFalse); expect(json.containsKey('valueProperties'), isFalse);
}); });
} }
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
...@@ -25,7 +23,7 @@ void main() { ...@@ -25,7 +23,7 @@ void main() {
), ),
); );
final RichText text = tester.widget(find.byType(RichText)); final RichText text = tester.widget(find.byType(RichText));
expect(text.text.style.color, const Color(0xFF666666).withOpacity(0.5)); expect(text.text.style!.color, const Color(0xFF666666).withOpacity(0.5));
}); });
testWidgets('Icon sizing - no theme, default size', (WidgetTester tester) async { testWidgets('Icon sizing - no theme, default size', (WidgetTester tester) async {
...@@ -125,7 +123,7 @@ void main() { ...@@ -125,7 +123,7 @@ void main() {
); );
final RichText richText = tester.firstWidget(find.byType(RichText)); final RichText richText = tester.firstWidget(find.byType(RichText));
expect(richText.text.style.fontFamily, equals('Roboto')); expect(richText.text.style!.fontFamily, equals('Roboto'));
}); });
testWidgets('Icon with semantic label', (WidgetTester tester) async { testWidgets('Icon with semantic label', (WidgetTester tester) async {
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'dart:typed_data'; import 'dart:typed_data';
import 'dart:ui'; import 'dart:ui';
...@@ -78,8 +76,7 @@ void main() { ...@@ -78,8 +76,7 @@ void main() {
await pumpWithSigma(5.0); await pumpWithSigma(5.0);
final RenderObject renderObject = tester.firstRenderObject(find.byType(ImageFiltered)); final RenderObject renderObject = tester.firstRenderObject(find.byType(ImageFiltered));
final ImageFilterLayer originalLayer = renderObject.debugLayer as ImageFilterLayer; final ImageFilterLayer originalLayer = renderObject.debugLayer! as ImageFilterLayer;
expect(originalLayer, isNotNull);
// Change blur sigma to force a repaint. // Change blur sigma to force a repaint.
await pumpWithSigma(10.0); await pumpWithSigma(10.0);
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'dart:async'; import 'dart:async';
import 'dart:io'; import 'dart:io';
...@@ -25,7 +23,7 @@ void main() { ...@@ -25,7 +23,7 @@ void main() {
expect(MockHttpHeaders.headers['flutter'], <String>['flutter']); expect(MockHttpHeaders.headers['flutter'], <String>['flutter']);
}, createHttpClient: (SecurityContext _) { }, createHttpClient: (SecurityContext? _) {
return client; return client;
}); });
}, skip: isBrowser); // https://github.com/flutter/flutter/issues/57187 }, skip: isBrowser); // https://github.com/flutter/flutter/issues/57187
...@@ -62,7 +60,7 @@ class MockHttpClientResponse extends Fake implements HttpClientResponse { ...@@ -62,7 +60,7 @@ class MockHttpClientResponse extends Fake implements HttpClientResponse {
HttpClientResponseCompressionState get compressionState => HttpClientResponseCompressionState.decompressed; HttpClientResponseCompressionState get compressionState => HttpClientResponseCompressionState.decompressed;
@override @override
StreamSubscription<List<int>> listen(void Function(List<int> event) onData, {Function onError, void Function() onDone, bool cancelOnError}) { StreamSubscription<List<int>> listen(void Function(List<int> event)? onData, {Function? onError, void Function()? onDone, bool? cancelOnError}) {
return Stream<List<int>>.fromIterable(<List<int>>[kTransparentImage]).listen( return Stream<List<int>>.fromIterable(<List<int>>[kTransparentImage]).listen(
onData, onData,
onDone: onDone, onDone: onDone,
...@@ -78,6 +76,6 @@ class MockHttpHeaders extends Fake implements HttpHeaders { ...@@ -78,6 +76,6 @@ class MockHttpHeaders extends Fake implements HttpHeaders {
@override @override
void add(String key, Object value, { bool preserveHeaderCase = false }) { void add(String key, Object value, { bool preserveHeaderCase = false }) {
headers[key] ??= <String>[]; headers[key] ??= <String>[];
headers[key].add(value.toString()); headers[key]!.add(value.toString());
} }
} }
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
...@@ -12,7 +10,7 @@ import '../painting/mocks_for_image_cache.dart'; ...@@ -12,7 +10,7 @@ import '../painting/mocks_for_image_cache.dart';
void main() { void main() {
ImageProvider _image; late ImageProvider _image;
setUpAll(() async { setUpAll(() async {
_image = TestImageProvider( _image = TestImageProvider(
...@@ -45,8 +43,7 @@ void main() { ...@@ -45,8 +43,7 @@ void main() {
); );
final Image image = tester.widget(find.byType(Image)); final Image image = tester.widget(find.byType(Image));
expect(image, isNotNull); expect(image.color!.alpha, equals(128));
expect(image.color.alpha, equals(128));
}); });
testWidgets('ImageIcon sizing - no theme, explicit size', (WidgetTester tester) async { testWidgets('ImageIcon sizing - no theme, explicit size', (WidgetTester tester) async {
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
@TestOn('!chrome') // asset bundle behaves differently. @TestOn('!chrome') // asset bundle behaves differently.
import 'dart:typed_data'; import 'dart:typed_data';
import 'dart:ui' as ui show Image; import 'dart:ui' as ui show Image;
...@@ -43,7 +41,7 @@ class TestAssetBundle extends CachingAssetBundle { ...@@ -43,7 +41,7 @@ class TestAssetBundle extends CachingAssetBundle {
@override @override
Future<ByteData> load(String key) { Future<ByteData> load(String key) {
ByteData data; late ByteData data;
switch (key) { switch (key) {
case 'assets/image.png': case 'assets/image.png':
data = TestByteData(1.0); data = TestByteData(1.0);
...@@ -71,7 +69,7 @@ class TestAssetBundle extends CachingAssetBundle { ...@@ -71,7 +69,7 @@ class TestAssetBundle extends CachingAssetBundle {
Future<String> loadString(String key, { bool cache = true }) { Future<String> loadString(String key, { bool cache = true }) {
if (key == 'AssetManifest.json') if (key == 'AssetManifest.json')
return SynchronousFuture<String>(manifest); return SynchronousFuture<String>(manifest);
return SynchronousFuture<String>(null); return SynchronousFuture<String>('');
} }
@override @override
...@@ -91,21 +89,20 @@ class TestAssetImage extends AssetImage { ...@@ -91,21 +89,20 @@ class TestAssetImage extends AssetImage {
@override @override
ImageStreamCompleter load(AssetBundleImageKey key, DecoderCallback decode) { ImageStreamCompleter load(AssetBundleImageKey key, DecoderCallback decode) {
ImageInfo imageInfo; late ImageInfo imageInfo;
key.bundle.load(key.name).then<void>((ByteData data) { key.bundle.load(key.name).then<void>((ByteData data) {
final TestByteData testData = data as TestByteData; final TestByteData testData = data as TestByteData;
final ui.Image image = images[testData.scale]; final ui.Image image = images[testData.scale]!;
assert(image != null, 'Expected ${testData.scale} to have a key in $images'); assert(image != null, 'Expected ${testData.scale} to have a key in $images');
imageInfo = ImageInfo(image: image, scale: key.scale); imageInfo = ImageInfo(image: image, scale: key.scale);
}); });
assert(imageInfo != null);
return FakeImageStreamCompleter( return FakeImageStreamCompleter(
SynchronousFuture<ImageInfo>(imageInfo) SynchronousFuture<ImageInfo>(imageInfo)
); );
} }
} }
Widget buildImageAtRatio(String imageName, Key key, double ratio, bool inferSize, Map<double, ui.Image> images, [ AssetBundle bundle ]) { Widget buildImageAtRatio(String imageName, Key key, double ratio, bool inferSize, Map<double, ui.Image> images, [ AssetBundle? bundle ]) {
const double windowSize = 500.0; // 500 logical pixels const double windowSize = 500.0; // 500 logical pixels
const double imageSize = 200.0; // 200 logical pixels const double imageSize = 200.0; // 200 logical pixels
...@@ -313,12 +310,12 @@ void main() { ...@@ -313,12 +310,12 @@ void main() {
await pumpTreeToLayout(tester, buildImageAtRatio(image, key, ratio, false, images, bundle)); await pumpTreeToLayout(tester, buildImageAtRatio(image, key, ratio, false, images, bundle));
expect(getRenderImage(tester, key).size, const Size(200.0, 200.0)); expect(getRenderImage(tester, key).size, const Size(200.0, 200.0));
// Verify we got the 10x scaled image, since the TestByteData said it should be 10x. // Verify we got the 10x scaled image, since the TestByteData said it should be 10x.
expect(getRenderImage(tester, key).image.height, 480); expect(getRenderImage(tester, key).image!.height, 480);
key = GlobalKey(); key = GlobalKey();
await pumpTreeToLayout(tester, buildImageAtRatio(image, key, ratio, true, images, bundle)); await pumpTreeToLayout(tester, buildImageAtRatio(image, key, ratio, true, images, bundle));
expect(getRenderImage(tester, key).size, const Size(480.0, 480.0)); expect(getRenderImage(tester, key).size, const Size(480.0, 480.0));
// Verify we got the 10x scaled image, since the TestByteData said it should be 10x. // Verify we got the 10x scaled image, since the TestByteData said it should be 10x.
expect(getRenderImage(tester, key).image.height, 480); expect(getRenderImage(tester, key).image!.height, 480);
}); });
testWidgets('Image cache resize upscale display 5', (WidgetTester tester) async { testWidgets('Image cache resize upscale display 5', (WidgetTester tester) async {
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'dart:ui' as ui show Image; import 'dart:ui' as ui show Image;
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
...@@ -31,7 +29,7 @@ class TestImageProvider extends ImageProvider<TestImageProvider> { ...@@ -31,7 +29,7 @@ class TestImageProvider extends ImageProvider<TestImageProvider> {
} }
void main() { void main() {
ui.Image testImage; late ui.Image testImage;
setUpAll(() async { setUpAll(() async {
testImage = await createTestImage(width: 16, height: 9); testImage = await createTestImage(width: 16, height: 9);
}); });
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
...@@ -20,7 +18,7 @@ const Duration animationDuration = Duration(milliseconds:1000); ...@@ -20,7 +18,7 @@ const Duration animationDuration = Duration(milliseconds:1000);
const Duration additionalDelay = Duration(milliseconds:1); const Duration additionalDelay = Duration(milliseconds:1);
void main() { void main() {
MockOnEndFunction mockOnEndFunction; late MockOnEndFunction mockOnEndFunction;
const Key switchKey = Key('switchKey'); const Key switchKey = Key('switchKey');
setUp(() { setUp(() {
...@@ -355,7 +353,7 @@ void main() { ...@@ -355,7 +353,7 @@ void main() {
}); });
} }
Widget wrap({Widget child}) { Widget wrap({required Widget child}) {
return Directionality( return Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: Material( child: Material(
...@@ -366,16 +364,13 @@ Widget wrap({Widget child}) { ...@@ -366,16 +364,13 @@ Widget wrap({Widget child}) {
class TestAnimatedWidget extends StatefulWidget { class TestAnimatedWidget extends StatefulWidget {
const TestAnimatedWidget({ const TestAnimatedWidget({
Key key, Key? key,
this.callback, this.callback,
this.switchKey, required this.switchKey,
this.state, required this.state,
}) : super(key: key); }) : super(key: key);
@required final VoidCallback? callback;
final VoidCallback callback;
@required
final Key switchKey; final Key switchKey;
@required
final State<StatefulWidget> state; final State<StatefulWidget> state;
@override @override
...@@ -408,7 +403,6 @@ abstract class _TestAnimatedWidgetState extends State<TestAnimatedWidget> { ...@@ -408,7 +403,6 @@ abstract class _TestAnimatedWidgetState extends State<TestAnimatedWidget> {
} }
} }
class _TestAnimatedContainerWidgetState extends _TestAnimatedWidgetState { class _TestAnimatedContainerWidgetState extends _TestAnimatedWidgetState {
@override @override
Widget getAnimatedWidget() { Widget getAnimatedWidget() {
...@@ -553,7 +547,7 @@ class _TestTweenAnimationBuilderWidgetState extends _TestAnimatedWidgetState { ...@@ -553,7 +547,7 @@ class _TestTweenAnimationBuilderWidgetState extends _TestAnimatedWidgetState {
tween: Tween<double>(begin: 1, end: 2), tween: Tween<double>(begin: 1, end: 2),
duration: duration, duration: duration,
onEnd: widget.callback, onEnd: widget.callback,
builder: (BuildContext context, double size, Widget child) { builder: (BuildContext context, double? size, Widget? child) {
return Container( return Container(
child: child, child: child,
width: size, width: size,
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
...@@ -13,7 +11,7 @@ const Size _kTestViewSize = Size(800.0, 600.0); ...@@ -13,7 +11,7 @@ const Size _kTestViewSize = Size(800.0, 600.0);
class OffscreenRenderView extends RenderView { class OffscreenRenderView extends RenderView {
OffscreenRenderView() : super( OffscreenRenderView() : super(
configuration: const ViewConfiguration(size: _kTestViewSize), configuration: const ViewConfiguration(size: _kTestViewSize),
window: WidgetsBinding.instance.window, window: WidgetsBinding.instance!.window,
); );
@override @override
...@@ -32,7 +30,7 @@ class OffscreenWidgetTree { ...@@ -32,7 +30,7 @@ class OffscreenWidgetTree {
final RenderView renderView = OffscreenRenderView(); final RenderView renderView = OffscreenRenderView();
final BuildOwner buildOwner = BuildOwner(); final BuildOwner buildOwner = BuildOwner();
final PipelineOwner pipelineOwner = PipelineOwner(); final PipelineOwner pipelineOwner = PipelineOwner();
RenderObjectToWidgetElement<RenderBox> root; RenderObjectToWidgetElement<RenderBox>? root;
void pumpWidget(Widget app) { void pumpWidget(Widget app) {
root = RenderObjectToWidgetAdapter<RenderBox>( root = RenderObjectToWidgetAdapter<RenderBox>(
...@@ -44,7 +42,7 @@ class OffscreenWidgetTree { ...@@ -44,7 +42,7 @@ class OffscreenWidgetTree {
} }
void pumpFrame() { void pumpFrame() {
buildOwner.buildScope(root); buildOwner.buildScope(root!);
pipelineOwner.flushLayout(); pipelineOwner.flushLayout();
pipelineOwner.flushCompositingBits(); pipelineOwner.flushCompositingBits();
pipelineOwner.flushPaint(); pipelineOwner.flushPaint();
...@@ -60,18 +58,18 @@ class Counter { ...@@ -60,18 +58,18 @@ class Counter {
} }
class Trigger { class Trigger {
VoidCallback callback; VoidCallback? callback;
void fire() { void fire() {
if (callback != null) if (callback != null)
callback(); callback!();
} }
} }
class TriggerableWidget extends StatefulWidget { class TriggerableWidget extends StatefulWidget {
const TriggerableWidget({ const TriggerableWidget({
Key key, Key? key,
this.trigger, required this.trigger,
this.counter, required this.counter,
}) : super(key: key); }) : super(key: key);
final Trigger trigger; final Trigger trigger;
...@@ -110,8 +108,8 @@ class TriggerableState extends State<TriggerableWidget> { ...@@ -110,8 +108,8 @@ class TriggerableState extends State<TriggerableWidget> {
class TestFocusable extends StatefulWidget { class TestFocusable extends StatefulWidget {
const TestFocusable({ const TestFocusable({
Key key, Key? key,
this.focusNode, required this.focusNode,
this.autofocus = true, this.autofocus = true,
}) : super(key: key); }) : super(key: key);
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/src/widgets/basic.dart'; import 'package:flutter/src/widgets/basic.dart';
import 'package:flutter/src/widgets/framework.dart'; import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
...@@ -19,7 +17,7 @@ void main() { ...@@ -19,7 +17,7 @@ void main() {
return const SizedBox(); return const SizedBox();
}), }),
)); ));
final InheritedElement element = key.currentContext as InheritedElement; final InheritedElement element = key.currentContext! as InheritedElement;
expect( expect(
element.toStringDeep(minLevel: DiagnosticLevel.info), element.toStringDeep(minLevel: DiagnosticLevel.info),
equalsIgnoringHashCodes( equalsIgnoringHashCodes(
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
...@@ -13,28 +11,28 @@ import 'package:flutter/material.dart'; ...@@ -13,28 +11,28 @@ import 'package:flutter/material.dart';
// valued fields: a, b, c. // valued fields: a, b, c.
class ABCModel extends InheritedModel<String> { class ABCModel extends InheritedModel<String> {
const ABCModel({ const ABCModel({
Key key, Key? key,
this.a, this.a,
this.b, this.b,
this.c, this.c,
this.aspects, this.aspects,
Widget child, required Widget child,
}) : super(key: key, child: child); }) : super(key: key, child: child);
final int a; final int? a;
final int b; final int? b;
final int c; final int? c;
// The aspects (fields) of this model that widgets can depend on with // The aspects (fields) of this model that widgets can depend on with
// inheritFrom. // inheritFrom.
// //
// This property is null by default, which means that the model supports // This property is null by default, which means that the model supports
// all 3 fields. // all 3 fields.
final Set<String> aspects; final Set<String>? aspects;
@override @override
bool isSupportedAspect(Object aspect) { bool isSupportedAspect(Object aspect) {
return aspect == null || aspects == null || aspects.contains(aspect); return aspect == null || aspects == null || aspects!.contains(aspect);
} }
@override @override
...@@ -50,13 +48,13 @@ class ABCModel extends InheritedModel<String> { ...@@ -50,13 +48,13 @@ class ABCModel extends InheritedModel<String> {
|| (c != old.c && dependencies.contains('c')); || (c != old.c && dependencies.contains('c'));
} }
static ABCModel of(BuildContext context, { String fieldName }) { static ABCModel? of(BuildContext context, { String? fieldName }) {
return InheritedModel.inheritFrom<ABCModel>(context, aspect: fieldName); return InheritedModel.inheritFrom<ABCModel>(context, aspect: fieldName);
} }
} }
class ShowABCField extends StatefulWidget { class ShowABCField extends StatefulWidget {
const ShowABCField({ Key key, this.fieldName }) : super(key: key); const ShowABCField({ Key? key, required this.fieldName }) : super(key: key);
final String fieldName; final String fieldName;
...@@ -69,8 +67,8 @@ class _ShowABCFieldState extends State<ShowABCField> { ...@@ -69,8 +67,8 @@ class _ShowABCFieldState extends State<ShowABCField> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final ABCModel abc = ABCModel.of(context, fieldName: widget.fieldName); final ABCModel abc = ABCModel.of(context, fieldName: widget.fieldName)!;
final int value = widget.fieldName == 'a' ? abc.a : (widget.fieldName == 'b' ? abc.b : abc.c); final int? value = widget.fieldName == 'a' ? abc.a : (widget.fieldName == 'b' ? abc.b : abc.c);
return Text('${widget.fieldName}: $value [${_buildCount++}]'); return Text('${widget.fieldName}: $value [${_buildCount++}]');
} }
} }
...@@ -91,7 +89,7 @@ void main() { ...@@ -91,7 +89,7 @@ void main() {
// aspect of the model changes. // aspect of the model changes.
final Widget showABC = Builder( final Widget showABC = Builder(
builder: (BuildContext context) { builder: (BuildContext context) {
final ABCModel abc = ABCModel.of(context); final ABCModel abc = ABCModel.of(context)!;
return Text('a: ${abc.a} b: ${abc.b} c: ${abc.c}'); return Text('a: ${abc.a} b: ${abc.b} c: ${abc.c}');
} }
); );
...@@ -193,7 +191,7 @@ void main() { ...@@ -193,7 +191,7 @@ void main() {
}); });
testWidgets('Looking up an non existent InheritedModel ancestor returns null', (WidgetTester tester) async { testWidgets('Looking up an non existent InheritedModel ancestor returns null', (WidgetTester tester) async {
ABCModel inheritedModel; ABCModel? inheritedModel;
await tester.pumpWidget( await tester.pumpWidget(
Builder( Builder(
...@@ -228,8 +226,8 @@ void main() { ...@@ -228,8 +226,8 @@ void main() {
// Which is the inner model, for which b,c are null. // Which is the inner model, for which b,c are null.
final Widget showABC = Builder( final Widget showABC = Builder(
builder: (BuildContext context) { builder: (BuildContext context) {
final ABCModel abc = ABCModel.of(context); final ABCModel abc = ABCModel.of(context)!;
return Text('a: ${abc.a} b: ${abc.b} c: ${abc.c}', style: Theme.of(context).textTheme.headline6); return Text('a: ${abc.a} b: ${abc.b} c: ${abc.c}', style: Theme.of(context)!.textTheme.headline6);
} }
); );
...@@ -330,7 +328,7 @@ void main() { ...@@ -330,7 +328,7 @@ void main() {
int _a = 0; int _a = 0;
int _b = 1; int _b = 1;
int _c = 2; int _c = 2;
Set<String> _innerModelAspects = <String>{'a'}; Set<String>? _innerModelAspects = <String>{'a'};
// Same as in abcPage in the "Inner InheritedModel shadows the outer one" // Same as in abcPage in the "Inner InheritedModel shadows the outer one"
// test except: the "Add b aspect" changes adds 'b' to the set of // test except: the "Add b aspect" changes adds 'b' to the set of
...@@ -345,8 +343,8 @@ void main() { ...@@ -345,8 +343,8 @@ void main() {
// Which is the inner model, for which b,c are null. // Which is the inner model, for which b,c are null.
final Widget showABC = Builder( final Widget showABC = Builder(
builder: (BuildContext context) { builder: (BuildContext context) {
final ABCModel abc = ABCModel.of(context); final ABCModel abc = ABCModel.of(context)!;
return Text('a: ${abc.a} b: ${abc.b} c: ${abc.c}', style: Theme.of(context).textTheme.headline6); return Text('a: ${abc.a} b: ${abc.b} c: ${abc.c}', style: Theme.of(context)!.textTheme.headline6);
} }
); );
......
...@@ -2,15 +2,13 @@ ...@@ -2,15 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'test_widgets.dart'; import 'test_widgets.dart';
class TestInherited extends InheritedWidget { class TestInherited extends InheritedWidget {
const TestInherited({ Key key, Widget child, this.shouldNotify = true }) const TestInherited({ Key? key, required Widget child, this.shouldNotify = true })
: super(key: key, child: child); : super(key: key, child: child);
final bool shouldNotify; final bool shouldNotify;
...@@ -22,7 +20,7 @@ class TestInherited extends InheritedWidget { ...@@ -22,7 +20,7 @@ class TestInherited extends InheritedWidget {
} }
class ValueInherited extends InheritedWidget { class ValueInherited extends InheritedWidget {
const ValueInherited({ Key key, Widget child, this.value }) const ValueInherited({ Key? key, required Widget child, required this.value })
: super(key: key, child: child); : super(key: key, child: child);
final int value; final int value;
...@@ -32,7 +30,7 @@ class ValueInherited extends InheritedWidget { ...@@ -32,7 +30,7 @@ class ValueInherited extends InheritedWidget {
} }
class ExpectFail extends StatefulWidget { class ExpectFail extends StatefulWidget {
const ExpectFail(this.onError, { Key key }) : super(key: key); const ExpectFail(this.onError, { Key? key }) : super(key: key);
final VoidCallback onError; final VoidCallback onError;
@override @override
...@@ -55,7 +53,7 @@ class ExpectFailState extends State<ExpectFail> { ...@@ -55,7 +53,7 @@ class ExpectFailState extends State<ExpectFail> {
} }
class ChangeNotifierInherited extends InheritedNotifier<ChangeNotifier> { class ChangeNotifierInherited extends InheritedNotifier<ChangeNotifier> {
const ChangeNotifierInherited({ Key key, Widget child, ChangeNotifier notifier }) const ChangeNotifierInherited({ Key? key, required Widget child, ChangeNotifier? notifier })
: super(key: key, child: child, notifier: notifier); : super(key: key, child: child, notifier: notifier);
} }
...@@ -65,7 +63,7 @@ void main() { ...@@ -65,7 +63,7 @@ void main() {
final Builder builder = Builder( final Builder builder = Builder(
builder: (BuildContext context) { builder: (BuildContext context) {
log.add(context.dependOnInheritedWidgetOfExactType<TestInherited>()); log.add(context.dependOnInheritedWidgetOfExactType<TestInherited>()!);
return Container(); return Container();
} }
); );
...@@ -97,7 +95,7 @@ void main() { ...@@ -97,7 +95,7 @@ void main() {
key: globalKey, key: globalKey,
child: Builder( child: Builder(
builder: (BuildContext context) { builder: (BuildContext context) {
log.add(context.dependOnInheritedWidgetOfExactType<TestInherited>()); log.add(context.dependOnInheritedWidgetOfExactType<TestInherited>()!);
return Container(); return Container();
} }
), ),
...@@ -134,7 +132,7 @@ void main() { ...@@ -134,7 +132,7 @@ void main() {
child: Container( child: Container(
child: Builder( child: Builder(
builder: (BuildContext context) { builder: (BuildContext context) {
final ValueInherited v = context.dependOnInheritedWidgetOfExactType<ValueInherited>(); final ValueInherited v = context.dependOnInheritedWidgetOfExactType<ValueInherited>()!;
log.add('a: ${v.value}'); log.add('a: ${v.value}');
return const Text('', textDirection: TextDirection.ltr); return const Text('', textDirection: TextDirection.ltr);
} }
...@@ -151,7 +149,7 @@ void main() { ...@@ -151,7 +149,7 @@ void main() {
child: Container( child: Container(
child: Builder( child: Builder(
builder: (BuildContext context) { builder: (BuildContext context) {
final ValueInherited v = context.dependOnInheritedWidgetOfExactType<ValueInherited>(); final ValueInherited v = context.dependOnInheritedWidgetOfExactType<ValueInherited>()!;
log.add('b: ${v.value}'); log.add('b: ${v.value}');
return const Text('', textDirection: TextDirection.ltr); return const Text('', textDirection: TextDirection.ltr);
} }
...@@ -209,7 +207,7 @@ void main() { ...@@ -209,7 +207,7 @@ void main() {
key: key, key: key,
child: Builder( child: Builder(
builder: (BuildContext context) { builder: (BuildContext context) {
final ValueInherited v = context.dependOnInheritedWidgetOfExactType<ValueInherited>(); final ValueInherited v = context.dependOnInheritedWidgetOfExactType<ValueInherited>()!;
log.add('a: ${v.value}'); log.add('a: ${v.value}');
return const Text('', textDirection: TextDirection.ltr); return const Text('', textDirection: TextDirection.ltr);
} }
...@@ -227,7 +225,7 @@ void main() { ...@@ -227,7 +225,7 @@ void main() {
key: key, key: key,
child: Builder( child: Builder(
builder: (BuildContext context) { builder: (BuildContext context) {
final ValueInherited v = context.dependOnInheritedWidgetOfExactType<ValueInherited>(); final ValueInherited v = context.dependOnInheritedWidgetOfExactType<ValueInherited>()!;
log.add('b: ${v.value}'); log.add('b: ${v.value}');
return const Text('', textDirection: TextDirection.ltr); return const Text('', textDirection: TextDirection.ltr);
} }
...@@ -270,7 +268,7 @@ void main() { ...@@ -270,7 +268,7 @@ void main() {
final Widget child = Builder( final Widget child = Builder(
builder: (BuildContext context) { builder: (BuildContext context) {
final ValueInherited v = context.dependOnInheritedWidgetOfExactType<ValueInherited>(); final ValueInherited v = context.dependOnInheritedWidgetOfExactType<ValueInherited>()!;
log.add(v.value); log.add(v.value);
return const Text('', textDirection: TextDirection.ltr); return const Text('', textDirection: TextDirection.ltr);
} }
...@@ -341,7 +339,7 @@ void main() { ...@@ -341,7 +339,7 @@ void main() {
final Widget child = Builder( final Widget child = Builder(
key: GlobalKey(), key: GlobalKey(),
builder: (BuildContext context) { builder: (BuildContext context) {
final ValueInherited v = context.dependOnInheritedWidgetOfExactType<ValueInherited>(); final ValueInherited v = context.dependOnInheritedWidgetOfExactType<ValueInherited>()!;
log.add(v.value); log.add(v.value);
return const Text('', textDirection: TextDirection.ltr); return const Text('', textDirection: TextDirection.ltr);
}, },
...@@ -382,13 +380,13 @@ void main() { ...@@ -382,13 +380,13 @@ void main() {
}); });
testWidgets('Inherited widget notifies descendants when descendant previously failed to find a match', (WidgetTester tester) async { testWidgets('Inherited widget notifies descendants when descendant previously failed to find a match', (WidgetTester tester) async {
int inheritedValue = -1; int? inheritedValue = -1;
final Widget inner = Container( final Widget inner = Container(
key: GlobalKey(), key: GlobalKey(),
child: Builder( child: Builder(
builder: (BuildContext context) { builder: (BuildContext context) {
final ValueInherited widget = context.dependOnInheritedWidgetOfExactType<ValueInherited>(); final ValueInherited? widget = context.dependOnInheritedWidgetOfExactType<ValueInherited>();
inheritedValue = widget?.value; inheritedValue = widget?.value;
return Container(); return Container();
} }
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
...@@ -14,7 +12,7 @@ class TestRoute extends PageRouteBuilder<void> { ...@@ -14,7 +12,7 @@ class TestRoute extends PageRouteBuilder<void> {
} }
class IconTextBox extends StatelessWidget { class IconTextBox extends StatelessWidget {
const IconTextBox(this.text, { Key key }) : super(key: key); const IconTextBox(this.text, { Key? key }) : super(key: key);
final String text; final String text;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
...@@ -34,7 +32,7 @@ void main() { ...@@ -34,7 +32,7 @@ void main() {
const Color textColor = Color(0xFF00FF00); const Color textColor = Color(0xFF00FF00);
const Color iconColor = Color(0xFF0000FF); const Color iconColor = Color(0xFF0000FF);
bool useCaptureAll = false; bool useCaptureAll = false;
BuildContext navigatorContext; late BuildContext navigatorContext;
Widget buildFrame() { Widget buildFrame() {
return WidgetsApp( return WidgetsApp(
...@@ -61,7 +59,7 @@ void main() { ...@@ -61,7 +59,7 @@ void main() {
behavior: HitTestBehavior.opaque, behavior: HitTestBehavior.opaque,
onTap: () { onTap: () {
navigatorContext = context; navigatorContext = context;
Navigator.of(context).push( Navigator.of(context)!.push(
TestRoute( TestRoute(
useCaptureAll useCaptureAll
? InheritedTheme.captureAll(context, const IconTextBox('Hello')) ? InheritedTheme.captureAll(context, const IconTextBox('Hello'))
...@@ -88,7 +86,7 @@ void main() { ...@@ -88,7 +86,7 @@ void main() {
of: find.byType(Icon), of: find.byType(Icon),
matching: find.byType(RichText), matching: find.byType(RichText),
), ),
).text.style; ).text.style!;
} }
TextStyle getTextStyle(String text) { TextStyle getTextStyle(String text) {
...@@ -97,7 +95,7 @@ void main() { ...@@ -97,7 +95,7 @@ void main() {
of: find.text(text), of: find.text(text),
matching: find.byType(RichText), matching: find.byType(RichText),
), ),
).text.style; ).text.style!;
} }
useCaptureAll = false; useCaptureAll = false;
...@@ -123,7 +121,7 @@ void main() { ...@@ -123,7 +121,7 @@ void main() {
// Return to the home route // Return to the home route
useCaptureAll = true; useCaptureAll = true;
Navigator.of(navigatorContext).pop(); Navigator.of(navigatorContext)!.pop();
await tester.pumpAndSettle(); // route transition await tester.pumpAndSettle(); // route transition
// Verify that all is the same as it was when the test started // Verify that all is the same as it was when the test started
...@@ -199,7 +197,7 @@ void main() { ...@@ -199,7 +197,7 @@ void main() {
of: find.byKey(key), of: find.byKey(key),
matching: find.byType(RichText), matching: find.byType(RichText),
), ),
).text.style; ).text.style!;
} }
expect(getIconStyle(icon1).color, innerColor); expect(getIconStyle(icon1).color, innerColor);
...@@ -245,7 +243,7 @@ void main() { ...@@ -245,7 +243,7 @@ void main() {
of: find.text(text), of: find.text(text),
matching: find.byType(RichText), matching: find.byType(RichText),
), ),
).text.style; ).text.style!;
} }
expect(getTextStyle('Hello').fontSize, null); expect(getTextStyle('Hello').fontSize, null);
......
...@@ -2,15 +2,13 @@ ...@@ -2,15 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
List<String> ancestors = <String>[]; List<String> ancestors = <String>[];
class TestWidget extends StatefulWidget { class TestWidget extends StatefulWidget {
const TestWidget({ Key key }) : super(key: key); const TestWidget({ Key? key }) : super(key: key);
@override @override
TestWidgetState createState() => TestWidgetState(); TestWidgetState createState() => TestWidgetState();
} }
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/gestures.dart'; import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
...@@ -625,11 +623,11 @@ void main() { ...@@ -625,11 +623,11 @@ void main() {
testWidgets('Scale with mouse returns onInteraction properties', (WidgetTester tester) async{ testWidgets('Scale with mouse returns onInteraction properties', (WidgetTester tester) async{
final TransformationController transformationController = TransformationController(); final TransformationController transformationController = TransformationController();
Offset focalPoint; late Offset focalPoint;
Offset localFocalPoint; late Offset localFocalPoint;
double scaleChange; late double scaleChange;
Velocity currentVelocity; late Velocity currentVelocity;
bool calledStart; late bool calledStart;
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
home: Scaffold( home: Scaffold(
...@@ -677,11 +675,11 @@ void main() { ...@@ -677,11 +675,11 @@ void main() {
testWidgets('onInteraction can be used to get scene point', (WidgetTester tester) async{ testWidgets('onInteraction can be used to get scene point', (WidgetTester tester) async{
final TransformationController transformationController = TransformationController(); final TransformationController transformationController = TransformationController();
Offset focalPoint; late Offset focalPoint;
Offset localFocalPoint; late Offset localFocalPoint;
double scaleChange; late double scaleChange;
Velocity currentVelocity; late Velocity currentVelocity;
bool calledStart; late bool calledStart;
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
home: Scaffold( home: Scaffold(
......
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