mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Migrate the tests of flutter_test to null-safety (#67058)
This commit is contained in:
parent
b63970c681
commit
cba170fbb2
@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.9
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
@ -181,7 +179,7 @@ void main() {
|
||||
});
|
||||
|
||||
group('custom minimum contrast guideline', () {
|
||||
Widget _icon ({IconData icon = Icons.search, Color color, Color background}) {
|
||||
Widget _icon({IconData icon = Icons.search, required Color color, required Color background}) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
color: background,
|
||||
@ -189,7 +187,7 @@ void main() {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _text ({String text = 'Text', Color color, Color background}) {
|
||||
Widget _text({String text = 'Text', required Color color, required Color background}) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
color: background,
|
||||
@ -197,7 +195,7 @@ void main() {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _row (List<Widget> widgets) => _boilerplate(Row(children: widgets));
|
||||
Widget _row(List<Widget> widgets) => _boilerplate(Row(children: widgets));
|
||||
|
||||
final Finder _findIcons = find.byWidgetPredicate((Widget widget) => widget is Icon);
|
||||
final Finder _findTexts = find.byWidgetPredicate((Widget widget) => widget is Text);
|
||||
@ -205,8 +203,8 @@ void main() {
|
||||
|
||||
testWidgets('Black icons on white background', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(_row(<Widget>[
|
||||
_icon (color: Colors.black, background: Colors.white),
|
||||
_icon (color: Colors.black, background: Colors.white),
|
||||
_icon(color: Colors.black, background: Colors.white),
|
||||
_icon(color: Colors.black, background: Colors.white),
|
||||
]));
|
||||
|
||||
await expectLater(tester, meetsGuideline(CustomMinimumContrastGuideline(finder: _findIcons)));
|
||||
@ -214,8 +212,8 @@ void main() {
|
||||
|
||||
testWidgets('Black icons on black background', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(_row(<Widget>[
|
||||
_icon (color: Colors.black, background: Colors.black),
|
||||
_icon (color: Colors.black, background: Colors.black),
|
||||
_icon(color: Colors.black, background: Colors.black),
|
||||
_icon(color: Colors.black, background: Colors.black),
|
||||
]));
|
||||
|
||||
await expectLater(tester, doesNotMeetGuideline(CustomMinimumContrastGuideline(finder: _findIcons)));
|
||||
@ -223,8 +221,8 @@ void main() {
|
||||
|
||||
testWidgets('White icons on black background ("dark mode")', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(_row(<Widget>[
|
||||
_icon (color: Colors.white, background: Colors.black),
|
||||
_icon (color: Colors.white, background: Colors.black),
|
||||
_icon(color: Colors.white, background: Colors.black),
|
||||
_icon(color: Colors.white, background: Colors.black),
|
||||
]));
|
||||
|
||||
await expectLater(tester, meetsGuideline(CustomMinimumContrastGuideline(finder: _findIcons)));
|
||||
@ -232,10 +230,10 @@ void main() {
|
||||
|
||||
testWidgets('Using different icons', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(_row(<Widget>[
|
||||
_icon (color: Colors.black, background: Colors.white, icon: Icons.more_horiz),
|
||||
_icon (color: Colors.black, background: Colors.white, icon: Icons.description),
|
||||
_icon (color: Colors.black, background: Colors.white, icon: Icons.image),
|
||||
_icon (color: Colors.black, background: Colors.white, icon: Icons.beach_access),
|
||||
_icon(color: Colors.black, background: Colors.white, icon: Icons.more_horiz),
|
||||
_icon(color: Colors.black, background: Colors.white, icon: Icons.description),
|
||||
_icon(color: Colors.black, background: Colors.white, icon: Icons.image),
|
||||
_icon(color: Colors.black, background: Colors.white, icon: Icons.beach_access),
|
||||
]));
|
||||
|
||||
await expectLater(tester, meetsGuideline(CustomMinimumContrastGuideline(finder: _findIcons)));
|
||||
@ -243,8 +241,8 @@ void main() {
|
||||
|
||||
testWidgets('One invalid instance fails entire test', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(_row(<Widget>[
|
||||
_icon (color: Colors.black, background: Colors.white),
|
||||
_icon (color: Colors.black, background: Colors.black),
|
||||
_icon(color: Colors.black, background: Colors.white),
|
||||
_icon(color: Colors.black, background: Colors.black),
|
||||
]));
|
||||
|
||||
await expectLater(tester, doesNotMeetGuideline(CustomMinimumContrastGuideline(finder: _findIcons)));
|
||||
@ -252,10 +250,10 @@ void main() {
|
||||
|
||||
testWidgets('White on different colors, passing', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(_row(<Widget>[
|
||||
_icon (color: Colors.white, background: Colors.red[800], icon: Icons.more_horiz),
|
||||
_icon (color: Colors.white, background: Colors.green[800], icon: Icons.description),
|
||||
_icon (color: Colors.white, background: Colors.blue[800], icon: Icons.image),
|
||||
_icon (color: Colors.white, background: Colors.purple[800], icon: Icons.beach_access),
|
||||
_icon(color: Colors.white, background: Colors.red[800]!, icon: Icons.more_horiz),
|
||||
_icon(color: Colors.white, background: Colors.green[800]!, icon: Icons.description),
|
||||
_icon(color: Colors.white, background: Colors.blue[800]!, icon: Icons.image),
|
||||
_icon(color: Colors.white, background: Colors.purple[800]!, icon: Icons.beach_access),
|
||||
]));
|
||||
|
||||
await expectLater(tester, meetsGuideline(CustomMinimumContrastGuideline(finder: _findIcons)));
|
||||
@ -263,10 +261,10 @@ void main() {
|
||||
|
||||
testWidgets('White on different colors, failing', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(_row(<Widget>[
|
||||
_icon (color: Colors.white, background: Colors.red[200], icon: Icons.more_horiz),
|
||||
_icon (color: Colors.white, background: Colors.green[400], icon: Icons.description),
|
||||
_icon (color: Colors.white, background: Colors.blue[600], icon: Icons.image),
|
||||
_icon (color: Colors.white, background: Colors.purple[800], icon: Icons.beach_access),
|
||||
_icon(color: Colors.white, background: Colors.red[200]!, icon: Icons.more_horiz),
|
||||
_icon(color: Colors.white, background: Colors.green[400]!, icon: Icons.description),
|
||||
_icon(color: Colors.white, background: Colors.blue[600]!, icon: Icons.image),
|
||||
_icon(color: Colors.white, background: Colors.purple[800]!, icon: Icons.beach_access),
|
||||
]));
|
||||
|
||||
await expectLater(tester, doesNotMeetGuideline(CustomMinimumContrastGuideline(finder: _findIcons)));
|
||||
@ -280,8 +278,8 @@ void main() {
|
||||
|
||||
testWidgets('Absence of icons, passing - 2nd test', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(_row(<Widget>[
|
||||
_text (color: Colors.black, background: Colors.white),
|
||||
_text (color: Colors.black, background: Colors.black),
|
||||
_text(color: Colors.black, background: Colors.white),
|
||||
_text(color: Colors.black, background: Colors.black),
|
||||
]));
|
||||
|
||||
await expectLater(tester, meetsGuideline(CustomMinimumContrastGuideline(finder: _findIcons)));
|
||||
@ -289,10 +287,10 @@ void main() {
|
||||
|
||||
testWidgets('Guideline ignores widgets of other types', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(_row(<Widget>[
|
||||
_icon (color: Colors.black, background: Colors.white),
|
||||
_icon (color: Colors.black, background: Colors.white),
|
||||
_text (color: Colors.black, background: Colors.white),
|
||||
_text (color: Colors.black, background: Colors.black),
|
||||
_icon(color: Colors.black, background: Colors.white),
|
||||
_icon(color: Colors.black, background: Colors.white),
|
||||
_text(color: Colors.black, background: Colors.white),
|
||||
_text(color: Colors.black, background: Colors.black),
|
||||
]));
|
||||
|
||||
await expectLater(tester, meetsGuideline(CustomMinimumContrastGuideline(finder: _findIcons)));
|
||||
@ -302,8 +300,8 @@ void main() {
|
||||
|
||||
testWidgets('Custom minimum ratio - Icons', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(_row(<Widget>[
|
||||
_icon (color: Colors.blue, background: Colors.white),
|
||||
_icon (color: Colors.black, background: Colors.white),
|
||||
_icon(color: Colors.blue, background: Colors.white),
|
||||
_icon(color: Colors.black, background: Colors.white),
|
||||
]));
|
||||
|
||||
await expectLater(tester, doesNotMeetGuideline(CustomMinimumContrastGuideline(finder: _findIcons)));
|
||||
@ -312,8 +310,8 @@ void main() {
|
||||
|
||||
testWidgets('Custom minimum ratio - Texts', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(_row(<Widget>[
|
||||
_text (color: Colors.blue, background: Colors.white),
|
||||
_text (color: Colors.black, background: Colors.white),
|
||||
_text(color: Colors.blue, background: Colors.white),
|
||||
_text(color: Colors.black, background: Colors.white),
|
||||
]));
|
||||
|
||||
await expectLater(tester, doesNotMeetGuideline(CustomMinimumContrastGuideline(finder: _findTexts)));
|
||||
@ -322,10 +320,10 @@ void main() {
|
||||
|
||||
testWidgets('Custom minimum ratio - Different standards for icons and texts', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(_row(<Widget>[
|
||||
_icon (color: Colors.blue, background: Colors.white),
|
||||
_icon (color: Colors.black, background: Colors.white),
|
||||
_text (color: Colors.blue, background: Colors.white),
|
||||
_text (color: Colors.black, background: Colors.white),
|
||||
_icon(color: Colors.blue, background: Colors.white),
|
||||
_icon(color: Colors.black, background: Colors.white),
|
||||
_text(color: Colors.blue, background: Colors.white),
|
||||
_text(color: Colors.black, background: Colors.white),
|
||||
]));
|
||||
|
||||
await expectLater(tester, doesNotMeetGuideline(CustomMinimumContrastGuideline(finder: _findIcons)));
|
||||
|
@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.9
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
|
@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.9
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
@ -2,9 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.9
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
|
@ -2,9 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.9
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
|
@ -1,16 +0,0 @@
|
||||
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.9
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
test('$WidgetsBinding initializes with $AutomatedTestWidgetsFlutterBinding when FLUTTER_TEST is defined but null', () {
|
||||
TestWidgetsFlutterBinding.ensureInitialized(<String, String>{'FLUTTER_TEST': null});
|
||||
expect(WidgetsBinding.instance, isA<AutomatedTestWidgetsFlutterBinding>());
|
||||
});
|
||||
}
|
@ -2,9 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.9
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
|
@ -2,9 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.9
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
|
@ -2,11 +2,8 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.9
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
|
@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.9
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.9
|
||||
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:flutter/semantics.dart';
|
||||
|
@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.9
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.9
|
||||
|
||||
import 'flutter_test_config.dart' as real_test;
|
||||
|
||||
void main() => real_test.runTest();
|
||||
|
@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.9
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
@ -38,7 +36,7 @@ Future<void> main() async {
|
||||
await binding.runTest(() async {
|
||||
final DebugPrintCallback oldDebugPrint = debugPrint;
|
||||
try {
|
||||
debugPrint = (String message, {int wrapWidth}) {};
|
||||
debugPrint = (String? message, {int? wrapWidth}) {};
|
||||
debugPrintStack(
|
||||
stackTrace: await getMangledStack(),
|
||||
);
|
||||
|
@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.9
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.9
|
||||
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.9
|
||||
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.9
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:io' as io;
|
||||
import 'dart:typed_data';
|
||||
@ -35,7 +33,7 @@ const List<int> _kSizeFailurePngBytes =
|
||||
0, 0, 73, 69, 78, 68, 174, 66, 96, 130];
|
||||
|
||||
void main() {
|
||||
MemoryFileSystem fs;
|
||||
late MemoryFileSystem fs;
|
||||
|
||||
setUp(() {
|
||||
final FileSystemStyle style = io.Platform.isWindows
|
||||
@ -86,7 +84,7 @@ void main() {
|
||||
});
|
||||
|
||||
group('LocalFileComparator', () {
|
||||
LocalFileComparator comparator;
|
||||
late LocalFileComparator comparator;
|
||||
|
||||
setUp(() {
|
||||
comparator = LocalFileComparator(fs.file(fix('/golden_test.dart')).uri, pathStyle: fs.path.style);
|
||||
|
@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.9
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.9
|
||||
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
@ -24,7 +22,7 @@ void main() {
|
||||
});
|
||||
|
||||
testWidgets('Input PointerHoverEvent', (WidgetTester tester) async {
|
||||
PointerHoverEvent hoverEvent;
|
||||
PointerHoverEvent? hoverEvent;
|
||||
await tester.pumpWidget(MaterialApp(home: MouseRegion(
|
||||
child: const Text('Test'),
|
||||
onHover: (PointerHoverEvent event){
|
||||
@ -37,7 +35,7 @@ void main() {
|
||||
// for mouse input without a down event, moveTo generates a hover event
|
||||
await gesture.moveTo(location);
|
||||
expect(hoverEvent, isNotNull);
|
||||
expect(hoverEvent.position, location);
|
||||
expect(hoverEvent!.position, location);
|
||||
await gesture.removePointer();
|
||||
});
|
||||
}
|
||||
|
@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.9
|
||||
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
@ -38,7 +36,7 @@ class AnimateSample extends StatefulWidget {
|
||||
|
||||
class _AnimateSampleState extends State<AnimateSample>
|
||||
with SingleTickerProviderStateMixin {
|
||||
AnimationController _controller;
|
||||
late AnimationController _controller;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@ -68,9 +66,9 @@ void main() {
|
||||
test('Test pump on LiveWidgetController', () async {
|
||||
runApp(MaterialApp(home: Center(child: CountButton())));
|
||||
|
||||
await SchedulerBinding.instance.endOfFrame;
|
||||
await SchedulerBinding.instance!.endOfFrame;
|
||||
final WidgetController controller =
|
||||
LiveWidgetController(WidgetsBinding.instance);
|
||||
LiveWidgetController(WidgetsBinding.instance!);
|
||||
await controller.tap(find.text('Counter 0'));
|
||||
expect(find.text('Counter 0'), findsOneWidget);
|
||||
expect(find.text('Counter 1'), findsNothing);
|
||||
@ -81,9 +79,9 @@ void main() {
|
||||
|
||||
test('Test pumpAndSettle on LiveWidgetController', () async {
|
||||
runApp(MaterialApp(home: Center(child: AnimateSample())));
|
||||
await SchedulerBinding.instance.endOfFrame;
|
||||
await SchedulerBinding.instance!.endOfFrame;
|
||||
final WidgetController controller =
|
||||
LiveWidgetController(WidgetsBinding.instance);
|
||||
LiveWidgetController(WidgetsBinding.instance!);
|
||||
expect(find.text('Value: 1.0'), findsNothing);
|
||||
await controller.pumpAndSettle();
|
||||
expect(find.text('Value: 1.0'), findsOneWidget);
|
||||
@ -101,9 +99,9 @@ void main() {
|
||||
),
|
||||
),
|
||||
);
|
||||
await SchedulerBinding.instance.endOfFrame;
|
||||
await SchedulerBinding.instance!.endOfFrame;
|
||||
final WidgetController controller =
|
||||
LiveWidgetController(WidgetsBinding.instance);
|
||||
LiveWidgetController(WidgetsBinding.instance!);
|
||||
|
||||
final Offset location = controller.getCenter(find.text('test'));
|
||||
final List<PointerEventRecord> records = <PointerEventRecord>[
|
||||
|
@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.9
|
||||
|
||||
import 'dart:typed_data';
|
||||
import 'dart:ui';
|
||||
|
||||
@ -13,9 +11,8 @@ import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
/// Class that makes it easy to mock common toStringDeep behavior.
|
||||
class _MockToStringDeep {
|
||||
_MockToStringDeep(String str) {
|
||||
_MockToStringDeep(String str) : _lines = <String>[] {
|
||||
final List<String> lines = str.split('\n');
|
||||
_lines = <String>[];
|
||||
for (int i = 0; i < lines.length - 1; ++i)
|
||||
_lines.add('${lines[i]}\n');
|
||||
|
||||
@ -31,7 +28,7 @@ class _MockToStringDeep {
|
||||
/// Lines in the message to display when [toStringDeep] is called.
|
||||
/// For correct toStringDeep behavior, each line should be terminated with a
|
||||
/// line break.
|
||||
List<String> _lines;
|
||||
final List<String> _lines;
|
||||
|
||||
String toStringDeep({ String prefixLineOne = '', String prefixOtherLines = '' }) {
|
||||
final StringBuffer sb = StringBuffer();
|
||||
@ -340,7 +337,7 @@ void main() {
|
||||
});
|
||||
|
||||
group('matchesGoldenFile', () {
|
||||
_FakeComparator comparator;
|
||||
late _FakeComparator comparator;
|
||||
|
||||
Widget boilerplate(Widget child) {
|
||||
return Directionality(
|
||||
@ -561,8 +558,7 @@ void main() {
|
||||
currentValueLength: 10,
|
||||
maxValueLength: 15,
|
||||
);
|
||||
final _FakeSemanticsNode node = _FakeSemanticsNode();
|
||||
node.data = data;
|
||||
final _FakeSemanticsNode node = _FakeSemanticsNode(data);
|
||||
|
||||
expect(node, matchesSemantics(
|
||||
rect: const Rect.fromLTRB(0.0, 0.0, 10.0, 10.0),
|
||||
@ -666,9 +662,9 @@ enum _ComparatorInvocation {
|
||||
|
||||
class _FakeComparator implements GoldenFileComparator {
|
||||
_ComparatorBehavior behavior = _ComparatorBehavior.returnTrue;
|
||||
_ComparatorInvocation invocation;
|
||||
Uint8List imageBytes;
|
||||
Uri golden;
|
||||
_ComparatorInvocation? invocation;
|
||||
Uint8List? imageBytes;
|
||||
Uri? golden;
|
||||
|
||||
@override
|
||||
Future<bool> compare(Uint8List imageBytes, Uri golden) {
|
||||
@ -683,7 +679,6 @@ class _FakeComparator implements GoldenFileComparator {
|
||||
case _ComparatorBehavior.throwTestFailure:
|
||||
throw TestFailure('fake message');
|
||||
}
|
||||
return Future<bool>.value(false);
|
||||
}
|
||||
|
||||
@override
|
||||
@ -695,12 +690,14 @@ class _FakeComparator implements GoldenFileComparator {
|
||||
}
|
||||
|
||||
@override
|
||||
Uri getTestUri(Uri key, int version) {
|
||||
Uri getTestUri(Uri key, int? version) {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
|
||||
class _FakeSemanticsNode extends SemanticsNode {
|
||||
_FakeSemanticsNode(this.data);
|
||||
|
||||
SemanticsData data;
|
||||
@override
|
||||
SemanticsData getSemanticsData() => data;
|
||||
@ -709,7 +706,7 @@ class _FakeSemanticsNode extends SemanticsNode {
|
||||
@immutable
|
||||
class _CustomColor extends Color {
|
||||
const _CustomColor(int value, {this.isEqual}) : super(value);
|
||||
final bool isEqual;
|
||||
final bool? isEqual;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) => isEqual ?? super == other;
|
||||
|
@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.9
|
||||
|
||||
import 'dart:ui' as ui;
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.9
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
@ -75,9 +73,9 @@ void main() {
|
||||
}
|
||||
|
||||
class _RestorableWidget extends StatefulWidget {
|
||||
const _RestorableWidget({Key key, this.restorationId}) : super(key: key);
|
||||
const _RestorableWidget({Key? key, this.restorationId}) : super(key: key);
|
||||
|
||||
final String restorationId;
|
||||
final String? restorationId;
|
||||
|
||||
@override
|
||||
State<_RestorableWidget> createState() => _RestorableWidgetState();
|
||||
@ -90,7 +88,7 @@ class _RestorableWidgetState extends State<_RestorableWidget> with RestorationMi
|
||||
double doubleValue = 1.0; // Not restorable.
|
||||
|
||||
@override
|
||||
void restoreState(RestorationBucket oldBucket, bool initialRestore) {
|
||||
void restoreState(RestorationBucket? oldBucket, bool initialRestore) {
|
||||
registerForRestoration(stringValue, 'string');
|
||||
registerForRestoration(intValue, 'int');
|
||||
}
|
||||
@ -109,5 +107,5 @@ class _RestorableWidgetState extends State<_RestorableWidget> with RestorationMi
|
||||
}
|
||||
|
||||
@override
|
||||
String get restorationId => widget.restorationId;
|
||||
String? get restorationId => widget.restorationId;
|
||||
}
|
||||
|
@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.9
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
@ -22,7 +20,7 @@ void main() {
|
||||
}
|
||||
|
||||
try {
|
||||
throw null;
|
||||
throw Object();
|
||||
} catch (e, stack) {
|
||||
final List<DiagnosticsNode> information = <DiagnosticsNode>[];
|
||||
expect(reportExpectCall(stack, information), 0);
|
||||
|
@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.9
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
@ -18,17 +16,17 @@ import 'package:test_api/test_api.dart' as real_test show expect;
|
||||
// of this test is to see how we handle leaking APIs.
|
||||
|
||||
class TestAPI {
|
||||
Future<Object> testGuard1() {
|
||||
return TestAsyncUtils.guard<Object>(() async { return null; });
|
||||
Future<Object?> testGuard1() {
|
||||
return TestAsyncUtils.guard<Object?>(() async { return null; });
|
||||
}
|
||||
Future<Object> testGuard2() {
|
||||
return TestAsyncUtils.guard<Object>(() async { return null; });
|
||||
Future<Object?> testGuard2() {
|
||||
return TestAsyncUtils.guard<Object?>(() async { return null; });
|
||||
}
|
||||
}
|
||||
|
||||
class TestAPISubclass extends TestAPI {
|
||||
Future<Object> testGuard3() {
|
||||
return TestAsyncUtils.guard<Object>(() async { return null; });
|
||||
Future<Object?> testGuard3() {
|
||||
return TestAsyncUtils.guard<Object?>(() async { return null; });
|
||||
}
|
||||
}
|
||||
|
||||
@ -41,7 +39,7 @@ Future<Object> _guardedThrower() {
|
||||
void main() {
|
||||
test('TestAsyncUtils - one class', () async {
|
||||
final TestAPI testAPI = TestAPI();
|
||||
Future<Object> f1, f2;
|
||||
Future<Object?>? f1, f2;
|
||||
f1 = testAPI.testGuard1();
|
||||
try {
|
||||
f2 = testAPI.testGuard2();
|
||||
@ -63,7 +61,7 @@ void main() {
|
||||
|
||||
test('TestAsyncUtils - two classes, all callers in superclass', () async {
|
||||
final TestAPI testAPI = TestAPISubclass();
|
||||
Future<Object> f1, f2;
|
||||
Future<Object?>? f1, f2;
|
||||
f1 = testAPI.testGuard1();
|
||||
try {
|
||||
f2 = testAPI.testGuard2();
|
||||
@ -85,7 +83,7 @@ void main() {
|
||||
|
||||
test('TestAsyncUtils - two classes, mixed callers', () async {
|
||||
final TestAPISubclass testAPI = TestAPISubclass();
|
||||
Future<Object> f1, f2;
|
||||
Future<Object?>? f1, f2;
|
||||
f1 = testAPI.testGuard1();
|
||||
try {
|
||||
f2 = testAPI.testGuard3();
|
||||
@ -107,7 +105,7 @@ void main() {
|
||||
|
||||
test('TestAsyncUtils - expect() catches pending async work', () async {
|
||||
final TestAPI testAPI = TestAPISubclass();
|
||||
Future<Object> f1;
|
||||
Future<Object?>? f1;
|
||||
f1 = testAPI.testGuard1();
|
||||
try {
|
||||
flutter_test.expect(0, 0);
|
||||
@ -128,7 +126,7 @@ void main() {
|
||||
});
|
||||
|
||||
testWidgets('TestAsyncUtils - expect() catches pending async work', (WidgetTester tester) async {
|
||||
Future<Object> f1, f2;
|
||||
Future<Object?>? f1, f2;
|
||||
try {
|
||||
f1 = tester.pump();
|
||||
f2 = tester.pump();
|
||||
@ -170,7 +168,7 @@ void main() {
|
||||
});
|
||||
|
||||
testWidgets('TestAsyncUtils - expect() catches pending async work', (WidgetTester tester) async {
|
||||
Future<Object> f1;
|
||||
Future<Object?>? f1;
|
||||
try {
|
||||
f1 = tester.pump();
|
||||
TestAsyncUtils.verifyAllScopesClosed();
|
||||
@ -195,7 +193,7 @@ void main() {
|
||||
});
|
||||
|
||||
testWidgets('TestAsyncUtils - expect() catches pending async work', (WidgetTester tester) async {
|
||||
Future<Object> f1;
|
||||
Future<Object?>? f1;
|
||||
try {
|
||||
f1 = tester.pump();
|
||||
TestAsyncUtils.verifyAllScopesClosed();
|
||||
|
@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.9
|
||||
|
||||
import '../config_test_utils.dart';
|
||||
|
||||
void main() {
|
||||
|
@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.9
|
||||
|
||||
import '../../config_test_utils.dart';
|
||||
|
||||
void main() {
|
||||
|
@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.9
|
||||
|
||||
import 'config_test_utils.dart';
|
||||
|
||||
void main() {
|
||||
|
@ -2,15 +2,13 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.9
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void testConfig(
|
||||
String description,
|
||||
String expectedStringValue, {
|
||||
String? expectedStringValue, {
|
||||
Map<Type, dynamic> otherExpectedValues = const <Type, dynamic>{int: isNull},
|
||||
}) {
|
||||
final String actualStringValue = Zone.current[String] as String;
|
||||
|
@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.9
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
Future<void> main(FutureOr<void> testMain()) async {
|
||||
|
@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.9
|
||||
|
||||
import '../config_test_utils.dart';
|
||||
|
||||
void main() {
|
||||
|
@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.9
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
Future<void> main(FutureOr<void> testMain()) async {
|
||||
|
@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.9
|
||||
|
||||
import '../config_test_utils.dart';
|
||||
|
||||
void main() {
|
||||
|
@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.9
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.9
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'dart:ui';
|
||||
@ -30,7 +28,7 @@ void main() {
|
||||
testWidgets('completes when matcher completes', (WidgetTester tester) async {
|
||||
final Completer<void> completer = Completer<void>();
|
||||
final Future<void> future = expectLater(null, FakeMatcher(completer));
|
||||
String result;
|
||||
String? result;
|
||||
future.then<void>((void value) {
|
||||
result = '123';
|
||||
});
|
||||
@ -62,7 +60,7 @@ void main() {
|
||||
});
|
||||
|
||||
testWidgets('fails with a descriptive message', (WidgetTester tester) async {
|
||||
TestFailure failure;
|
||||
late TestFailure failure;
|
||||
try {
|
||||
expect(find.text('foo', skipOffstage: false), findsOneWidget);
|
||||
} on TestFailure catch (e) {
|
||||
@ -85,7 +83,7 @@ void main() {
|
||||
testWidgets('fails with a descriptive message', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(const Text('foo', textDirection: TextDirection.ltr));
|
||||
|
||||
TestFailure failure;
|
||||
late TestFailure failure;
|
||||
try {
|
||||
expect(find.text('foo', skipOffstage: false), findsNothing);
|
||||
} on TestFailure catch (e) {
|
||||
@ -103,7 +101,7 @@ void main() {
|
||||
testWidgets('fails with a descriptive message when skipping', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(const Text('foo', textDirection: TextDirection.ltr));
|
||||
|
||||
TestFailure failure;
|
||||
late TestFailure failure;
|
||||
try {
|
||||
expect(find.text('foo'), findsNothing);
|
||||
} on TestFailure catch (e) {
|
||||
@ -156,13 +154,13 @@ void main() {
|
||||
|
||||
testWidgets('pumpFrames', (WidgetTester tester) async {
|
||||
final List<int> logPaints = <int>[];
|
||||
int initial;
|
||||
int? initial;
|
||||
|
||||
final Widget target = _AlwaysAnimating(
|
||||
onPaint: () {
|
||||
final int current = SchedulerBinding.instance.currentFrameTimeStamp.inMicroseconds;
|
||||
final int current = SchedulerBinding.instance!.currentFrameTimeStamp.inMicroseconds;
|
||||
initial ??= current;
|
||||
logPaints.add(current - initial);
|
||||
logPaints.add(current - initial!);
|
||||
},
|
||||
);
|
||||
|
||||
@ -182,7 +180,7 @@ void main() {
|
||||
await tester.pumpWidget(const Text('foo', textDirection: TextDirection.ltr));
|
||||
|
||||
const String customDescription = 'custom description';
|
||||
TestFailure failure;
|
||||
late TestFailure failure;
|
||||
try {
|
||||
expect(find.byElementPredicate((_) => false, description: customDescription), findsOneWidget);
|
||||
} on TestFailure catch (e) {
|
||||
@ -199,7 +197,7 @@ void main() {
|
||||
await tester.pumpWidget(const Text('foo', textDirection: TextDirection.ltr));
|
||||
|
||||
const String customDescription = 'custom description';
|
||||
TestFailure failure;
|
||||
late TestFailure failure;
|
||||
try {
|
||||
expect(find.byWidgetPredicate((_) => false, description: customDescription), findsOneWidget);
|
||||
} on TestFailure catch (e) {
|
||||
@ -250,7 +248,7 @@ void main() {
|
||||
],
|
||||
));
|
||||
|
||||
TestFailure failure;
|
||||
late TestFailure failure;
|
||||
try {
|
||||
expect(find.descendant(
|
||||
of: find.widgetWithText(Column, 'foo'),
|
||||
@ -312,7 +310,7 @@ void main() {
|
||||
],
|
||||
));
|
||||
|
||||
TestFailure failure;
|
||||
late TestFailure failure;
|
||||
try {
|
||||
expect(find.ancestor(
|
||||
of: find.text('bar'),
|
||||
@ -554,7 +552,7 @@ void main() {
|
||||
|
||||
group('runAsync', () {
|
||||
testWidgets('works with no async calls', (WidgetTester tester) async {
|
||||
String value;
|
||||
String? value;
|
||||
await tester.runAsync(() async {
|
||||
value = '123';
|
||||
});
|
||||
@ -574,14 +572,14 @@ void main() {
|
||||
});
|
||||
|
||||
testWidgets('propagates return values', (WidgetTester tester) async {
|
||||
final String value = await tester.runAsync<String>(() async {
|
||||
final String? value = await tester.runAsync<String>(() async {
|
||||
return '123';
|
||||
});
|
||||
expect(value, '123');
|
||||
});
|
||||
|
||||
testWidgets('reports errors via framework', (WidgetTester tester) async {
|
||||
final String value = await tester.runAsync<String>(() async {
|
||||
final String? value = await tester.runAsync<String>(() async {
|
||||
throw ArgumentError();
|
||||
});
|
||||
expect(value, isNull);
|
||||
@ -630,7 +628,7 @@ void main() {
|
||||
});
|
||||
|
||||
testWidgets('verifyTickersWereDisposed control test', (WidgetTester tester) async {
|
||||
FlutterError error;
|
||||
late FlutterError error;
|
||||
final Ticker ticker = tester.createTicker((Duration duration) {});
|
||||
ticker.start();
|
||||
try {
|
||||
@ -685,7 +683,7 @@ void main() {
|
||||
|
||||
group('TargetPlatformVariant', () {
|
||||
int numberOfVariationsRun = 0;
|
||||
TargetPlatform origTargetPlatform;
|
||||
TargetPlatform? origTargetPlatform;
|
||||
|
||||
setUpAll((){
|
||||
origTargetPlatform = debugDefaultTargetPlatformOverride;
|
||||
@ -717,7 +715,7 @@ void main() {
|
||||
});
|
||||
|
||||
group('Pending timer', () {
|
||||
TestExceptionReporter currentExceptionReporter;
|
||||
late TestExceptionReporter currentExceptionReporter;
|
||||
setUp(() {
|
||||
currentExceptionReporter = reportTestException;
|
||||
});
|
||||
@ -727,7 +725,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('Throws assertion message without code', () async {
|
||||
FlutterErrorDetails flutterErrorDetails;
|
||||
late FlutterErrorDetails flutterErrorDetails;
|
||||
reportTestException = (FlutterErrorDetails details, String testDescription) {
|
||||
flutterErrorDetails = details;
|
||||
};
|
||||
@ -738,8 +736,8 @@ void main() {
|
||||
expect(timer.isActive, true);
|
||||
}, () {});
|
||||
|
||||
expect(flutterErrorDetails?.exception, isA<AssertionError>());
|
||||
expect(flutterErrorDetails?.exception?.message, 'A Timer is still pending even after the widget tree was disposed.');
|
||||
expect(flutterErrorDetails.exception, isA<AssertionError>());
|
||||
expect(flutterErrorDetails.exception!.message, 'A Timer is still pending even after the widget tree was disposed.');
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -750,8 +748,8 @@ class FakeMatcher extends AsyncMatcher {
|
||||
final Completer<void> completer;
|
||||
|
||||
@override
|
||||
Future<String> matchAsync(dynamic object) {
|
||||
return completer.future.then<String>((void value) {
|
||||
Future<String?> matchAsync(dynamic object) {
|
||||
return completer.future.then<String?>((void value) {
|
||||
return object?.toString();
|
||||
});
|
||||
}
|
||||
@ -761,14 +759,14 @@ class FakeMatcher extends AsyncMatcher {
|
||||
}
|
||||
|
||||
class _SingleTickerTest extends StatefulWidget {
|
||||
const _SingleTickerTest({Key key}) : super(key: key);
|
||||
const _SingleTickerTest({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_SingleTickerTestState createState() => _SingleTickerTestState();
|
||||
}
|
||||
|
||||
class _SingleTickerTestState extends State<_SingleTickerTest> with SingleTickerProviderStateMixin {
|
||||
AnimationController controller;
|
||||
late AnimationController controller;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@ -788,10 +786,10 @@ class _SingleTickerTestState extends State<_SingleTickerTest> with SingleTickerP
|
||||
class _AlwaysAnimating extends StatefulWidget {
|
||||
const _AlwaysAnimating({
|
||||
this.child,
|
||||
this.onPaint,
|
||||
required this.onPaint,
|
||||
});
|
||||
|
||||
final Widget child;
|
||||
final Widget? child;
|
||||
final VoidCallback onPaint;
|
||||
|
||||
@override
|
||||
@ -799,7 +797,7 @@ class _AlwaysAnimating extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _AlwaysAnimatingState extends State<_AlwaysAnimating> with SingleTickerProviderStateMixin {
|
||||
AnimationController _controller;
|
||||
late AnimationController _controller;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@ -821,7 +819,7 @@ class _AlwaysAnimatingState extends State<_AlwaysAnimating> with SingleTickerPro
|
||||
Widget build(BuildContext context) {
|
||||
return AnimatedBuilder(
|
||||
animation: _controller.view,
|
||||
builder: (BuildContext context, Widget child) {
|
||||
builder: (BuildContext context, Widget? child) {
|
||||
return CustomPaint(
|
||||
painter: _AlwaysRepaint(widget.onPaint),
|
||||
child: widget.child,
|
||||
|
@ -2,18 +2,15 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.9
|
||||
|
||||
import 'dart:ui' as ui show window;
|
||||
import 'dart:ui' show Size, Locale, WindowPadding, AccessibilityFeatures, Brightness;
|
||||
|
||||
import 'package:flutter/widgets.dart' show WidgetsBinding;
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
void main() {
|
||||
test('TestWindow can handle new methods without breaking', () {
|
||||
final dynamic testWindow = TestWindow(window: ui.window);
|
||||
final dynamic testWindow = TestWindow(window: ui.window); // ignore: unnecessary_nullable_for_final_variable_declarations
|
||||
expect(testWindow.someNewProperty, null);
|
||||
});
|
||||
|
||||
@ -23,7 +20,7 @@ void main() {
|
||||
realValue: ui.window.devicePixelRatio,
|
||||
fakeValue: 2.5,
|
||||
propertyRetriever: () {
|
||||
return WidgetsBinding.instance.window.devicePixelRatio;
|
||||
return WidgetsBinding.instance!.window.devicePixelRatio;
|
||||
},
|
||||
propertyFaker: (TestWidgetsFlutterBinding binding, double fakeValue) {
|
||||
binding.window.devicePixelRatioTestValue = fakeValue;
|
||||
@ -37,7 +34,7 @@ void main() {
|
||||
realValue: ui.window.physicalSize,
|
||||
fakeValue: const Size(50, 50),
|
||||
propertyRetriever: () {
|
||||
return WidgetsBinding.instance.window.physicalSize;
|
||||
return WidgetsBinding.instance!.window.physicalSize;
|
||||
},
|
||||
propertyFaker: (TestWidgetsFlutterBinding binding, Size fakeValue) {
|
||||
binding.window.physicalSizeTestValue = fakeValue;
|
||||
@ -51,7 +48,7 @@ void main() {
|
||||
realValue: ui.window.viewInsets,
|
||||
fakeValue: const FakeWindowPadding(),
|
||||
propertyRetriever: () {
|
||||
return WidgetsBinding.instance.window.viewInsets;
|
||||
return WidgetsBinding.instance!.window.viewInsets;
|
||||
},
|
||||
propertyFaker: (TestWidgetsFlutterBinding binding, WindowPadding fakeValue) {
|
||||
binding.window.viewInsetsTestValue = fakeValue;
|
||||
@ -65,7 +62,7 @@ void main() {
|
||||
realValue: ui.window.padding,
|
||||
fakeValue: const FakeWindowPadding(),
|
||||
propertyRetriever: () {
|
||||
return WidgetsBinding.instance.window.padding;
|
||||
return WidgetsBinding.instance!.window.padding;
|
||||
},
|
||||
propertyFaker: (TestWidgetsFlutterBinding binding, WindowPadding fakeValue) {
|
||||
binding.window.paddingTestValue = fakeValue;
|
||||
@ -79,7 +76,7 @@ void main() {
|
||||
realValue: ui.window.locale,
|
||||
fakeValue: const Locale('fake_language_code'),
|
||||
propertyRetriever: () {
|
||||
return WidgetsBinding.instance.window.locale;
|
||||
return WidgetsBinding.instance!.window.locale;
|
||||
},
|
||||
propertyFaker: (TestWidgetsFlutterBinding binding, Locale fakeValue) {
|
||||
binding.window.localeTestValue = fakeValue;
|
||||
@ -93,7 +90,7 @@ void main() {
|
||||
realValue: ui.window.locales,
|
||||
fakeValue: <Locale>[const Locale('fake_language_code')],
|
||||
propertyRetriever: () {
|
||||
return WidgetsBinding.instance.window.locales;
|
||||
return WidgetsBinding.instance!.window.locales;
|
||||
},
|
||||
propertyFaker: (TestWidgetsFlutterBinding binding, List<Locale> fakeValue) {
|
||||
binding.window.localesTestValue = fakeValue;
|
||||
@ -107,7 +104,7 @@ void main() {
|
||||
realValue: ui.window.textScaleFactor,
|
||||
fakeValue: 2.5,
|
||||
propertyRetriever: () {
|
||||
return WidgetsBinding.instance.window.textScaleFactor;
|
||||
return WidgetsBinding.instance!.window.textScaleFactor;
|
||||
},
|
||||
propertyFaker: (TestWidgetsFlutterBinding binding, double fakeValue) {
|
||||
binding.window.textScaleFactorTestValue = fakeValue;
|
||||
@ -121,7 +118,7 @@ void main() {
|
||||
realValue: ui.window.alwaysUse24HourFormat,
|
||||
fakeValue: !ui.window.alwaysUse24HourFormat,
|
||||
propertyRetriever: () {
|
||||
return WidgetsBinding.instance.window.alwaysUse24HourFormat;
|
||||
return WidgetsBinding.instance!.window.alwaysUse24HourFormat;
|
||||
},
|
||||
propertyFaker: (TestWidgetsFlutterBinding binding, bool fakeValue) {
|
||||
binding.window.alwaysUse24HourFormatTestValue = fakeValue;
|
||||
@ -135,7 +132,7 @@ void main() {
|
||||
realValue: ui.window.defaultRouteName,
|
||||
fakeValue: 'fake_route',
|
||||
propertyRetriever: () {
|
||||
return WidgetsBinding.instance.window.defaultRouteName;
|
||||
return WidgetsBinding.instance!.window.defaultRouteName;
|
||||
},
|
||||
propertyFaker: (TestWidgetsFlutterBinding binding, String fakeValue) {
|
||||
binding.window.defaultRouteNameTestValue = fakeValue;
|
||||
@ -149,7 +146,7 @@ void main() {
|
||||
realValue: ui.window.accessibilityFeatures,
|
||||
fakeValue: const FakeAccessibilityFeatures(),
|
||||
propertyRetriever: () {
|
||||
return WidgetsBinding.instance.window.accessibilityFeatures;
|
||||
return WidgetsBinding.instance!.window.accessibilityFeatures;
|
||||
},
|
||||
propertyFaker: (TestWidgetsFlutterBinding binding, AccessibilityFeatures fakeValue) {
|
||||
binding.window.accessibilityFeaturesTestValue = fakeValue;
|
||||
@ -163,7 +160,7 @@ void main() {
|
||||
realValue: Brightness.light,
|
||||
fakeValue: Brightness.dark,
|
||||
propertyRetriever: () {
|
||||
return WidgetsBinding.instance.window.platformBrightness;
|
||||
return WidgetsBinding.instance!.window.platformBrightness;
|
||||
},
|
||||
propertyFaker: (TestWidgetsFlutterBinding binding, Brightness fakeValue) {
|
||||
binding.window.platformBrightnessTestValue = fakeValue;
|
||||
@ -184,20 +181,20 @@ void main() {
|
||||
testWindow.clearAllTestValues();
|
||||
|
||||
// Verify that the window once again reports real property values.
|
||||
expect(WidgetsBinding.instance.window.devicePixelRatio, originalDevicePixelRatio);
|
||||
expect(WidgetsBinding.instance.window.textScaleFactor, originalTextScaleFactor);
|
||||
expect(WidgetsBinding.instance!.window.devicePixelRatio, originalDevicePixelRatio);
|
||||
expect(WidgetsBinding.instance!.window.textScaleFactor, originalTextScaleFactor);
|
||||
});
|
||||
}
|
||||
|
||||
void verifyThatTestWindowCanFakeProperty<WindowPropertyType>({
|
||||
@required WidgetTester tester,
|
||||
@required WindowPropertyType realValue,
|
||||
@required WindowPropertyType fakeValue,
|
||||
@required WindowPropertyType Function() propertyRetriever,
|
||||
@required Function(TestWidgetsFlutterBinding, WindowPropertyType fakeValue) propertyFaker,
|
||||
required WidgetTester tester,
|
||||
required WindowPropertyType? realValue,
|
||||
required WindowPropertyType fakeValue,
|
||||
required WindowPropertyType? Function() propertyRetriever,
|
||||
required Function(TestWidgetsFlutterBinding, WindowPropertyType fakeValue) propertyFaker,
|
||||
}) {
|
||||
WindowPropertyType propertyBeforeFaking;
|
||||
WindowPropertyType propertyAfterFaking;
|
||||
WindowPropertyType? propertyBeforeFaking;
|
||||
WindowPropertyType? propertyAfterFaking;
|
||||
|
||||
propertyBeforeFaking = propertyRetriever();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user