From 3c21775c94839e3aa88259297cb718df43b8c26c Mon Sep 17 00:00:00 2001 From: Darren Austin Date: Wed, 7 Oct 2020 16:44:00 -0700 Subject: [PATCH] Migrate Material framework tests to null safety (#67556) Migrate Material framework tests to null safety. --- .../test/material/button_bar_theme_test.dart | 8 +- .../test/material/button_style_test.dart | 2 - .../test/material/button_theme_test.dart | 46 +++++---- packages/flutter/test/material/card_test.dart | 6 +- .../test/material/card_theme_test.dart | 2 - .../material/checkbox_list_tile_test.dart | 30 +++--- .../flutter/test/material/checkbox_test.dart | 64 ++++++------- packages/flutter/test/material/chip_test.dart | 64 +++++-------- .../test/material/chip_theme_test.dart | 20 ++-- .../test/material/circle_avatar_test.dart | 24 +++-- .../test/material/color_scheme_test.dart | 2 - .../flutter/test/material/colors_test.dart | 34 ++++--- .../test/material/data_table_test.dart | 64 ++++++------- .../test/material/data_table_theme_test.dart | 16 ++-- .../test/material/date_picker_test.dart | 94 +++++++++---------- .../test/material/date_range_picker_test.dart | 88 +++++++++-------- .../flutter/test/material/debug_test.dart | 6 +- 17 files changed, 261 insertions(+), 309 deletions(-) diff --git a/packages/flutter/test/material/button_bar_theme_test.dart b/packages/flutter/test/material/button_bar_theme_test.dart index 1e74c0f032..0daab30859 100644 --- a/packages/flutter/test/material/button_bar_theme_test.dart +++ b/packages/flutter/test/material/button_bar_theme_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.8 - import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -56,7 +54,7 @@ void main() { overflowDirection: VerticalDirection.up, ); - final ButtonBarThemeData lerp = ButtonBarThemeData.lerp(barThemePrimary, barThemeAccent, 0.5); + final ButtonBarThemeData lerp = ButtonBarThemeData.lerp(barThemePrimary, barThemeAccent, 0.5)!; expect(lerp.alignment, equals(MainAxisAlignment.center)); expect(lerp.mainAxisSize, equals(MainAxisSize.max)); expect(lerp.buttonTextTheme, equals(ButtonTextTheme.accent)); @@ -114,7 +112,7 @@ void main() { testWidgets('ButtonBarTheme.of falls back to ThemeData.buttonBarTheme', (WidgetTester tester) async { const ButtonBarThemeData buttonBarTheme = ButtonBarThemeData(buttonMinWidth: 42.0); - BuildContext capturedContext; + late BuildContext capturedContext; await tester.pumpWidget( MaterialApp( theme: ThemeData(buttonBarTheme: buttonBarTheme), @@ -133,7 +131,7 @@ void main() { testWidgets('ButtonBarTheme overrides ThemeData.buttonBarTheme', (WidgetTester tester) async { const ButtonBarThemeData defaultBarTheme = ButtonBarThemeData(buttonMinWidth: 42.0); const ButtonBarThemeData buttonBarTheme = ButtonBarThemeData(buttonMinWidth: 84.0); - BuildContext capturedContext; + late BuildContext capturedContext; await tester.pumpWidget( MaterialApp( theme: ThemeData(buttonBarTheme: defaultBarTheme), diff --git a/packages/flutter/test/material/button_style_test.dart b/packages/flutter/test/material/button_style_test.dart index 4addf40665..57ccf4ef20 100644 --- a/packages/flutter/test/material/button_style_test.dart +++ b/packages/flutter/test/material/button_style_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.8 - import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; diff --git a/packages/flutter/test/material/button_theme_test.dart b/packages/flutter/test/material/button_theme_test.dart index 713e9fb2a0..fd1e1fe649 100644 --- a/packages/flutter/test/material/button_theme_test.dart +++ b/packages/flutter/test/material/button_theme_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.8 - import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; @@ -39,13 +37,13 @@ void main() { }); testWidgets('ButtonTheme defaults', (WidgetTester tester) async { - ButtonTextTheme textTheme; - ButtonBarLayoutBehavior layoutBehavior; - BoxConstraints constraints; - EdgeInsets padding; - ShapeBorder shape; - bool alignedDropdown; - ColorScheme colorScheme; + late ButtonTextTheme textTheme; + late ButtonBarLayoutBehavior layoutBehavior; + late BoxConstraints constraints; + late EdgeInsets padding; + late ShapeBorder shape; + late bool alignedDropdown; + late ColorScheme colorScheme; await tester.pumpWidget( ButtonTheme( @@ -57,7 +55,7 @@ void main() { padding = theme.padding as EdgeInsets; shape = theme.shape; layoutBehavior = theme.layoutBehavior; - colorScheme = theme.colorScheme; + colorScheme = theme.colorScheme!; alignedDropdown = theme.alignedDropdown; return Container( alignment: Alignment.topLeft, @@ -121,10 +119,10 @@ void main() { testWidgets('Theme buttonTheme defaults', (WidgetTester tester) async { final ThemeData lightTheme = ThemeData.light(); - ButtonTextTheme textTheme; - BoxConstraints constraints; - EdgeInsets padding; - ShapeBorder shape; + late ButtonTextTheme textTheme; + late BoxConstraints constraints; + late EdgeInsets padding; + late ShapeBorder shape; const Color disabledColor = Color(0xFF00FF00); await tester.pumpWidget( @@ -133,7 +131,7 @@ void main() { disabledColor: disabledColor, // disabled RaisedButton fill color buttonTheme: const ButtonThemeData(disabledColor: disabledColor), textTheme: lightTheme.textTheme.copyWith( - button: lightTheme.textTheme.button.copyWith( + button: lightTheme.textTheme.button!.copyWith( // The button's height will match because there's no // vertical padding by default fontSize: 48.0, @@ -175,10 +173,10 @@ void main() { }); testWidgets('Theme buttonTheme ButtonTheme overrides', (WidgetTester tester) async { - ButtonTextTheme textTheme; - BoxConstraints constraints; - EdgeInsets padding; - ShapeBorder shape; + late ButtonTextTheme textTheme; + late BoxConstraints constraints; + late EdgeInsets padding; + late ShapeBorder shape; await tester.pumpWidget( Theme( @@ -228,12 +226,12 @@ void main() { testWidgets('ButtonTheme alignedDropdown', (WidgetTester tester) async { final Key dropdownKey = UniqueKey(); - Widget buildFrame({ bool alignedDropdown, TextDirection textDirection }) { + Widget buildFrame({ required bool alignedDropdown, required TextDirection textDirection }) { return MaterialApp( - builder: (BuildContext context, Widget child) { + builder: (BuildContext context, Widget? child) { return Directionality( textDirection: textDirection, - child: child, + child: child!, ); }, home: ButtonTheme( @@ -248,7 +246,7 @@ void main() { width: 200.0, child: DropdownButton( key: dropdownKey, - onChanged: (String value) { }, + onChanged: (String? value) { }, value: 'foo', items: const >[ DropdownMenuItem( @@ -374,7 +372,7 @@ void main() { ); Color textColor() { - return tester.renderObject(find.text('FlatButton')).text.style.color; + return tester.renderObject(find.text('FlatButton')).text.style!.color!; } // Default, not disabled. diff --git a/packages/flutter/test/material/card_test.dart b/packages/flutter/test/material/card_test.dart index a07751af81..50436aaa9a 100644 --- a/packages/flutter/test/material/card_test.dart +++ b/packages/flutter/test/material/card_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.8 - import 'package:flutter/painting.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter/material.dart'; @@ -178,7 +176,7 @@ void main() { testWidgets('Card clipBehavior property defers to theme when null', (WidgetTester tester) async { await tester.pumpWidget(Builder(builder: (BuildContext context) { - final ThemeData themeData = Theme.of(context); + final ThemeData themeData = Theme.of(context)!; return Theme( data: themeData.copyWith( cardTheme: themeData.cardTheme.copyWith( @@ -223,4 +221,4 @@ void main() { expect(_getCardMaterial(tester).shadowColor, _getCard(tester).shadowColor); expect(_getCardMaterial(tester).shadowColor, Colors.red); }); -} \ No newline at end of file +} diff --git a/packages/flutter/test/material/card_theme_test.dart b/packages/flutter/test/material/card_theme_test.dart index d3756fcc80..f70fed98f8 100644 --- a/packages/flutter/test/material/card_theme_test.dart +++ b/packages/flutter/test/material/card_theme_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.8 - import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter_test/flutter_test.dart'; diff --git a/packages/flutter/test/material/checkbox_list_tile_test.dart b/packages/flutter/test/material/checkbox_list_tile_test.dart index 4fcb66db24..f97f097355 100644 --- a/packages/flutter/test/material/checkbox_list_tile_test.dart +++ b/packages/flutter/test/material/checkbox_list_tile_test.dart @@ -2,14 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'package:flutter_test/flutter_test.dart'; import 'package:flutter/material.dart'; import '../rendering/mock_canvas.dart'; -Widget wrap({ Widget child }) { +Widget wrap({ required Widget child }) { return MediaQuery( data: const MediaQueryData(), child: Directionality( @@ -25,7 +23,7 @@ void main() { await tester.pumpWidget(wrap( child: CheckboxListTile( value: true, - onChanged: (bool value) { log.add(value); }, + onChanged: (bool? value) { log.add(value); }, title: const Text('Hello'), ), )); @@ -36,12 +34,12 @@ void main() { }); testWidgets('CheckboxListTile checkColor test', (WidgetTester tester) async { - Widget buildFrame(Color color) { + Widget buildFrame(Color? color) { return wrap( child: CheckboxListTile( value: true, checkColor: color, - onChanged: (bool value) {}, + onChanged: (bool? value) {}, ), ); } @@ -52,22 +50,22 @@ void main() { await tester.pumpWidget(buildFrame(null)); await tester.pumpAndSettle(); - expect(getCheckboxListTileRenderer(), paints..path(color: const Color(0xFFFFFFFF))); // paints's color is 0xFFFFFFFF (default color) + expect(getCheckboxListTileRenderer(), paints..path(color: const Color(0xFFFFFFFF))); await tester.pumpWidget(buildFrame(const Color(0xFF000000))); await tester.pumpAndSettle(); - expect(getCheckboxListTileRenderer(), paints..path(color: const Color(0xFF000000))); // paints's color is 0xFF000000 (params) + expect(getCheckboxListTileRenderer(), paints..path(color: const Color(0xFF000000))); }); testWidgets('CheckboxListTile activeColor test', (WidgetTester tester) async { - Widget buildFrame(Color themeColor, Color activeColor) { + Widget buildFrame(Color? themeColor, Color? activeColor) { return wrap( child: Theme( data: ThemeData(toggleableActiveColor: themeColor), child: CheckboxListTile( value: true, activeColor: activeColor, - onChanged: (bool value) {}, + onChanged: (bool? value) {}, ), ), ); @@ -78,11 +76,11 @@ void main() { await tester.pumpWidget(buildFrame(const Color(0xFF000000), null)); await tester.pumpAndSettle(); - expect(getCheckboxListTileRenderer(), paints..rrect(color: const Color(0xFF000000))); // paints's color is 0xFF000000 (theme) + expect(getCheckboxListTileRenderer(), paints..rrect(color: const Color(0xFF000000))); await tester.pumpWidget(buildFrame(const Color(0xFF000000), const Color(0xFFFFFFFF))); await tester.pumpAndSettle(); - expect(getCheckboxListTileRenderer(), paints..rrect(color: const Color(0xFFFFFFFF))); // paints's color is 0xFFFFFFFF (params) + expect(getCheckboxListTileRenderer(), paints..rrect(color: const Color(0xFFFFFFFF))); }); testWidgets('CheckboxListTile can autofocus unless disabled.', (WidgetTester tester) async { @@ -100,7 +98,7 @@ void main() { ); await tester.pump(); - expect(Focus.of(childKey.currentContext, nullOk: true).hasPrimaryFocus, isTrue); + expect(Focus.of(childKey.currentContext!, nullOk: true)!.hasPrimaryFocus, isTrue); await tester.pumpWidget( wrap( @@ -114,7 +112,7 @@ void main() { ); await tester.pump(); - expect(Focus.of(childKey.currentContext, nullOk: true).hasPrimaryFocus, isFalse); + expect(Focus.of(childKey.currentContext!, nullOk: true)!.hasPrimaryFocus, isFalse); }); testWidgets('CheckboxListTile contentPadding test', (WidgetTester tester) async { @@ -148,7 +146,7 @@ void main() { }); testWidgets('CheckboxListTile tristate test', (WidgetTester tester) async { - bool _value = false; + bool? _value = false; bool _tristate = false; await tester.pumpWidget( @@ -160,7 +158,7 @@ void main() { title: const Text('Title'), tristate: _tristate, value: _value, - onChanged: (bool value) { + onChanged: (bool? value) { setState(() { _value = value; }); diff --git a/packages/flutter/test/material/checkbox_test.dart b/packages/flutter/test/material/checkbox_test.dart index 773e6f9918..6280dc9fa4 100644 --- a/packages/flutter/test/material/checkbox_test.dart +++ b/packages/flutter/test/material/checkbox_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.8 - import 'dart:ui'; import 'package:flutter/foundation.dart'; @@ -30,7 +28,7 @@ void main() { child: Center( child: Checkbox( value: true, - onChanged: (bool newValue) { }, + onChanged: (bool? newValue) { }, ), ), ), @@ -49,7 +47,7 @@ void main() { child: Center( child: Checkbox( value: true, - onChanged: (bool newValue) { }, + onChanged: (bool? newValue) { }, ), ), ), @@ -66,7 +64,7 @@ void main() { await tester.pumpWidget(Material( child: Checkbox( value: false, - onChanged: (bool b) { }, + onChanged: (bool? b) { }, ), )); @@ -81,7 +79,7 @@ void main() { await tester.pumpWidget(Material( child: Checkbox( value: true, - onChanged: (bool b) { }, + onChanged: (bool? b) { }, ), )); @@ -139,7 +137,7 @@ void main() { textDirection: TextDirection.ltr, child: Checkbox( value: false, - onChanged: (bool b) { }, + onChanged: (bool? b) { }, ), ), )); @@ -157,7 +155,7 @@ void main() { }); testWidgets('CheckBox tristate: true', (WidgetTester tester) async { - bool checkBoxValue; + bool? checkBoxValue; await tester.pumpWidget( Material( @@ -166,7 +164,7 @@ void main() { return Checkbox( tristate: true, value: checkBoxValue, - onChanged: (bool value) { + onChanged: (bool? value) { setState(() { checkBoxValue = value; }); @@ -207,7 +205,7 @@ void main() { child: Checkbox( tristate: true, value: null, - onChanged: (bool newValue) { }, + onChanged: (bool? newValue) { }, ), ), ); @@ -227,7 +225,7 @@ void main() { child: Checkbox( tristate: true, value: true, - onChanged: (bool newValue) { }, + onChanged: (bool? newValue) { }, ), ), ); @@ -248,7 +246,7 @@ void main() { child: Checkbox( tristate: true, value: false, - onChanged: (bool newValue) { }, + onChanged: (bool? newValue) { }, ), ), ); @@ -268,7 +266,7 @@ void main() { testWidgets('has semantic events', (WidgetTester tester) async { dynamic semanticEvent; - bool checkboxValue = false; + bool? checkboxValue = false; SystemChannels.accessibility.setMockMessageHandler((dynamic message) async { semanticEvent = message; }); @@ -280,7 +278,7 @@ void main() { builder: (BuildContext context, StateSetter setState) { return Checkbox( value: checkboxValue, - onChanged: (bool value) { + onChanged: (bool? value) { setState(() { checkboxValue = value; }); @@ -297,24 +295,24 @@ void main() { expect(checkboxValue, true); expect(semanticEvent, { 'type': 'tap', - 'nodeId': object.debugSemantics.id, + 'nodeId': object.debugSemantics!.id, 'data': {}, }); - expect(object.debugSemantics.getSemanticsData().hasAction(SemanticsAction.tap), true); + expect(object.debugSemantics!.getSemanticsData().hasAction(SemanticsAction.tap), true); SystemChannels.accessibility.setMockMessageHandler(null); semanticsTester.dispose(); }); testWidgets('CheckBox tristate rendering, programmatic transitions', (WidgetTester tester) async { - Widget buildFrame(bool checkboxValue) { + Widget buildFrame(bool? checkboxValue) { return Material( child: StatefulBuilder( builder: (BuildContext context, StateSetter setState) { return Checkbox( tristate: true, value: checkboxValue, - onChanged: (bool value) { }, + onChanged: (bool? value) { }, ); }, ), @@ -357,7 +355,7 @@ void main() { }); testWidgets('CheckBox color rendering', (WidgetTester tester) async { - Widget buildFrame({Color activeColor, Color checkColor, ThemeData themeData}) { + Widget buildFrame({Color? activeColor, Color? checkColor, ThemeData? themeData}) { return Material( child: Theme( data: themeData ?? ThemeData(), @@ -367,7 +365,7 @@ void main() { value: true, activeColor: activeColor, checkColor: checkColor, - onChanged: (bool value) { }, + onChanged: (bool? value) { }, ); }, ), @@ -401,7 +399,7 @@ void main() { testWidgets('Checkbox is focusable and has correct focus color', (WidgetTester tester) async { final FocusNode focusNode = FocusNode(debugLabel: 'Checkbox'); tester.binding.focusManager.highlightStrategy = FocusHighlightStrategy.alwaysTraditional; - bool value = true; + bool? value = true; Widget buildApp({bool enabled = true}) { return MaterialApp( home: Material( @@ -409,7 +407,7 @@ void main() { child: StatefulBuilder(builder: (BuildContext context, StateSetter setState) { return Checkbox( value: value, - onChanged: enabled ? (bool newValue) { + onChanged: enabled ? (bool? newValue) { setState(() { value = newValue; }); @@ -474,7 +472,7 @@ void main() { testWidgets('Checkbox can be hovered and has correct hover color', (WidgetTester tester) async { tester.binding.focusManager.highlightStrategy = FocusHighlightStrategy.alwaysTraditional; - bool value = true; + bool? value = true; Widget buildApp({bool enabled = true}) { return MaterialApp( home: Material( @@ -482,7 +480,7 @@ void main() { child: StatefulBuilder(builder: (BuildContext context, StateSetter setState) { return Checkbox( value: value, - onChanged: enabled ? (bool newValue) { + onChanged: enabled ? (bool? newValue) { setState(() { value = newValue; }); @@ -539,7 +537,7 @@ void main() { testWidgets('Checkbox can be toggled by keyboard shortcuts', (WidgetTester tester) async { tester.binding.focusManager.highlightStrategy = FocusHighlightStrategy.alwaysTraditional; - bool value = true; + bool? value = true; Widget buildApp({bool enabled = true}) { return MaterialApp( home: Material( @@ -547,7 +545,7 @@ void main() { child: StatefulBuilder(builder: (BuildContext context, StateSetter setState) { return Checkbox( value: value, - onChanged: enabled ? (bool newValue) { + onChanged: enabled ? (bool? newValue) { setState(() { value = newValue; }); @@ -587,7 +585,7 @@ void main() { child: Checkbox( visualDensity: visualDensity, key: key, - onChanged: (bool value) {}, + onChanged: (bool? value) {}, value: true, ), ), @@ -616,7 +614,7 @@ void main() { testWidgets('Checkbox stops hover animation when removed from the tree.', (WidgetTester tester) async { const Key checkboxKey = Key('checkbox'); - bool checkboxVal = true; + bool? checkboxVal = true; await tester.pumpWidget( Theme( @@ -629,7 +627,7 @@ void main() { builder: (_, StateSetter setState) => Checkbox( key: checkboxKey, value: checkboxVal, - onChanged: (bool newValue) => setState(() {checkboxVal = newValue;}), + onChanged: (bool? newValue) => setState(() {checkboxVal = newValue;}), ), ), ), @@ -696,7 +694,7 @@ void main() { await tester.pump(); - expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.text); + expect(RendererBinding.instance!.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.text); // Test default cursor await tester.pumpWidget( @@ -718,7 +716,7 @@ void main() { ), ); - expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.click); + expect(RendererBinding.instance!.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.click); // Test default cursor when disabled await tester.pumpWidget( @@ -740,7 +738,7 @@ void main() { ), ); - expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.basic); + expect(RendererBinding.instance!.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.basic); // Test cursor when tristate await tester.pumpWidget( @@ -764,7 +762,7 @@ void main() { ), ); - expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.grab); + expect(RendererBinding.instance!.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.grab); await tester.pumpAndSettle(); }); diff --git a/packages/flutter/test/material/chip_test.dart b/packages/flutter/test/material/chip_test.dart index 05386def28..bd18497530 100644 --- a/packages/flutter/test/material/chip_test.dart +++ b/packages/flutter/test/material/chip_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.8 - import 'dart:ui' show window; import 'package:flutter/gestures.dart'; @@ -73,7 +71,7 @@ double getEnableProgress(WidgetTester tester) => getRenderChip(tester)?.enableAn /// Adds the basic requirements for a Chip. Widget _wrapForChip({ - Widget child, + required Widget child, TextDirection textDirection = TextDirection.ltr, double textScaleFactor = 1.0, Brightness brightness = Brightness.light, @@ -96,8 +94,8 @@ Widget _wrapForChip({ /// cause the chip or label to exceed its constrained height. Future _testConstrainedLabel( WidgetTester tester, { - CircleAvatar avatar, - VoidCallback onDeleted, + CircleAvatar? avatar, + VoidCallback? onDeleted, }) async { const double labelWidth = 100.0; const double labelHeight = 50.0; @@ -134,7 +132,7 @@ Future _testConstrainedLabel( expect(chipSize.height, chipParentHeight); } -Widget _selectedInputChip({ Color checkmarkColor }) { +Widget _selectedInputChip({ Color? checkmarkColor }) { return InputChip( label: const Text('InputChip'), selected: true, @@ -143,7 +141,7 @@ Widget _selectedInputChip({ Color checkmarkColor }) { ); } -Widget _selectedFilterChip({ Color checkmarkColor }) { +Widget _selectedFilterChip({ Color? checkmarkColor }) { return FilterChip( label: const Text('InputChip'), selected: true, @@ -155,8 +153,8 @@ Widget _selectedFilterChip({ Color checkmarkColor }) { Future _pumpCheckmarkChip( WidgetTester tester, { - @required Widget chip, - Color themeColor, + required Widget chip, + Color? themeColor, Brightness brightness = Brightness.light, }) async { await tester.pumpWidget( @@ -191,9 +189,9 @@ void _expectCheckmarkColor(Finder finder, Color color) { } Widget _chipWithOptionalDeleteButton({ - UniqueKey deleteButtonKey, - UniqueKey labelKey, - bool deletable, + UniqueKey? deleteButtonKey, + UniqueKey? labelKey, + required bool deletable, TextDirection textDirection = TextDirection.ltr, }){ return _wrapForChip( @@ -394,7 +392,7 @@ void main() { 'the chip when it exceeds the available space', (WidgetTester tester) async { // Regression test for https://github.com/flutter/flutter/issues/11523 - Widget chipBuilder (String text, {Widget avatar, VoidCallback onDeleted}) { + Widget chipBuilder (String text, {Widget? avatar, VoidCallback? onDeleted}) { return MaterialApp( home: Scaffold( body: Container( @@ -770,7 +768,7 @@ void main() { testWidgets('Avatar drawer works as expected on RawChip', (WidgetTester tester) async { final GlobalKey labelKey = GlobalKey(); - Future pushChip({ Widget avatar }) async { + Future pushChip({ Widget? avatar }) async { return tester.pumpWidget( _wrapForChip( child: Wrap( @@ -1195,7 +1193,7 @@ void main() { testWidgets('Selection with avatar works as expected on RawChip', (WidgetTester tester) async { bool selected = false; final UniqueKey labelKey = UniqueKey(); - Future pushChip({ Widget avatar, bool selectable = false }) async { + Future pushChip({ Widget? avatar, bool selectable = false }) async { return tester.pumpWidget( _wrapForChip( child: Wrap( @@ -1241,7 +1239,7 @@ void main() { // Simulate a tap on the label to select the chip. await tester.tap(find.byKey(labelKey)); expect(selected, equals(true)); - expect(SchedulerBinding.instance.transientCallbackCount, equals(2)); + expect(SchedulerBinding.instance!.transientCallbackCount, equals(2)); await tester.pump(); await tester.pump(const Duration(milliseconds: 50)); expect(getSelectProgress(tester), moreOrLessEquals(0.002, epsilon: 0.01)); @@ -1259,7 +1257,7 @@ void main() { // Simulate another tap on the label to deselect the chip. await tester.tap(find.byKey(labelKey)); expect(selected, equals(false)); - expect(SchedulerBinding.instance.transientCallbackCount, equals(2)); + expect(SchedulerBinding.instance!.transientCallbackCount, equals(2)); await tester.pump(); await tester.pump(const Duration(milliseconds: 20)); expect(getSelectProgress(tester), moreOrLessEquals(0.875, epsilon: 0.01)); @@ -1317,7 +1315,7 @@ void main() { // Simulate a tap on the label to select the chip. await tester.tap(find.byKey(labelKey)); expect(selected, equals(true)); - expect(SchedulerBinding.instance.transientCallbackCount, equals(2)); + expect(SchedulerBinding.instance!.transientCallbackCount, equals(2)); await tester.pump(); await tester.pump(const Duration(milliseconds: 50)); expect(getSelectProgress(tester), moreOrLessEquals(0.002, epsilon: 0.01)); @@ -1335,7 +1333,7 @@ void main() { // Simulate another tap on the label to deselect the chip. await tester.tap(find.byKey(labelKey)); expect(selected, equals(false)); - expect(SchedulerBinding.instance.transientCallbackCount, equals(2)); + expect(SchedulerBinding.instance!.transientCallbackCount, equals(2)); await tester.pump(); await tester.pump(const Duration(milliseconds: 20)); expect(getSelectProgress(tester), moreOrLessEquals(0.875, epsilon: 0.01)); @@ -1354,7 +1352,7 @@ void main() { testWidgets('Activation works as expected on RawChip', (WidgetTester tester) async { bool selected = false; final UniqueKey labelKey = UniqueKey(); - Future pushChip({ Widget avatar, bool selectable = false }) async { + Future pushChip({ Widget? avatar, bool selectable = false }) async { return tester.pumpWidget( _wrapForChip( child: Wrap( @@ -1392,7 +1390,7 @@ void main() { await tester.tap(find.byKey(labelKey)); expect(selected, equals(true)); - expect(SchedulerBinding.instance.transientCallbackCount, equals(2)); + expect(SchedulerBinding.instance!.transientCallbackCount, equals(2)); await tester.pump(); await tester.pump(const Duration(milliseconds: 50)); expect(getSelectProgress(tester), moreOrLessEquals(0.002, epsilon: 0.01)); @@ -1484,9 +1482,9 @@ void main() { final ChipThemeData defaultChipTheme = themeData.chipTheme; bool value = false; Widget buildApp({ - ChipThemeData chipTheme, - Widget avatar, - Widget deleteIcon, + ChipThemeData? chipTheme, + Widget? avatar, + Widget? deleteIcon, bool isSelectable = true, bool isPressable = false, bool isDeletable = true, @@ -1506,7 +1504,7 @@ void main() { avatar: avatar, deleteIcon: deleteIcon, isEnabled: isSelectable || isPressable, - shape: chipTheme.shape, + shape: chipTheme?.shape, selected: isSelectable && value, label: Text('$value'), onSelected: isSelectable @@ -2296,20 +2294,6 @@ void main() { expect(find.byType(InkWell), findsOneWidget); }); - testWidgets('RawChip.selected can not be null', (WidgetTester tester) async { - expect(() async { - MaterialApp( - home: Material( - child: RawChip( - onPressed: () { }, - selected: null, - label: const Text('Chip'), - ), - ), - ); - }, throwsAssertionError); - }); - testWidgets('Chip uses stateful color for text color in different states', (WidgetTester tester) async { final FocusNode focusNode = FocusNode(); @@ -2355,7 +2339,7 @@ void main() { ); } Color textColor() { - return tester.renderObject(find.text('Chip')).text.style.color; + return tester.renderObject(find.text('Chip')).text.style!.color!; } // Default, not disabled. diff --git a/packages/flutter/test/material/chip_theme_test.dart b/packages/flutter/test/material/chip_theme_test.dart index 0882056b88..183fac8368 100644 --- a/packages/flutter/test/material/chip_theme_test.dart +++ b/packages/flutter/test/material/chip_theme_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.8 - import 'dart:ui' show window; import 'package:flutter/gestures.dart'; @@ -171,7 +169,7 @@ void main() { testWidgets('ChipThemeData generates correct opacities for defaults', (WidgetTester tester) async { const Color customColor1 = Color(0xcafefeed); const Color customColor2 = Color(0xdeadbeef); - final TextStyle customStyle = ThemeData.fallback().textTheme.bodyText1.copyWith(color: customColor2); + final TextStyle customStyle = ThemeData.fallback().textTheme.bodyText1!.copyWith(color: customColor2); final ChipThemeData lightTheme = ChipThemeData.fromDefaults( secondaryColor: customColor1, @@ -232,7 +230,7 @@ void main() { final ChipThemeData chipThemeBlack = ChipThemeData.fromDefaults( secondaryColor: Colors.black, brightness: Brightness.dark, - labelStyle: ThemeData.fallback().textTheme.bodyText1.copyWith(color: Colors.black), + labelStyle: ThemeData.fallback().textTheme.bodyText1!.copyWith(color: Colors.black), ).copyWith( elevation: 1.0, labelPadding: const EdgeInsets.symmetric(horizontal: 8.0), @@ -244,7 +242,7 @@ void main() { final ChipThemeData chipThemeWhite = ChipThemeData.fromDefaults( secondaryColor: Colors.white, brightness: Brightness.light, - labelStyle: ThemeData.fallback().textTheme.bodyText1.copyWith(color: Colors.white), + labelStyle: ThemeData.fallback().textTheme.bodyText1!.copyWith(color: Colors.white), ).copyWith( padding: const EdgeInsets.all(2.0), labelPadding: const EdgeInsets.only(top: 8.0, bottom: 8.0), @@ -255,7 +253,7 @@ void main() { checkmarkColor: Colors.white, ); - final ChipThemeData lerp = ChipThemeData.lerp(chipThemeBlack, chipThemeWhite, 0.5); + final ChipThemeData lerp = ChipThemeData.lerp(chipThemeBlack, chipThemeWhite, 0.5)!; const Color middleGrey = Color(0xff7f7f7f); expect(lerp.backgroundColor, equals(middleGrey.withAlpha(0x1f))); expect(lerp.deleteIconColor, equals(middleGrey.withAlpha(0xde))); @@ -276,7 +274,7 @@ void main() { expect(ChipThemeData.lerp(null, null, 0.25), isNull); - final ChipThemeData lerpANull25 = ChipThemeData.lerp(null, chipThemeWhite, 0.25); + final ChipThemeData lerpANull25 = ChipThemeData.lerp(null, chipThemeWhite, 0.25)!; expect(lerpANull25.backgroundColor, equals(Colors.black.withAlpha(0x08))); expect(lerpANull25.deleteIconColor, equals(Colors.black.withAlpha(0x38))); expect(lerpANull25.disabledColor, equals(Colors.black.withAlpha(0x03))); @@ -294,7 +292,7 @@ void main() { expect(lerpANull25.pressElevation, 2.5); expect(lerpANull25.checkmarkColor, equals(Colors.white.withAlpha(0x40))); - final ChipThemeData lerpANull75 = ChipThemeData.lerp(null, chipThemeWhite, 0.75); + final ChipThemeData lerpANull75 = ChipThemeData.lerp(null, chipThemeWhite, 0.75)!; expect(lerpANull75.backgroundColor, equals(Colors.black.withAlpha(0x17))); expect(lerpANull75.deleteIconColor, equals(Colors.black.withAlpha(0xa7))); expect(lerpANull75.disabledColor, equals(Colors.black.withAlpha(0x09))); @@ -312,7 +310,7 @@ void main() { expect(lerpANull75.pressElevation, 7.5); expect(lerpANull75.checkmarkColor, equals(Colors.white.withAlpha(0xbf))); - final ChipThemeData lerpBNull25 = ChipThemeData.lerp(chipThemeBlack, null, 0.25); + final ChipThemeData lerpBNull25 = ChipThemeData.lerp(chipThemeBlack, null, 0.25)!; expect(lerpBNull25.backgroundColor, equals(Colors.white.withAlpha(0x17))); expect(lerpBNull25.deleteIconColor, equals(Colors.white.withAlpha(0xa7))); expect(lerpBNull25.disabledColor, equals(Colors.white.withAlpha(0x09))); @@ -330,7 +328,7 @@ void main() { expect(lerpBNull25.pressElevation, 3.0); expect(lerpBNull25.checkmarkColor, equals(Colors.black.withAlpha(0xbf))); - final ChipThemeData lerpBNull75 = ChipThemeData.lerp(chipThemeBlack, null, 0.75); + final ChipThemeData lerpBNull75 = ChipThemeData.lerp(chipThemeBlack, null, 0.75)!; expect(lerpBNull75.backgroundColor, equals(Colors.white.withAlpha(0x08))); expect(lerpBNull75.deleteIconColor, equals(Colors.white.withAlpha(0x38))); expect(lerpBNull75.disabledColor, equals(Colors.white.withAlpha(0x03))); @@ -402,7 +400,7 @@ void main() { ); } Color textColor() { - return tester.renderObject(find.text('Chip')).text.style.color; + return tester.renderObject(find.text('Chip')).text.style!.color!; } // Default, not disabled. diff --git a/packages/flutter/test/material/circle_avatar_test.dart b/packages/flutter/test/material/circle_avatar_test.dart index 13830c911d..bb71a7f058 100644 --- a/packages/flutter/test/material/circle_avatar_test.dart +++ b/packages/flutter/test/material/circle_avatar_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.8 - import 'dart:typed_data'; import 'package:flutter/material.dart'; @@ -32,7 +30,7 @@ void main() { expect(decoration.color, equals(backgroundColor)); final RenderParagraph paragraph = tester.renderObject(find.text('Z')); - expect(paragraph.text.style.color, equals(ThemeData.fallback().primaryColorLight)); + expect(paragraph.text.style!.color, equals(ThemeData.fallback().primaryColorLight)); }); testWidgets('CircleAvatar with light background color', (WidgetTester tester) async { @@ -54,7 +52,7 @@ void main() { expect(decoration.color, equals(backgroundColor)); final RenderParagraph paragraph = tester.renderObject(find.text('Z')); - expect(paragraph.text.style.color, equals(ThemeData.fallback().primaryColorDark)); + expect(paragraph.text.style!.color, equals(ThemeData.fallback().primaryColorDark)); }); testWidgets('CircleAvatar with image background', (WidgetTester tester) async { @@ -71,7 +69,7 @@ void main() { expect(box.size, equals(const Size(100.0, 100.0))); final RenderDecoratedBox child = box.child as RenderDecoratedBox; final BoxDecoration decoration = child.decoration as BoxDecoration; - expect(decoration.image.fit, equals(BoxFit.cover)); + expect(decoration.image!.fit, equals(BoxFit.cover)); }); testWidgets('CircleAvatar with foreground color', (WidgetTester tester) async { @@ -94,7 +92,7 @@ void main() { expect(decoration.color, equals(fallback.primaryColorDark)); final RenderParagraph paragraph = tester.renderObject(find.text('Z')); - expect(paragraph.text.style.color, equals(foregroundColor)); + expect(paragraph.text.style!.color, equals(foregroundColor)); }); testWidgets('CircleAvatar with light theme', (WidgetTester tester) async { @@ -119,7 +117,7 @@ void main() { expect(decoration.color, equals(theme.primaryColorLight)); final RenderParagraph paragraph = tester.renderObject(find.text('Z')); - expect(paragraph.text.style.color, equals(theme.primaryTextTheme.headline6.color)); + expect(paragraph.text.style!.color, equals(theme.primaryTextTheme.headline6!.color)); }); testWidgets('CircleAvatar with dark theme', (WidgetTester tester) async { @@ -144,7 +142,7 @@ void main() { expect(decoration.color, equals(theme.primaryColorDark)); final RenderParagraph paragraph = tester.renderObject(find.text('Z')); - expect(paragraph.text.style.color, equals(theme.primaryTextTheme.headline6.color)); + expect(paragraph.text.style!.color, equals(theme.primaryTextTheme.headline6!.color)); }); testWidgets('CircleAvatar text does not expand with textScaleFactor', (WidgetTester tester) async { @@ -171,7 +169,7 @@ void main() { child: CircleAvatar( child: Builder( builder: (BuildContext context) { - final MediaQueryData data = MediaQuery.of(context); + final MediaQueryData data = MediaQuery.of(context)!; // These should not change. expect(data.size, equals(const Size(111.0, 111.0))); @@ -211,7 +209,7 @@ void main() { expect(decoration.color, equals(backgroundColor)); final RenderParagraph paragraph = tester.renderObject(find.text('Z')); - expect(paragraph.text.style.color, equals(ThemeData.fallback().primaryColorLight)); + expect(paragraph.text.style!.color, equals(ThemeData.fallback().primaryColorLight)); }); testWidgets('CircleAvatar respects maxRadius', (WidgetTester tester) async { @@ -233,7 +231,7 @@ void main() { expect(decoration.color, equals(backgroundColor)); final RenderParagraph paragraph = tester.renderObject(find.text('Z')); - expect(paragraph.text.style.color, equals(ThemeData.fallback().primaryColorLight)); + expect(paragraph.text.style!.color, equals(ThemeData.fallback().primaryColorLight)); }); testWidgets('CircleAvatar respects setting both minRadius and maxRadius', (WidgetTester tester) async { @@ -256,11 +254,11 @@ void main() { expect(decoration.color, equals(backgroundColor)); final RenderParagraph paragraph = tester.renderObject(find.text('Z')); - expect(paragraph.text.style.color, equals(ThemeData.fallback().primaryColorLight)); + expect(paragraph.text.style!.color, equals(ThemeData.fallback().primaryColorLight)); }); } -Widget wrap({ Widget child }) { +Widget wrap({ required Widget child }) { return Directionality( textDirection: TextDirection.ltr, child: MediaQuery( diff --git a/packages/flutter/test/material/color_scheme_test.dart b/packages/flutter/test/material/color_scheme_test.dart index 1fb09f2189..2e2ea20a5f 100644 --- a/packages/flutter/test/material/color_scheme_test.dart +++ b/packages/flutter/test/material/color_scheme_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.8 - import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; diff --git a/packages/flutter/test/material/colors_test.dart b/packages/flutter/test/material/colors_test.dart index cc64190a31..6f6500dc87 100644 --- a/packages/flutter/test/material/colors_test.dart +++ b/packages/flutter/test/material/colors_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.8 - import 'package:flutter/material.dart'; import '../flutter_test_alternative.dart'; @@ -31,16 +29,16 @@ void main() { expect(color.value, 500); - expect(color[50].value, 0x00000050); - expect(color[100].value, 0x00000100); - expect(color[200].value, 0x00000200); - expect(color[300].value, 0x00000300); - expect(color[400].value, 0x00000400); - expect(color[500].value, 0x00000500); - expect(color[600].value, 0x00000600); - expect(color[700].value, 0x00000700); - expect(color[800].value, 0x00000800); - expect(color[900].value, 0x00000900); + expect(color[50]!.value, 0x00000050); + expect(color[100]!.value, 0x00000100); + expect(color[200]!.value, 0x00000200); + expect(color[300]!.value, 0x00000300); + expect(color[400]!.value, 0x00000400); + expect(color[500]!.value, 0x00000500); + expect(color[600]!.value, 0x00000600); + expect(color[700]!.value, 0x00000700); + expect(color[800]!.value, 0x00000800); + expect(color[900]!.value, 0x00000900); expect(color.shade50.value, 0x00000050); expect(color.shade100.value, 0x00000100); @@ -56,31 +54,31 @@ void main() { test('Colors swatches do not contain duplicates', () { for (final MaterialColor color in Colors.primaries) - expect(primaryKeys.map((int key) => color[key]).toSet().length, primaryKeys.length); + expect(primaryKeys.map((int key) => color[key]!).toSet().length, primaryKeys.length); - expect(primaryKeys.map((int key) => Colors.grey[key]).toSet().length, primaryKeys.length); + expect(primaryKeys.map((int key) => Colors.grey[key]!).toSet().length, primaryKeys.length); for (final MaterialAccentColor color in Colors.accents) - expect(accentKeys.map((int key) => color[key]).toSet().length, accentKeys.length); + expect(accentKeys.map((int key) => color[key]!).toSet().length, accentKeys.length); }); test('All color swatch colors are opaque and equal their primary color', () { for (final MaterialColor color in Colors.primaries) { expect(color.value, color.shade500.value); for (final int key in primaryKeys) { - expect(color[key].alpha, 0xFF); + expect(color[key]!.alpha, 0xFF); } } expect(Colors.grey.value, Colors.grey.shade500.value); for (final int key in primaryKeys) { - expect(Colors.grey[key].alpha, 0xFF); + expect(Colors.grey[key]!.alpha, 0xFF); } for (final MaterialAccentColor color in Colors.accents) { expect(color.value, color.shade200.value); for (final int key in accentKeys) { - expect(color[key].alpha, 0xFF); + expect(color[key]!.alpha, 0xFF); } } }); diff --git a/packages/flutter/test/material/data_table_test.dart b/packages/flutter/test/material/data_table_test.dart index e7edfeb2b3..f6573d62be 100644 --- a/packages/flutter/test/material/data_table_test.dart +++ b/packages/flutter/test/material/data_table_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.8 - import 'dart:math' as math; import 'package:flutter/gestures.dart'; @@ -18,11 +16,11 @@ void main() { testWidgets('DataTable control test', (WidgetTester tester) async { final List log = []; - Widget buildTable({ int sortColumnIndex, bool sortAscending = true }) { + Widget buildTable({ int? sortColumnIndex, bool sortAscending = true }) { return DataTable( sortColumnIndex: sortColumnIndex, sortAscending: sortAscending, - onSelectAll: (bool value) { + onSelectAll: (bool? value) { log.add('select-all: $value'); }, columns: [ @@ -42,7 +40,7 @@ void main() { rows: kDesserts.map((Dessert dessert) { return DataRow( key: ValueKey(dessert.name), - onSelectChanged: (bool selected) { + onSelectChanged: (bool? selected) { log.add('row-selected: ${dessert.name}'); }, cells: [ @@ -112,7 +110,7 @@ void main() { Widget buildTable({ bool checkboxes = false }) { return DataTable( showCheckboxColumn: checkboxes, - onSelectAll: (bool value) { + onSelectAll: (bool? value) { log.add('select-all: $value'); }, columns: const [ @@ -129,7 +127,7 @@ void main() { rows: kDesserts.map((Dessert dessert) { return DataRow( key: ValueKey(dessert.name), - onSelectChanged: (bool selected) { + onSelectChanged: (bool? selected) { log.add('row-selected: ${dessert.name}'); }, cells: [ @@ -395,7 +393,7 @@ void main() { testWidgets('DataTable custom row height', (WidgetTester tester) async { Widget buildCustomTable({ - int sortColumnIndex, + int? sortColumnIndex, bool sortAscending = true, double dataRowHeight = 48.0, double headingRowHeight = 56.0, @@ -403,7 +401,7 @@ void main() { return DataTable( sortColumnIndex: sortColumnIndex, sortAscending: sortAscending, - onSelectAll: (bool value) {}, + onSelectAll: (bool? value) {}, dataRowHeight: dataRowHeight, headingRowHeight: headingRowHeight, columns: [ @@ -421,7 +419,7 @@ void main() { rows: kDesserts.map((Dessert dessert) { return DataRow( key: ValueKey(dessert.name), - onSelectChanged: (bool selected) {}, + onSelectChanged: (bool? selected) {}, cells: [ DataCell( Text(dessert.name), @@ -441,7 +439,7 @@ void main() { await tester.pumpWidget(MaterialApp( home: Material( child: DataTable( - onSelectAll: (bool value) {}, + onSelectAll: (bool? value) {}, columns: [ const DataColumn( label: Text('Name'), @@ -457,7 +455,7 @@ void main() { rows: kDesserts.map((Dessert dessert) { return DataRow( key: ValueKey(dessert.name), - onSelectChanged: (bool selected) {}, + onSelectChanged: (bool? selected) {}, cells: [ DataCell( Text(dessert.name), @@ -520,13 +518,13 @@ void main() { Finder padding; Widget buildDefaultTable({ - int sortColumnIndex, + int? sortColumnIndex, bool sortAscending = true, }) { return DataTable( sortColumnIndex: sortColumnIndex, sortAscending: sortAscending, - onSelectAll: (bool value) {}, + onSelectAll: (bool? value) {}, columns: [ const DataColumn( label: Text('Name'), @@ -548,7 +546,7 @@ void main() { rows: kDesserts.map((Dessert dessert) { return DataRow( key: ValueKey(dessert.name), - onSelectChanged: (bool selected) {}, + onSelectChanged: (bool? selected) {}, cells: [ DataCell( Text(dessert.name), @@ -623,15 +621,15 @@ void main() { ); Widget buildCustomTable({ - int sortColumnIndex, + int? sortColumnIndex, bool sortAscending = true, - double horizontalMargin, - double columnSpacing, + double? horizontalMargin, + double? columnSpacing, }) { return DataTable( sortColumnIndex: sortColumnIndex, sortAscending: sortAscending, - onSelectAll: (bool value) {}, + onSelectAll: (bool? value) {}, horizontalMargin: horizontalMargin, columnSpacing: columnSpacing, columns: [ @@ -655,7 +653,7 @@ void main() { rows: kDesserts.map((Dessert dessert) { return DataRow( key: ValueKey(dessert.name), - onSelectChanged: (bool selected) {}, + onSelectChanged: (bool? selected) {}, cells: [ DataCell( Text(dessert.name), @@ -742,7 +740,7 @@ void main() { Finder padding; Widget buildDefaultTable({ - int sortColumnIndex, + int? sortColumnIndex, bool sortAscending = true, }) { return DataTable( @@ -831,10 +829,10 @@ void main() { ); Widget buildCustomTable({ - int sortColumnIndex, + int? sortColumnIndex, bool sortAscending = true, - double horizontalMargin, - double columnSpacing, + double? horizontalMargin, + double? columnSpacing, }) { return DataTable( sortColumnIndex: sortColumnIndex, @@ -959,7 +957,7 @@ void main() { Table table = tester.widget(find.byType(Table)); TableRow tableRow = table.children.last; BoxDecoration boxDecoration = tableRow.decoration as BoxDecoration; - expect(boxDecoration.border.top.width, 1.0); + expect(boxDecoration.border!.top.width, 1.0); const double thickness = 4.2; await tester.pumpWidget( @@ -976,7 +974,7 @@ void main() { table = tester.widget(find.byType(Table)); tableRow = table.children.last; boxDecoration = tableRow.decoration as BoxDecoration; - expect(boxDecoration.border.top.width, thickness); + expect(boxDecoration.border!.top.width, thickness); }); testWidgets('DataTable set show bottom border', (WidgetTester tester) async { @@ -1010,7 +1008,7 @@ void main() { Table table = tester.widget(find.byType(Table)); TableRow tableRow = table.children.last; BoxDecoration boxDecoration = tableRow.decoration as BoxDecoration; - expect(boxDecoration.border.bottom.width, 1.0); + expect(boxDecoration.border!.bottom.width, 1.0); await tester.pumpWidget( MaterialApp( @@ -1025,11 +1023,11 @@ void main() { table = tester.widget(find.byType(Table)); tableRow = table.children.last; boxDecoration = tableRow.decoration as BoxDecoration; - expect(boxDecoration.border.bottom.width, 0.0); + expect(boxDecoration.border!.bottom.width, 0.0); }); testWidgets('DataTable column heading cell - with and without sorting', (WidgetTester tester) async { - Widget buildTable({ int sortColumnIndex, bool sortEnabled = true }) { + Widget buildTable({ int? sortColumnIndex, bool sortEnabled = true }) { return DataTable( sortColumnIndex: sortColumnIndex, columns: [ @@ -1098,7 +1096,7 @@ void main() { // Regression test for a bug described in // https://github.com/flutter/flutter/pull/43735#issuecomment-589459947 // Filed at https://github.com/flutter/flutter/issues/51152 - Widget buildTable({ int sortColumnIndex }) { + Widget buildTable({ int? sortColumnIndex }) { return DataTable( sortColumnIndex: sortColumnIndex, columns: [ @@ -1208,7 +1206,7 @@ void main() { cells: const [ DataCell(Text('Content1')), ], - onSelectChanged: (bool value) {}, + onSelectChanged: (bool? value) {}, ), DataRow( color: MaterialStateProperty.resolveWith( @@ -1221,7 +1219,7 @@ void main() { cells: const [ DataCell(Text('Content2')), ], - onSelectChanged: disabled ? null : (bool value) {}, + onSelectChanged: disabled ? null : (bool? value) {}, ), ], ), @@ -1263,7 +1261,7 @@ void main() { return Colors.transparent; }, ), - onSelectChanged: (bool value) {}, + onSelectChanged: (bool? value) {}, cells: const [ DataCell(Text('Content1')), ], diff --git a/packages/flutter/test/material/data_table_theme_test.dart b/packages/flutter/test/material/data_table_theme_test.dart index 5583b867c1..a84ccbf571 100644 --- a/packages/flutter/test/material/data_table_theme_test.dart +++ b/packages/flutter/test/material/data_table_theme_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.8 - import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -135,15 +133,15 @@ void main() { ), ); - final TextStyle dataRowTextStyle = tester.renderObject(find.text('Data')).text.style; + final TextStyle dataRowTextStyle = tester.renderObject(find.text('Data')).text.style!; expect(dataRowTextStyle.fontSize, dataTextStyle.fontSize); expect(_tableRowBoxDecoration(tester: tester, index: 1).color, dataRowColor.resolve({})); - expect(_tableRowBoxDecoration(tester: tester, index: 1).border.top.width, dividerThickness); + expect(_tableRowBoxDecoration(tester: tester, index: 1).border!.top.width, dividerThickness); final Finder dataRowContainer = find.ancestor(of: find.text('Data'), matching: find.byType(Container)); expect(tester.getSize(dataRowContainer).height, dataRowHeight); - final TextStyle headingRowTextStyle = tester.renderObject(find.text('A')).text.style; + final TextStyle headingRowTextStyle = tester.renderObject(find.text('A')).text.style!; expect(headingRowTextStyle.fontSize, headingTextStyle.fontSize); expect(_tableRowBoxDecoration(tester: tester, index: 0).color, headingRowColor.resolve({})); @@ -226,15 +224,15 @@ void main() { ), ); - final TextStyle dataRowTextStyle = tester.renderObject(find.text('Data')).text.style; + final TextStyle dataRowTextStyle = tester.renderObject(find.text('Data')).text.style!; expect(dataRowTextStyle.fontSize, dataTextStyle.fontSize); expect(_tableRowBoxDecoration(tester: tester, index: 1).color, dataRowColor.resolve({})); - expect(_tableRowBoxDecoration(tester: tester, index: 1).border.top.width, dividerThickness); + expect(_tableRowBoxDecoration(tester: tester, index: 1).border!.top.width, dividerThickness); final Finder dataRowContainer = find.ancestor(of: find.text('Data'), matching: find.byType(Container)); expect(tester.getSize(dataRowContainer).height, dataRowHeight); - final TextStyle headingRowTextStyle = tester.renderObject(find.text('A')).text.style; + final TextStyle headingRowTextStyle = tester.renderObject(find.text('A')).text.style!; expect(headingRowTextStyle.fontSize, headingTextStyle.fontSize); expect(_tableRowBoxDecoration(tester: tester, index: 0).color, headingRowColor.resolve({})); @@ -245,7 +243,7 @@ void main() { }); } -BoxDecoration _tableRowBoxDecoration({WidgetTester tester, int index}) { +BoxDecoration _tableRowBoxDecoration({required WidgetTester tester, required int index}) { final Table table = tester.widget(find.byType(Table)); final TableRow tableRow = table.children[index]; return tableRow.decoration as BoxDecoration; diff --git a/packages/flutter/test/material/date_picker_test.dart b/packages/flutter/test/material/date_picker_test.dart index f94d7afcab..fcb2b7a86f 100644 --- a/packages/flutter/test/material/date_picker_test.dart +++ b/packages/flutter/test/material/date_picker_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.8 - import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -12,7 +10,7 @@ import '../rendering/mock_canvas.dart'; import 'feedback_tester.dart'; class MockClipboard { - Object _clipboardData = { + dynamic _clipboardData = { 'text': null, }; @@ -31,21 +29,21 @@ void main() { TestWidgetsFlutterBinding.ensureInitialized(); final MockClipboard mockClipboard = MockClipboard(); - DateTime firstDate; - DateTime lastDate; - DateTime initialDate; - DateTime today; - SelectableDayPredicate selectableDayPredicate; - DatePickerEntryMode initialEntryMode; - DatePickerMode initialCalendarMode; + late DateTime firstDate; + late DateTime lastDate; + late DateTime initialDate; + late DateTime today; + late SelectableDayPredicate? selectableDayPredicate; + late DatePickerEntryMode initialEntryMode; + late DatePickerMode initialCalendarMode; - String cancelText; - String confirmText; - String errorFormatText; - String errorInvalidText; - String fieldHintText; - String fieldLabelText; - String helpText; + String? cancelText; + String? confirmText; + String? errorFormatText; + String? errorInvalidText; + String? fieldHintText; + String? fieldLabelText; + String? helpText; final Finder nextMonthIcon = find.byWidgetPredicate((Widget w) => w is IconButton && (w.tooltip?.startsWith('Next month') ?? false)); final Finder previousMonthIcon = find.byWidgetPredicate((Widget w) => w is IconButton && (w.tooltip?.startsWith('Previous month') ?? false)); @@ -88,7 +86,7 @@ void main() { Future callback(Future date), { TextDirection textDirection = TextDirection.ltr } ) async { - BuildContext buttonContext; + late BuildContext buttonContext; await tester.pumpWidget(MaterialApp( home: Material( child: Builder( @@ -123,10 +121,10 @@ void main() { fieldHintText: fieldHintText, fieldLabelText: fieldLabelText, helpText: helpText, - builder: (BuildContext context, Widget child) { + builder: (BuildContext context, Widget? child) { return Directionality( textDirection: textDirection, - child: child, + child: child ?? const SizedBox(), ); }, ); @@ -141,9 +139,9 @@ void main() { confirmText = 'yep'; helpText = 'help'; await prepareDatePicker(tester, (Future date) async { - expect(find.text(cancelText), findsOneWidget); - expect(find.text(confirmText), findsOneWidget); - expect(find.text(helpText), findsOneWidget); + expect(find.text(cancelText!), findsOneWidget); + expect(find.text(confirmText!), findsOneWidget); + expect(find.text(helpText!), findsOneWidget); }); }); @@ -219,10 +217,10 @@ void main() { initialDate: DateTime.now(), firstDate: DateTime(2018), lastDate: DateTime(2030), - builder: (BuildContext context, Widget child) { + builder: (BuildContext context, Widget? child) { return Directionality( textDirection: textDirection, - child: child, + child: child ?? const SizedBox(), ); }, ); @@ -273,7 +271,7 @@ void main() { initialDate: DateTime.now(), firstDate: DateTime(2018), lastDate: DateTime(2030), - builder: (BuildContext context, Widget child) => const SizedBox(), + builder: (BuildContext context, Widget? child) => const SizedBox(), ); }, child: const Text('Show Date Picker'), @@ -377,10 +375,10 @@ void main() { initialDate: DateTime(2016, DateTime.january, 15), firstDate:DateTime(2001, DateTime.january, 1), lastDate: DateTime(2031, DateTime.december, 31), - builder: (BuildContext context, Widget child) { + builder: (BuildContext context, Widget? child) { return Directionality( textDirection: textDirection, - child: child, + child: child ?? const SizedBox(), ); }, ); @@ -670,11 +668,11 @@ void main() { fieldLabelText = 'label'; helpText = 'help'; await prepareDatePicker(tester, (Future date) async { - expect(find.text(cancelText), findsOneWidget); - expect(find.text(confirmText), findsOneWidget); - expect(find.text(fieldHintText), findsOneWidget); - expect(find.text(fieldLabelText), findsOneWidget); - expect(find.text(helpText), findsOneWidget); + expect(find.text(cancelText!), findsOneWidget); + expect(find.text(confirmText!), findsOneWidget); + expect(find.text(fieldHintText!), findsOneWidget); + expect(find.text(fieldLabelText!), findsOneWidget); + expect(find.text(helpText!), findsOneWidget); }); }); @@ -697,7 +695,7 @@ void main() { testWidgets('Toggle to calendar mode keeps selected date', (WidgetTester tester) async { await prepareDatePicker(tester, (Future date) async { final TextField field = textField(tester); - field.controller.clear(); + field.controller!.clear(); await tester.enterText(find.byType(TextField), '12/25/2016'); await tester.tap(find.byIcon(Icons.calendar_today)); @@ -710,7 +708,7 @@ void main() { testWidgets('Entered text returns date', (WidgetTester tester) async { await prepareDatePicker(tester, (Future date) async { final TextField field = textField(tester); - field.controller.clear(); + field.controller!.clear(); await tester.enterText(find.byType(TextField), '12/25/2016'); await tester.tap(find.text('OK')); @@ -722,15 +720,15 @@ void main() { errorFormatText = 'oops'; await prepareDatePicker(tester, (Future date) async { final TextField field = textField(tester); - field.controller.clear(); + field.controller!.clear(); await tester.pumpAndSettle(); await tester.enterText(find.byType(TextField), '1225'); - expect(find.text(errorFormatText), findsNothing); + expect(find.text(errorFormatText!), findsNothing); await tester.tap(find.text('OK')); await tester.pumpAndSettle(); - expect(find.text(errorFormatText), findsOneWidget); + expect(find.text(errorFormatText!), findsOneWidget); }); }); @@ -738,16 +736,16 @@ void main() { errorFormatText = 'oops'; await prepareDatePicker(tester, (Future date) async { final TextField field = textField(tester); - field.controller.clear(); + field.controller!.clear(); await tester.pumpAndSettle(); await tester.enterText(find.byType(TextField), '20 days, 3 months, 2003'); expect(find.text('20 days, 3 months, 2003'), findsOneWidget); - expect(find.text(errorFormatText), findsNothing); + expect(find.text(errorFormatText!), findsNothing); await tester.tap(find.text('OK')); await tester.pumpAndSettle(); - expect(find.text(errorFormatText), findsOneWidget); + expect(find.text(errorFormatText!), findsOneWidget); }); }); @@ -755,20 +753,20 @@ void main() { errorInvalidText = 'oops'; await prepareDatePicker(tester, (Future date) async { final TextField field = textField(tester); - field.controller.clear(); + field.controller!.clear(); await tester.pumpAndSettle(); await tester.enterText(find.byType(TextField), '08/10/1969'); - expect(find.text(errorInvalidText), findsNothing); + expect(find.text(errorInvalidText!), findsNothing); await tester.tap(find.text('OK')); await tester.pumpAndSettle(); - expect(find.text(errorInvalidText), findsOneWidget); + expect(find.text(errorInvalidText!), findsOneWidget); }); }); testWidgets('InputDecorationTheme is honored', (WidgetTester tester) async { - BuildContext buttonContext; + late BuildContext buttonContext; const InputBorder border = InputBorder.none; await tester.pumpWidget(MaterialApp( theme: ThemeData.light().copyWith( @@ -883,7 +881,7 @@ void main() { group('Haptic feedback', () { const Duration hapticFeedbackInterval = Duration(milliseconds: 10); - FeedbackTester feedback; + late FeedbackTester feedback; setUp(() { feedback = FeedbackTester(); @@ -895,7 +893,7 @@ void main() { }); tearDown(() { - feedback?.dispose(); + feedback.dispose(); }); testWidgets('Selecting date vibrates', (WidgetTester tester) async { @@ -1523,7 +1521,7 @@ class _DatePickerObserver extends NavigatorObserver { int datePickerCount = 0; @override - void didPush(Route route, Route previousRoute) { + void didPush(Route route, Route? previousRoute) { if (route.toString().contains('_DialogRoute')) { datePickerCount++; } diff --git a/packages/flutter/test/material/date_range_picker_test.dart b/packages/flutter/test/material/date_range_picker_test.dart index 10eafb0fc7..8d1bb8a3c9 100644 --- a/packages/flutter/test/material/date_range_picker_test.dart +++ b/packages/flutter/test/material/date_range_picker_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.8 - import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -11,23 +9,23 @@ import 'package:flutter_test/flutter_test.dart'; import 'feedback_tester.dart'; void main() { - DateTime firstDate; - DateTime lastDate; - DateTime currentDate; - DateTimeRange initialDateRange; - DatePickerEntryMode initialEntryMode = DatePickerEntryMode.calendar; + late DateTime firstDate; + late DateTime lastDate; + late DateTime? currentDate; + late DateTimeRange? initialDateRange; + late DatePickerEntryMode initialEntryMode = DatePickerEntryMode.calendar; - String cancelText; - String confirmText; - String errorInvalidRangeText; - String errorFormatText; - String errorInvalidText; - String fieldStartHintText; - String fieldEndHintText; - String fieldStartLabelText; - String fieldEndLabelText; - String helpText; - String saveText; + String? cancelText; + String? confirmText; + String? errorInvalidRangeText; + String? errorFormatText; + String? errorInvalidText; + String? fieldStartHintText; + String? fieldEndHintText; + String? fieldStartLabelText; + String? fieldEndLabelText; + String? helpText; + String? saveText; setUp(() { firstDate = DateTime(2015, DateTime.january, 1); @@ -57,7 +55,7 @@ void main() { Future callback(Future date), { TextDirection textDirection = TextDirection.ltr } ) async { - BuildContext buttonContext; + late BuildContext buttonContext; await tester.pumpWidget(MaterialApp( home: Material( child: Builder( @@ -94,10 +92,10 @@ void main() { fieldEndLabelText: fieldEndLabelText, helpText: helpText, saveText: saveText, - builder: (BuildContext context, Widget child) { + builder: (BuildContext context, Widget? child) { return Directionality( textDirection: textDirection, - child: child, + child: child ?? const SizedBox(), ); }, ); @@ -110,8 +108,8 @@ void main() { helpText = 'help'; saveText = 'make it so'; await preparePicker(tester, (Future range) async { - expect(find.text(helpText), findsOneWidget); - expect(find.text(saveText), findsOneWidget); + expect(find.text(helpText!), findsOneWidget); + expect(find.text(saveText!), findsOneWidget); }); }); @@ -316,10 +314,10 @@ void main() { context: context, firstDate:DateTime(2001, DateTime.january, 1), lastDate: DateTime(2031, DateTime.december, 31), - builder: (BuildContext context, Widget child) { + builder: (BuildContext context, Widget? child) { return Directionality( textDirection: textDirection, - child: child, + child: child ?? const SizedBox(), ); }, ); @@ -360,7 +358,7 @@ void main() { group('Haptic feedback', () { const Duration hapticFeedbackInterval = Duration(milliseconds: 10); - FeedbackTester feedback; + late FeedbackTester feedback; setUp(() { feedback = FeedbackTester(); @@ -373,7 +371,7 @@ void main() { }); tearDown(() { - feedback?.dispose(); + feedback.dispose(); }); testWidgets('Selecting dates vibrates', (WidgetTester tester) async { @@ -606,13 +604,13 @@ void main() { fieldEndLabelText = 'label2'; helpText = 'help'; await preparePicker(tester, (Future range) async { - expect(find.text(cancelText), findsOneWidget); - expect(find.text(confirmText), findsOneWidget); - expect(find.text(fieldStartHintText), findsOneWidget); - expect(find.text(fieldEndHintText), findsOneWidget); - expect(find.text(fieldStartLabelText), findsOneWidget); - expect(find.text(fieldEndLabelText), findsOneWidget); - expect(find.text(helpText), findsOneWidget); + expect(find.text(cancelText!), findsOneWidget); + expect(find.text(confirmText!), findsOneWidget); + expect(find.text(fieldStartHintText!), findsOneWidget); + expect(find.text(fieldEndHintText!), findsOneWidget); + expect(find.text(fieldStartLabelText!), findsOneWidget); + expect(find.text(fieldEndLabelText!), findsOneWidget); + expect(find.text(helpText!), findsOneWidget); }); }); @@ -671,11 +669,11 @@ void main() { await preparePicker(tester, (Future range) async { await tester.enterText(find.byType(TextField).at(0), '12/25'); await tester.enterText(find.byType(TextField).at(1), '12/25'); - expect(find.text(errorFormatText), findsNothing); + expect(find.text(errorFormatText!), findsNothing); await tester.tap(find.text('OK')); await tester.pumpAndSettle(); - expect(find.text(errorFormatText), findsNWidgets(2)); + expect(find.text(errorFormatText!), findsNWidgets(2)); }); }); @@ -685,11 +683,11 @@ void main() { await preparePicker(tester, (Future range) async { await tester.enterText(find.byType(TextField).at(0), '20202014'); await tester.enterText(find.byType(TextField).at(1), '20212014'); - expect(find.text(errorFormatText), findsNothing); + expect(find.text(errorFormatText!), findsNothing); await tester.tap(find.text('OK')); await tester.pumpAndSettle(); - expect(find.text(errorFormatText), findsNWidgets(2)); + expect(find.text(errorFormatText!), findsNWidgets(2)); }); }); @@ -699,11 +697,11 @@ void main() { await preparePicker(tester, (Future range) async { await tester.enterText(find.byType(TextField).at(0), '08/08/2014'); await tester.enterText(find.byType(TextField).at(1), '08/08/2014'); - expect(find.text(errorInvalidText), findsNothing); + expect(find.text(errorInvalidText!), findsNothing); await tester.tap(find.text('OK')); await tester.pumpAndSettle(); - expect(find.text(errorInvalidText), findsNWidgets(2)); + expect(find.text(errorInvalidText!), findsNWidgets(2)); }); }); @@ -713,11 +711,11 @@ void main() { await preparePicker(tester, (Future range) async { await tester.enterText(find.byType(TextField).at(0), '12/27/2016'); await tester.enterText(find.byType(TextField).at(1), '12/25/2016'); - expect(find.text(errorInvalidRangeText), findsNothing); + expect(find.text(errorInvalidRangeText!), findsNothing); await tester.tap(find.text('OK')); await tester.pumpAndSettle(); - expect(find.text(errorInvalidRangeText), findsOneWidget); + expect(find.text(errorInvalidRangeText!), findsOneWidget); }); }); @@ -727,11 +725,11 @@ void main() { await preparePicker(tester, (Future range) async { await tester.enterText(find.byType(TextField).at(0), '12/27/2016'); await tester.enterText(find.byType(TextField).at(1), '01/01/2018'); - expect(find.text(errorInvalidText), findsNothing); + expect(find.text(errorInvalidText!), findsNothing); await tester.tap(find.text('OK')); await tester.pumpAndSettle(); - expect(find.text(errorInvalidText), findsOneWidget); + expect(find.text(errorInvalidText!), findsOneWidget); }); }); @@ -768,7 +766,7 @@ void main() { expect(containerColor, equals(expectedContainerColor)); } - BuildContext buttonContext; + late BuildContext buttonContext; const InputBorder border = InputBorder.none; await tester.pumpWidget(MaterialApp( theme: ThemeData.light().copyWith( diff --git a/packages/flutter/test/material/debug_test.dart b/packages/flutter/test/material/debug_test.dart index de63033cd9..5647ba9f86 100644 --- a/packages/flutter/test/material/debug_test.dart +++ b/packages/flutter/test/material/debug_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.8 - import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -231,12 +229,12 @@ void main() { ) )); final List exceptions = []; - final FlutterExceptionHandler oldHandler = FlutterError.onError; + final FlutterExceptionHandler? oldHandler = FlutterError.onError; FlutterError.onError = (FlutterErrorDetails details) { exceptions.add(details.exception); }; // ScaffoldMessenger shows SnackBar. - _scaffoldMessengerKey.currentState.showSnackBar(snackBar); + _scaffoldMessengerKey.currentState!.showSnackBar(snackBar); await tester.pumpAndSettle(); // Pump widget to rebuild without ScaffoldMessenger