From 793678d50e4b52ffa63c60a91d4d2051b1932d37 Mon Sep 17 00:00:00 2001 From: Michael Goderbauer Date: Fri, 9 Oct 2020 10:42:02 -0700 Subject: [PATCH] Migrate tests to null-safety (#67692) --- .../test/material/text_theme_test.dart | 88 ++++--- .../test/material/theme_data_test.dart | 42 ++-- .../test/material/theme_defaults_test.dart | 20 +- .../flutter/test/material/theme_test.dart | 230 +++++++++--------- .../test/material/time_picker_test.dart | 90 ++++--- .../test/material/time_picker_theme_test.dart | 72 +++--- packages/flutter/test/material/time_test.dart | 4 +- .../test/material/toggle_buttons_test.dart | 62 +---- .../material/toggle_buttons_theme_test.dart | 4 +- .../flutter/test/material/tooltip_test.dart | 18 +- .../test/material/tooltip_theme_test.dart | 30 ++- .../test/material/typography_test.dart | 128 +++++----- .../user_accounts_drawer_header_test.dart | 28 +-- .../flutter/test/material/will_pop_test.dart | 34 +-- .../test/widgets/app_overrides_test.dart | 8 +- packages/flutter/test/widgets/app_test.dart | 53 ++-- .../flutter/test/widgets/app_title_test.dart | 4 +- .../test/widgets/aspect_ratio_test.dart | 2 - .../test/widgets/async_lifecycle_test.dart | 6 +- 19 files changed, 418 insertions(+), 505 deletions(-) diff --git a/packages/flutter/test/material/text_theme_test.dart b/packages/flutter/test/material/text_theme_test.dart index 44d673430d..e5a88c2c21 100644 --- a/packages/flutter/test/material/text_theme_test.dart +++ b/packages/flutter/test/material/text_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_test/flutter_test.dart'; @@ -52,7 +50,7 @@ void main() { test('TextTheme merges properly in the presence of null fields.', () { const TextTheme partialTheme = TextTheme(headline6: TextStyle(color: Color(0xcafefeed))); final TextTheme fullTheme = ThemeData.fallback().textTheme.merge(partialTheme); - expect(fullTheme.headline6.color, equals(partialTheme.headline6.color)); + expect(fullTheme.headline6!.color, equals(partialTheme.headline6!.color)); const TextTheme onlyHeadlineAndTitle = TextTheme( headline5: TextStyle(color: Color(0xcafefeed)), @@ -64,9 +62,9 @@ void main() { ); TextTheme merged = onlyHeadlineAndTitle.merge(onlyBody1AndTitle); expect(merged.bodyText1, isNull); - expect(merged.bodyText2.color, equals(onlyBody1AndTitle.bodyText2.color)); - expect(merged.headline5.color, equals(onlyHeadlineAndTitle.headline5.color)); - expect(merged.headline6.color, equals(onlyBody1AndTitle.headline6.color)); + expect(merged.bodyText2!.color, equals(onlyBody1AndTitle.bodyText2!.color)); + expect(merged.headline5!.color, equals(onlyHeadlineAndTitle.headline5!.color)); + expect(merged.headline6!.color, equals(onlyBody1AndTitle.headline6!.color)); merged = onlyHeadlineAndTitle.merge(null); expect(merged, equals(onlyHeadlineAndTitle)); @@ -96,34 +94,34 @@ void main() { decorationStyle: decorationStyle, ); - expect(theme.headline1.color, displayColor); - expect(theme.headline2.color, displayColor); - expect(theme.headline3.color, displayColor); - expect(theme.headline4.color, displayColor); - expect(theme.caption.color, displayColor); - expect(theme.headline5.color, bodyColor); - expect(theme.headline6.color, bodyColor); - expect(theme.subtitle1.color, bodyColor); - expect(theme.bodyText1.color, bodyColor); - expect(theme.bodyText2.color, bodyColor); - expect(theme.button.color, bodyColor); - expect(theme.subtitle2.color, bodyColor); - expect(theme.overline.color, bodyColor); + expect(theme.headline1!.color, displayColor); + expect(theme.headline2!.color, displayColor); + expect(theme.headline3!.color, displayColor); + expect(theme.headline4!.color, displayColor); + expect(theme.caption!.color, displayColor); + expect(theme.headline5!.color, bodyColor); + expect(theme.headline6!.color, bodyColor); + expect(theme.subtitle1!.color, bodyColor); + expect(theme.bodyText1!.color, bodyColor); + expect(theme.bodyText2!.color, bodyColor); + expect(theme.button!.color, bodyColor); + expect(theme.subtitle2!.color, bodyColor); + expect(theme.overline!.color, bodyColor); final List themeStyles = [ - theme.headline1, - theme.headline2, - theme.headline3, - theme.headline4, - theme.caption, - theme.headline5, - theme.headline6, - theme.subtitle1, - theme.bodyText1, - theme.bodyText2, - theme.button, - theme.subtitle2, - theme.overline, + theme.headline1!, + theme.headline2!, + theme.headline3!, + theme.headline4!, + theme.caption!, + theme.headline5!, + theme.headline6!, + theme.subtitle1!, + theme.bodyText1!, + theme.bodyText2!, + theme.button!, + theme.subtitle2!, + theme.overline!, ]; expect(themeStyles.every((TextStyle style) => style.fontFamily == fontFamily), true); expect(themeStyles.every((TextStyle style) => style.decorationColor == decorationColor), true); @@ -139,19 +137,19 @@ void main() { fontSizeDelta: 5.0, ); - expect(sizeTheme.headline1.fontSize, baseTheme.headline1.fontSize * 2.0 + 5.0); - expect(sizeTheme.headline2.fontSize, baseTheme.headline2.fontSize * 2.0 + 5.0); - expect(sizeTheme.headline3.fontSize, baseTheme.headline3.fontSize * 2.0 + 5.0); - expect(sizeTheme.headline4.fontSize, baseTheme.headline4.fontSize * 2.0 + 5.0); - expect(sizeTheme.caption.fontSize, baseTheme.caption.fontSize * 2.0 + 5.0); - expect(sizeTheme.headline5.fontSize, baseTheme.headline5.fontSize * 2.0 + 5.0); - expect(sizeTheme.headline6.fontSize, baseTheme.headline6.fontSize * 2.0 + 5.0); - expect(sizeTheme.subtitle1.fontSize, baseTheme.subtitle1.fontSize * 2.0 + 5.0); - expect(sizeTheme.bodyText1.fontSize, baseTheme.bodyText1.fontSize * 2.0 + 5.0); - expect(sizeTheme.bodyText2.fontSize, baseTheme.bodyText2.fontSize * 2.0 + 5.0); - expect(sizeTheme.button.fontSize, baseTheme.button.fontSize * 2.0 + 5.0); - expect(sizeTheme.subtitle2.fontSize, baseTheme.subtitle2.fontSize * 2.0 + 5.0); - expect(sizeTheme.overline.fontSize, baseTheme.overline.fontSize * 2.0 + 5.0); + expect(sizeTheme.headline1!.fontSize, baseTheme.headline1!.fontSize! * 2.0 + 5.0); + expect(sizeTheme.headline2!.fontSize, baseTheme.headline2!.fontSize! * 2.0 + 5.0); + expect(sizeTheme.headline3!.fontSize, baseTheme.headline3!.fontSize! * 2.0 + 5.0); + expect(sizeTheme.headline4!.fontSize, baseTheme.headline4!.fontSize! * 2.0 + 5.0); + expect(sizeTheme.caption!.fontSize, baseTheme.caption!.fontSize! * 2.0 + 5.0); + expect(sizeTheme.headline5!.fontSize, baseTheme.headline5!.fontSize! * 2.0 + 5.0); + expect(sizeTheme.headline6!.fontSize, baseTheme.headline6!.fontSize! * 2.0 + 5.0); + expect(sizeTheme.subtitle1!.fontSize, baseTheme.subtitle1!.fontSize! * 2.0 + 5.0); + expect(sizeTheme.bodyText1!.fontSize, baseTheme.bodyText1!.fontSize! * 2.0 + 5.0); + expect(sizeTheme.bodyText2!.fontSize, baseTheme.bodyText2!.fontSize! * 2.0 + 5.0); + expect(sizeTheme.button!.fontSize, baseTheme.button!.fontSize! * 2.0 + 5.0); + expect(sizeTheme.subtitle2!.fontSize, baseTheme.subtitle2!.fontSize! * 2.0 + 5.0); + expect(sizeTheme.overline!.fontSize, baseTheme.overline!.fontSize! * 2.0 + 5.0); }); test('TextTheme lerp with second parameter null', () { diff --git a/packages/flutter/test/material/theme_data_test.dart b/packages/flutter/test/material/theme_data_test.dart index b77bdf4ba3..776d447636 100644 --- a/packages/flutter/test/material/theme_data_test.dart +++ b/packages/flutter/test/material/theme_data_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'; @@ -37,8 +35,8 @@ void main() { final ThemeData darkTheme = ThemeData(brightness: Brightness.dark); final Typography typography = Typography.material2018(platform: lightTheme.platform); - expect(lightTheme.textTheme.headline6.color, typography.black.headline6.color); - expect(darkTheme.textTheme.headline6.color, typography.white.headline6.color); + expect(lightTheme.textTheme.headline6!.color, typography.black.headline6!.color); + expect(darkTheme.textTheme.headline6!.color, typography.white.headline6!.color); }); test('Default primary text theme contrasts with primary brightness', () { @@ -46,8 +44,8 @@ void main() { final ThemeData darkTheme = ThemeData(primaryColorBrightness: Brightness.dark); final Typography typography = Typography.material2018(platform: lightTheme.platform); - expect(lightTheme.primaryTextTheme.headline6.color, typography.black.headline6.color); - expect(darkTheme.primaryTextTheme.headline6.color, typography.white.headline6.color); + expect(lightTheme.primaryTextTheme.headline6!.color, typography.black.headline6!.color); + expect(darkTheme.primaryTextTheme.headline6!.color, typography.white.headline6!.color); }); test('Default accent text theme contrasts with accent brightness', () { @@ -55,8 +53,8 @@ void main() { final ThemeData darkTheme = ThemeData(accentColorBrightness: Brightness.dark); final Typography typography = Typography.material2018(platform: lightTheme.platform); - expect(lightTheme.accentTextTheme.headline6.color, typography.black.headline6.color); - expect(darkTheme.accentTextTheme.headline6.color, typography.white.headline6.color); + expect(lightTheme.accentTextTheme.headline6!.color, typography.black.headline6!.color); + expect(darkTheme.accentTextTheme.headline6!.color, typography.white.headline6!.color); }); test('Default chip label style gets a default bodyText1 if textTheme.bodyText1 is null', () { @@ -65,8 +63,8 @@ void main() { final ThemeData darkTheme = ThemeData(brightness: Brightness.dark, textTheme: noBodyText1TextTheme); final Typography typography = Typography.material2018(platform: lightTheme.platform); - expect(lightTheme.chipTheme.labelStyle.color, equals(typography.black.bodyText1.color.withAlpha(0xde))); - expect(darkTheme.chipTheme.labelStyle.color, equals(typography.white.bodyText1.color.withAlpha(0xde))); + expect(lightTheme.chipTheme.labelStyle.color, equals(typography.black.bodyText1!.color!.withAlpha(0xde))); + expect(darkTheme.chipTheme.labelStyle.color, equals(typography.white.bodyText1!.color!.withAlpha(0xde))); }); test('Default icon theme contrasts with brightness', () { @@ -74,8 +72,8 @@ void main() { final ThemeData darkTheme = ThemeData(brightness: Brightness.dark); final Typography typography = Typography.material2018(platform: lightTheme.platform); - expect(lightTheme.textTheme.headline6.color, typography.black.headline6.color); - expect(darkTheme.textTheme.headline6.color, typography.white.headline6.color); + expect(lightTheme.textTheme.headline6!.color, typography.black.headline6!.color); + expect(darkTheme.textTheme.headline6!.color, typography.white.headline6!.color); }); test('Default primary icon theme contrasts with primary brightness', () { @@ -83,8 +81,8 @@ void main() { final ThemeData darkTheme = ThemeData(primaryColorBrightness: Brightness.dark); final Typography typography = Typography.material2018(platform: lightTheme.platform); - expect(lightTheme.primaryTextTheme.headline6.color, typography.black.headline6.color); - expect(darkTheme.primaryTextTheme.headline6.color, typography.white.headline6.color); + expect(lightTheme.primaryTextTheme.headline6!.color, typography.black.headline6!.color); + expect(darkTheme.primaryTextTheme.headline6!.color, typography.white.headline6!.color); }); test('Default accent icon theme contrasts with accent brightness', () { @@ -92,8 +90,8 @@ void main() { final ThemeData darkTheme = ThemeData(accentColorBrightness: Brightness.dark); final Typography typography = Typography.material2018(platform: lightTheme.platform); - expect(lightTheme.accentTextTheme.headline6.color, typography.black.headline6.color); - expect(darkTheme.accentTextTheme.headline6.color, typography.white.headline6.color); + expect(lightTheme.accentTextTheme.headline6!.color, typography.black.headline6!.color); + expect(darkTheme.accentTextTheme.headline6!.color, typography.white.headline6!.color); }); testWidgets('Defaults to MaterialTapTargetBehavior.padded on mobile platforms and MaterialTapTargetBehavior.shrinkWrap on desktop', (WidgetTester tester) async { @@ -120,12 +118,12 @@ void main() { ), ); - expect(themeData.textTheme.bodyText1.fontFamily, equals('Ahem')); - expect(themeData.primaryTextTheme.headline3.fontFamily, equals('Ahem')); - expect(themeData.accentTextTheme.headline1.fontFamily, equals('Ahem')); + expect(themeData.textTheme.bodyText1!.fontFamily, equals('Ahem')); + expect(themeData.primaryTextTheme.headline3!.fontFamily, equals('Ahem')); + expect(themeData.accentTextTheme.headline1!.fontFamily, equals('Ahem')); // Shouldn't override the specified style's family - expect(themeData.textTheme.headline6.fontFamily, equals('Roboto')); + expect(themeData.textTheme.headline6!.fontFamily, equals('Roboto')); }); test('Can estimate brightness - directly', () { @@ -192,7 +190,7 @@ void main() { }); testWidgets('VisualDensity.adaptivePlatformDensity returns adaptive values', (WidgetTester tester) async { - switch (debugDefaultTargetPlatformOverride) { + switch (debugDefaultTargetPlatformOverride!) { case TargetPlatform.android: case TargetPlatform.iOS: case TargetPlatform.fuchsia: @@ -207,7 +205,7 @@ void main() { testWidgets('VisualDensity in ThemeData defaults to "compact" on desktop and "standard" on mobile', (WidgetTester tester) async { final ThemeData themeData = ThemeData(); - switch (debugDefaultTargetPlatformOverride) { + switch (debugDefaultTargetPlatformOverride!) { case TargetPlatform.android: case TargetPlatform.iOS: case TargetPlatform.fuchsia: diff --git a/packages/flutter/test/material/theme_defaults_test.dart b/packages/flutter/test/material/theme_defaults_test.dart index ffb5d1c5d5..0b2004c0b6 100644 --- a/packages/flutter/test/material/theme_defaults_test.dart +++ b/packages/flutter/test/material/theme_defaults_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'; @@ -28,7 +26,7 @@ void main() { ); final RawMaterialButton raw = tester.widget(find.byType(RawMaterialButton)); - expect(raw.textStyle.color, const Color(0xdd000000)); + expect(raw.textStyle!.color, const Color(0xdd000000)); expect(raw.fillColor, const Color(0xffe0e0e0)); expect(raw.highlightColor, const Color(0x29000000)); // Was Color(0x66bcbcbc) expect(raw.splashColor, const Color(0x1f000000)); // Was Color(0x66c8c8c8) @@ -56,7 +54,7 @@ void main() { ); final RawMaterialButton raw = tester.widget(find.byType(RawMaterialButton)); - expect(raw.textStyle.color, const Color(0x61000000)); + expect(raw.textStyle!.color, const Color(0x61000000)); expect(raw.fillColor, const Color(0x61000000)); // highlightColor, disabled button can't be pressed // splashColor, disabled button doesn't splash @@ -86,7 +84,7 @@ void main() { ); final RawMaterialButton raw = tester.widget(find.byType(RawMaterialButton)); - expect(raw.textStyle.color, const Color(0xdd000000)); + expect(raw.textStyle!.color, const Color(0xdd000000)); expect(raw.fillColor, null); expect(raw.highlightColor, const Color(0x29000000)); // Was Color(0x66bcbcbc) expect(raw.splashColor, const Color(0x1f000000)); // Was Color(0x66c8c8c8) @@ -114,7 +112,7 @@ void main() { ); final RawMaterialButton raw = tester.widget(find.byType(RawMaterialButton)); - expect(raw.textStyle.color, const Color(0x61000000)); + expect(raw.textStyle!.color, const Color(0x61000000)); expect(raw.fillColor, null); // highlightColor, disabled button can't be pressed // splashColor, disabled button doesn't splash @@ -148,7 +146,7 @@ void main() { ); final RawMaterialButton raw = tester.widget(find.byType(RawMaterialButton)); - expect(raw.textStyle.color, const Color(0xdd000000)); + expect(raw.textStyle!.color, const Color(0xdd000000)); expect(raw.fillColor, const Color(0x00fafafa)); expect(raw.highlightColor, const Color(0x29000000)); // Was Color(0x66bcbcbc) expect(raw.splashColor, const Color(0x1f000000)); // Was Color(0x66c8c8c8) @@ -175,7 +173,7 @@ void main() { ); final RawMaterialButton raw = tester.widget(find.byType(RawMaterialButton)); - expect(raw.textStyle.color, const Color(0xdd000000)); + expect(raw.textStyle!.color, const Color(0xdd000000)); expect(raw.fillColor, Colors.transparent); expect(raw.highlightColor, const Color(0x29000000)); // Was Color(0x66bcbcbc) expect(raw.splashColor, const Color(0x1f000000)); // Was Color(0x66c8c8c8) @@ -202,7 +200,7 @@ void main() { ); final RawMaterialButton raw = tester.widget(find.byType(RawMaterialButton)); - expect(raw.textStyle.color, const Color(0x61000000)); + expect(raw.textStyle!.color, const Color(0x61000000)); expect(raw.fillColor, const Color(0x00000000)); // highlightColor, disabled button can't be pressed // splashColor, disabled button doesn't splash @@ -236,7 +234,7 @@ void main() { final RawMaterialButton raw = tester.widget(find.byType(RawMaterialButton)); expect(raw.enabled, true); - expect(raw.textStyle.color, const Color(0xffffffff)); + expect(raw.textStyle!.color, const Color(0xffffffff)); expect(raw.fillColor, const Color(0xff2196f3)); expect(raw.elevation, 6.0); expect(raw.highlightElevation, 12.0); @@ -263,7 +261,7 @@ void main() { final RawMaterialButton raw = tester.widget(find.byType(RawMaterialButton)); expect(raw.enabled, false); - expect(raw.textStyle.color, const Color(0xffffffff)); + expect(raw.textStyle!.color, const Color(0xffffffff)); expect(raw.fillColor, const Color(0xff2196f3)); // highlightColor, disabled button can't be pressed // splashColor, disabled button doesn't splash diff --git a/packages/flutter/test/material/theme_test.dart b/packages/flutter/test/material/theme_test.dart index 275125a75f..2d948dcb4f 100644 --- a/packages/flutter/test/material/theme_test.dart +++ b/packages/flutter/test/material/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' as ui; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -46,11 +44,11 @@ void main() { await tester.tap(find.byKey(popupMenuButtonKey)); await tester.pump(const Duration(seconds: 1)); - expect(Theme.of(tester.element(find.text('menuItem'))).brightness, equals(Brightness.dark)); + expect(Theme.of(tester.element(find.text('menuItem')))!.brightness, equals(Brightness.dark)); }); testWidgets('Fallback theme', (WidgetTester tester) async { - BuildContext capturedContext; + late BuildContext capturedContext; await tester.pumpWidget( Builder( builder: (BuildContext context) { @@ -116,7 +114,7 @@ void main() { await tester.tap(find.byKey(popupMenuButtonKey)); await tester.pump(const Duration(seconds: 1)); - expect(Theme.of(tester.element(find.text('menuItem'))).brightness, equals(Brightness.light)); + expect(Theme.of(tester.element(find.text('menuItem')))!.brightness, equals(Brightness.light)); }); testWidgets('DropdownMenu inherits shadowed app theme', (WidgetTester tester) async { @@ -131,7 +129,7 @@ void main() { actions: [ DropdownButton( key: dropdownMenuButtonKey, - onChanged: (String newValue) { }, + onChanged: (String? newValue) { }, value: 'menuItem', items: const >[ DropdownMenuItem( @@ -151,7 +149,7 @@ void main() { await tester.pump(const Duration(seconds: 1)); for (final Element item in tester.elementList(find.text('menuItem'))) - expect(Theme.of(item).brightness, equals(Brightness.light)); + expect(Theme.of(item)!.brightness, equals(Brightness.light)); }); testWidgets('ModalBottomSheet inherits shadowed app theme', (WidgetTester tester) async { @@ -183,7 +181,7 @@ void main() { await tester.tap(find.text('SHOW')); await tester.pump(const Duration(seconds: 1)); - expect(Theme.of(tester.element(find.text('bottomSheet'))).brightness, equals(Brightness.light)); + expect(Theme.of(tester.element(find.text('bottomSheet')))!.brightness, equals(Brightness.light)); await tester.tap(find.text('bottomSheet')); // dismiss the bottom sheet await tester.pump(const Duration(seconds: 1)); @@ -220,7 +218,7 @@ void main() { await tester.tap(find.text('SHOW')); await tester.pump(const Duration(seconds: 1)); - expect(Theme.of(tester.element(find.text('dialog'))).brightness, equals(Brightness.light)); + expect(Theme.of(tester.element(find.text('dialog')))!.brightness, equals(Brightness.light)); }); testWidgets("Scaffold inherits theme's scaffoldBackgroundColor", (WidgetTester tester) async { @@ -275,8 +273,8 @@ void main() { RenderParagraph glyphText = tester.renderObject(find.byType(RichText)); - expect(glyphText.text.style.color, Colors.green); - expect(glyphText.text.style.fontSize, 10.0); + expect(glyphText.text.style!.color, Colors.green); + expect(glyphText.text.style!.fontSize, 10.0); await tester.pumpWidget( MaterialApp( @@ -288,14 +286,14 @@ void main() { glyphText = tester.renderObject(find.byType(RichText)); - expect(glyphText.text.style.color, Color.lerp(Colors.green, Colors.orange, 0.5)); - expect(glyphText.text.style.fontSize, 15.0); + expect(glyphText.text.style!.color, Color.lerp(Colors.green, Colors.orange, 0.5)); + expect(glyphText.text.style!.fontSize, 15.0); await tester.pump(const Duration(milliseconds: 100)); // Finish the transition glyphText = tester.renderObject(find.byType(RichText)); - expect(glyphText.text.style.color, Colors.orange); - expect(glyphText.text.style.fontSize, 20.0); + expect(glyphText.text.style!.color, Colors.orange); + expect(glyphText.text.style!.fontSize, 20.0); }); testWidgets( @@ -338,21 +336,21 @@ void main() { final ThemeData fallback = ThemeData.fallback(); final ThemeData customTheme = fallback.copyWith( primaryTextTheme: fallback.primaryTextTheme.copyWith( - bodyText2: fallback.primaryTextTheme.bodyText2.copyWith( + bodyText2: fallback.primaryTextTheme.bodyText2!.copyWith( fontSize: _kMagicFontSize, ), ), ); - expect(customTheme.primaryTextTheme.bodyText2.fontSize, _kMagicFontSize); + expect(customTheme.primaryTextTheme.bodyText2!.fontSize, _kMagicFontSize); - double actualFontSize; + late double actualFontSize; await tester.pumpWidget(Directionality( textDirection: TextDirection.ltr, child: Theme( data: customTheme, child: Builder(builder: (BuildContext context) { - final ThemeData theme = Theme.of(context); - actualFontSize = theme.primaryTextTheme.bodyText2.fontSize; + final ThemeData theme = Theme.of(context)!; + actualFontSize = theme.primaryTextTheme.bodyText2!.fontSize!; return Text( 'A', style: theme.primaryTextTheme.bodyText2, @@ -365,12 +363,12 @@ void main() { }); testWidgets('Default Theme provides all basic TextStyle properties', (WidgetTester tester) async { - ThemeData theme; + late ThemeData theme; await tester.pumpWidget(Directionality( textDirection: TextDirection.ltr, child: Builder( builder: (BuildContext context) { - theme = Theme.of(context); + theme = Theme.of(context)!; return const Text('A'); }, ), @@ -378,17 +376,17 @@ void main() { List extractStyles(TextTheme textTheme) { return [ - textTheme.headline1, - textTheme.headline2, - textTheme.headline3, - textTheme.headline4, - textTheme.headline5, - textTheme.headline6, - textTheme.subtitle1, - textTheme.bodyText1, - textTheme.bodyText2, - textTheme.caption, - textTheme.button, + textTheme.headline1!, + textTheme.headline2!, + textTheme.headline3!, + textTheme.headline4!, + textTheme.headline5!, + textTheme.headline6!, + textTheme.subtitle1!, + textTheme.bodyText1!, + textTheme.bodyText2!, + textTheme.caption!, + textTheme.button!, ]; } @@ -413,14 +411,14 @@ void main() { } } - expect(theme.textTheme.headline1.debugLabel, '(englishLike display4 2014).merge(blackMountainView headline1)'); + expect(theme.textTheme.headline1!.debugLabel, '(englishLike display4 2014).merge(blackMountainView headline1)'); }); group('Cupertino theme', () { - int buildCount; - CupertinoThemeData actualTheme; - IconThemeData actualIconTheme; - BuildContext context; + late int buildCount; + CupertinoThemeData? actualTheme; + IconThemeData? actualIconTheme; + BuildContext? context; final Widget singletonThemeSubtree = Builder( builder: (BuildContext localContext) { @@ -434,7 +432,7 @@ void main() { Future testTheme(WidgetTester tester, ThemeData theme) async { await tester.pumpWidget(Theme(data: theme, child: singletonThemeSubtree)); - return actualTheme; + return actualTheme!; } setUp(() { @@ -468,23 +466,23 @@ void main() { testWidgets('MaterialTheme overrides the brightness', (WidgetTester tester) async { await testTheme(tester, ThemeData.dark()); - expect(CupertinoTheme.brightnessOf(context), Brightness.dark); + expect(CupertinoTheme.brightnessOf(context!), Brightness.dark); await testTheme(tester, ThemeData.light()); - expect(CupertinoTheme.brightnessOf(context), Brightness.light); + expect(CupertinoTheme.brightnessOf(context!), Brightness.light); // Overridable by cupertinoOverrideTheme. await testTheme(tester, ThemeData( brightness: Brightness.light, cupertinoOverrideTheme: const CupertinoThemeData(brightness: Brightness.dark), )); - expect(CupertinoTheme.brightnessOf(context), Brightness.dark); + expect(CupertinoTheme.brightnessOf(context!), Brightness.dark); await testTheme(tester, ThemeData( brightness: Brightness.dark, cupertinoOverrideTheme: const CupertinoThemeData(brightness: Brightness.light), )); - expect(CupertinoTheme.brightnessOf(context), Brightness.light); + expect(CupertinoTheme.brightnessOf(context!), Brightness.light); }); testWidgets('Can override material theme', (WidgetTester tester) async { @@ -544,7 +542,7 @@ void main() { )); expect(buildCount, 1); - expect(actualIconTheme.color, materialIconColor); + expect(actualIconTheme!.color, materialIconColor); }); testWidgets( @@ -674,9 +672,9 @@ void main() { }); } -int testBuildCalled; +int testBuildCalled = 0; class Test extends StatefulWidget { - const Test({ Key key }) : super(key: key); + const Test({ Key? key }) : super(key: key); @override _TestState createState() => _TestState(); @@ -688,7 +686,7 @@ class _TestState extends State { testBuildCalled += 1; return Container( decoration: BoxDecoration( - color: Theme.of(context).primaryColor, + color: Theme.of(context)!.primaryColor, ), ); } @@ -704,56 +702,56 @@ class _TextStyleProxy implements TextStyle { // Do make sure that all the properties correctly forward to the _delegate. @override - Color get color => _delegate.color; + Color? get color => _delegate.color; @override - Color get backgroundColor => _delegate.backgroundColor; + Color? get backgroundColor => _delegate.backgroundColor; @override - String get debugLabel => _delegate.debugLabel; + String? get debugLabel => _delegate.debugLabel; @override - TextDecoration get decoration => _delegate.decoration; + TextDecoration? get decoration => _delegate.decoration; @override - Color get decorationColor => _delegate.decorationColor; + Color? get decorationColor => _delegate.decorationColor; @override - TextDecorationStyle get decorationStyle => _delegate.decorationStyle; + TextDecorationStyle? get decorationStyle => _delegate.decorationStyle; @override - double get decorationThickness => _delegate.decorationThickness; + double? get decorationThickness => _delegate.decorationThickness; @override - String get fontFamily => _delegate.fontFamily; + String? get fontFamily => _delegate.fontFamily; @override - List get fontFamilyFallback => _delegate.fontFamilyFallback; + List? get fontFamilyFallback => _delegate.fontFamilyFallback; @override - double get fontSize => _delegate.fontSize; + double? get fontSize => _delegate.fontSize; @override - FontStyle get fontStyle => _delegate.fontStyle; + FontStyle? get fontStyle => _delegate.fontStyle; @override - FontWeight get fontWeight => _delegate.fontWeight; + FontWeight? get fontWeight => _delegate.fontWeight; @override - double get height => _delegate.height; + double? get height => _delegate.height; @override - Locale get locale => _delegate.locale; + Locale? get locale => _delegate.locale; @override - ui.Paint get foreground => _delegate.foreground; + ui.Paint? get foreground => _delegate.foreground; @override - ui.Paint get background => _delegate.background; + ui.Paint? get background => _delegate.background; @override bool get inherit => _delegate.inherit; @override - double get letterSpacing => _delegate.letterSpacing; + double? get letterSpacing => _delegate.letterSpacing; @override - TextBaseline get textBaseline => _delegate.textBaseline; + TextBaseline? get textBaseline => _delegate.textBaseline; @override - double get wordSpacing => _delegate.wordSpacing; + double? get wordSpacing => _delegate.wordSpacing; @override - List get shadows => _delegate.shadows; + List? get shadows => _delegate.shadows; @override - List get fontFeatures => _delegate.fontFeatures; + List? get fontFeatures => _delegate.fontFeatures; @override String toString({ DiagnosticLevel minLevel = DiagnosticLevel.info }) => super.toString(); @override - DiagnosticsNode toDiagnosticsNode({ String name, DiagnosticsTreeStyle style }) { + DiagnosticsNode toDiagnosticsNode({ String? name, DiagnosticsTreeStyle? style }) { throw UnimplementedError(); } @@ -764,29 +762,29 @@ class _TextStyleProxy implements TextStyle { @override TextStyle apply({ - Color color, - Color backgroundColor, - TextDecoration decoration, - Color decorationColor, - TextDecorationStyle decorationStyle, + Color? color, + Color? backgroundColor, + TextDecoration? decoration, + Color? decorationColor, + TextDecorationStyle? decorationStyle, double decorationThicknessFactor = 1.0, double decorationThicknessDelta = 0.0, - String fontFamily, - List fontFamilyFallback, + String? fontFamily, + List? fontFamilyFallback, double fontSizeFactor = 1.0, double fontSizeDelta = 0.0, int fontWeightDelta = 0, - FontStyle fontStyle, + FontStyle? fontStyle, double letterSpacingFactor = 1.0, double letterSpacingDelta = 0.0, double wordSpacingFactor = 1.0, double wordSpacingDelta = 0.0, double heightFactor = 1.0, double heightDelta = 0.0, - TextBaseline textBaseline, - Locale locale, - List shadows, - List fontFeatures, + TextBaseline? textBaseline, + Locale? locale, + List? shadows, + List? fontFeatures, }) { throw UnimplementedError(); } @@ -798,28 +796,28 @@ class _TextStyleProxy implements TextStyle { @override TextStyle copyWith({ - bool inherit, - Color color, - Color backgroundColor, - String fontFamily, - List fontFamilyFallback, - double fontSize, - FontWeight fontWeight, - FontStyle fontStyle, - double letterSpacing, - double wordSpacing, - TextBaseline textBaseline, - double height, - Locale locale, - ui.Paint foreground, - ui.Paint background, - List shadows, - List fontFeatures, - TextDecoration decoration, - Color decorationColor, - TextDecorationStyle decorationStyle, - double decorationThickness, - String debugLabel, + bool? inherit, + Color? color, + Color? backgroundColor, + String? fontFamily, + List? fontFamilyFallback, + double? fontSize, + FontWeight? fontWeight, + FontStyle? fontStyle, + double? letterSpacing, + double? wordSpacing, + TextBaseline? textBaseline, + double? height, + Locale? locale, + ui.Paint? foreground, + ui.Paint? background, + List? shadows, + List? fontFeatures, + TextDecoration? decoration, + Color? decorationColor, + TextDecorationStyle? decorationStyle, + double? decorationThickness, + String? debugLabel, }) { throw UnimplementedError(); } @@ -831,19 +829,19 @@ class _TextStyleProxy implements TextStyle { @override ui.ParagraphStyle getParagraphStyle({ - TextAlign textAlign, - TextDirection textDirection, + TextAlign? textAlign, + TextDirection? textDirection, double textScaleFactor = 1.0, - String ellipsis, - int maxLines, - ui.TextHeightBehavior textHeightBehavior, - Locale locale, - String fontFamily, - double fontSize, - FontWeight fontWeight, - FontStyle fontStyle, - double height, - StrutStyle strutStyle, + String? ellipsis, + int? maxLines, + ui.TextHeightBehavior? textHeightBehavior, + Locale? locale, + String? fontFamily, + double? fontSize, + FontWeight? fontWeight, + FontStyle? fontStyle, + double? height, + StrutStyle? strutStyle, }) { throw UnimplementedError(); } @@ -854,7 +852,7 @@ class _TextStyleProxy implements TextStyle { } @override - TextStyle merge(TextStyle other) { + TextStyle merge(TextStyle? other) { throw UnimplementedError(); } } diff --git a/packages/flutter/test/material/time_picker_test.dart b/packages/flutter/test/material/time_picker_test.dart index 9fb032ddde..1296104142 100644 --- a/packages/flutter/test/material/time_picker_test.dart +++ b/packages/flutter/test/material/time_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 - @TestOn('!chrome') // entire file needs triage. import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; @@ -19,14 +17,14 @@ final Finder _timePickerDialog = find.byWidgetPredicate((Widget widget) => '${wi class _TimePickerLauncher extends StatelessWidget { const _TimePickerLauncher({ - Key key, - this.onChanged, + Key? key, + required this.onChanged, this.locale, this.entryMode = TimePickerEntryMode.dial, }) : super(key: key); final ValueChanged onChanged; - final Locale locale; + final Locale? locale; final TimePickerEntryMode entryMode; @override @@ -55,7 +53,7 @@ class _TimePickerLauncher extends StatelessWidget { } } -Future startPicker( +Future startPicker( WidgetTester tester, ValueChanged onChanged, { TimePickerEntryMode entryMode = TimePickerEntryMode.dial, @@ -67,7 +65,7 @@ Future startPicker( } Future finishPicker(WidgetTester tester) async { - final MaterialLocalizations materialLocalizations = MaterialLocalizations.of(tester.element(find.byType(ElevatedButton))); + final MaterialLocalizations materialLocalizations = MaterialLocalizations.of(tester.element(find.byType(ElevatedButton)))!; await tester.tap(find.text(materialLocalizations.okButtonLabel)); await tester.pumpAndSettle(const Duration(seconds: 1)); } @@ -84,24 +82,24 @@ void main() { void _tests() { testWidgets('tap-select an hour', (WidgetTester tester) async { - TimeOfDay result; + late TimeOfDay result; - Offset center = await startPicker(tester, (TimeOfDay time) { result = time; }); + Offset center = (await startPicker(tester, (TimeOfDay time) { result = time; }))!; await tester.tapAt(Offset(center.dx, center.dy - 50.0)); // 12:00 AM await finishPicker(tester); expect(result, equals(const TimeOfDay(hour: 0, minute: 0))); - center = await startPicker(tester, (TimeOfDay time) { result = time; }); + center = (await startPicker(tester, (TimeOfDay time) { result = time; }))!; await tester.tapAt(Offset(center.dx + 50.0, center.dy)); await finishPicker(tester); expect(result, equals(const TimeOfDay(hour: 3, minute: 0))); - center = await startPicker(tester, (TimeOfDay time) { result = time; }); + center = (await startPicker(tester, (TimeOfDay time) { result = time; }))!; await tester.tapAt(Offset(center.dx, center.dy + 50.0)); await finishPicker(tester); expect(result, equals(const TimeOfDay(hour: 6, minute: 0))); - center = await startPicker(tester, (TimeOfDay time) { result = time; }); + center = (await startPicker(tester, (TimeOfDay time) { result = time; }))!; await tester.tapAt(Offset(center.dx, center.dy + 50.0)); await tester.tapAt(Offset(center.dx - 50, center.dy)); await finishPicker(tester); @@ -109,9 +107,9 @@ void _tests() { }); testWidgets('drag-select an hour', (WidgetTester tester) async { - TimeOfDay result; + late TimeOfDay result; - final Offset center = await startPicker(tester, (TimeOfDay time) { result = time; }); + final Offset center = (await startPicker(tester, (TimeOfDay time) { result = time; }))!; final Offset hour0 = Offset(center.dx, center.dy - 50.0); // 12:00 AM final Offset hour3 = Offset(center.dx + 50.0, center.dy); final Offset hour6 = Offset(center.dx, center.dy + 50.0); @@ -148,9 +146,9 @@ void _tests() { }); testWidgets('tap-select switches from hour to minute', (WidgetTester tester) async { - TimeOfDay result; + late TimeOfDay result; - final Offset center = await startPicker(tester, (TimeOfDay time) { result = time; }); + final Offset center = (await startPicker(tester, (TimeOfDay time) { result = time; }))!; final Offset hour6 = Offset(center.dx, center.dy + 50.0); // 6:00 final Offset min45 = Offset(center.dx - 50.0, center.dy); // 45 mins (or 9:00 hours) @@ -162,9 +160,9 @@ void _tests() { }); testWidgets('drag-select switches from hour to minute', (WidgetTester tester) async { - TimeOfDay result; + late TimeOfDay result; - final Offset center = await startPicker(tester, (TimeOfDay time) { result = time; }); + final Offset center = (await startPicker(tester, (TimeOfDay time) { result = time; }))!; final Offset hour3 = Offset(center.dx + 50.0, center.dy); final Offset hour6 = Offset(center.dx, center.dy + 50.0); final Offset hour9 = Offset(center.dx - 50.0, center.dy); @@ -181,9 +179,9 @@ void _tests() { }); testWidgets('tap-select rounds down to nearest 5 minute increment', (WidgetTester tester) async { - TimeOfDay result; + late TimeOfDay result; - final Offset center = await startPicker(tester, (TimeOfDay time) { result = time; }); + final Offset center = (await startPicker(tester, (TimeOfDay time) { result = time; }))!; final Offset hour6 = Offset(center.dx, center.dy + 50.0); // 6:00 final Offset min46 = Offset(center.dx - 50.0, center.dy - 5); // 46 mins @@ -195,9 +193,9 @@ void _tests() { }); testWidgets('tap-select rounds up to nearest 5 minute increment', (WidgetTester tester) async { - TimeOfDay result; + late TimeOfDay result; - final Offset center = await startPicker(tester, (TimeOfDay time) { result = time; }); + final Offset center = (await startPicker(tester, (TimeOfDay time) { result = time; }))!; final Offset hour6 = Offset(center.dx, center.dy + 50.0); // 6:00 final Offset min48 = Offset(center.dx - 50.0, center.dy - 15); // 48 mins @@ -211,25 +209,25 @@ void _tests() { group('haptic feedback', () { const Duration kFastFeedbackInterval = Duration(milliseconds: 10); const Duration kSlowFeedbackInterval = Duration(milliseconds: 200); - FeedbackTester feedback; + late FeedbackTester feedback; setUp(() { feedback = FeedbackTester(); }); tearDown(() { - feedback?.dispose(); + feedback.dispose(); }); testWidgets('tap-select vibrates once', (WidgetTester tester) async { - final Offset center = await startPicker(tester, (TimeOfDay time) { }); + final Offset center = (await startPicker(tester, (TimeOfDay time) { }))!; await tester.tapAt(Offset(center.dx, center.dy - 50.0)); await finishPicker(tester); expect(feedback.hapticCount, 1); }); testWidgets('quick successive tap-selects vibrate once', (WidgetTester tester) async { - final Offset center = await startPicker(tester, (TimeOfDay time) { }); + final Offset center = (await startPicker(tester, (TimeOfDay time) { }))!; await tester.tapAt(Offset(center.dx, center.dy - 50.0)); await tester.pump(kFastFeedbackInterval); await tester.tapAt(Offset(center.dx, center.dy + 50.0)); @@ -238,7 +236,7 @@ void _tests() { }); testWidgets('slow successive tap-selects vibrate once per tap', (WidgetTester tester) async { - final Offset center = await startPicker(tester, (TimeOfDay time) { }); + final Offset center = (await startPicker(tester, (TimeOfDay time) { }))!; await tester.tapAt(Offset(center.dx, center.dy - 50.0)); await tester.pump(kSlowFeedbackInterval); await tester.tapAt(Offset(center.dx, center.dy + 50.0)); @@ -249,7 +247,7 @@ void _tests() { }); testWidgets('drag-select vibrates once', (WidgetTester tester) async { - final Offset center = await startPicker(tester, (TimeOfDay time) { }); + final Offset center = (await startPicker(tester, (TimeOfDay time) { }))!; final Offset hour0 = Offset(center.dx, center.dy - 50.0); final Offset hour3 = Offset(center.dx + 50.0, center.dy); @@ -261,7 +259,7 @@ void _tests() { }); testWidgets('quick drag-select vibrates once', (WidgetTester tester) async { - final Offset center = await startPicker(tester, (TimeOfDay time) { }); + final Offset center = (await startPicker(tester, (TimeOfDay time) { }))!; final Offset hour0 = Offset(center.dx, center.dy - 50.0); final Offset hour3 = Offset(center.dx + 50.0, center.dy); @@ -277,7 +275,7 @@ void _tests() { }); testWidgets('slow drag-select vibrates once', (WidgetTester tester) async { - final Offset center = await startPicker(tester, (TimeOfDay time) { }); + final Offset center = (await startPicker(tester, (TimeOfDay time) { }))!; final Offset hour0 = Offset(center.dx, center.dy - 50.0); final Offset hour3 = Offset(center.dx + 50.0, center.dy); @@ -403,12 +401,12 @@ void _tests() { testWidgets('can increment and decrement hours', (WidgetTester tester) async { final SemanticsTester semantics = SemanticsTester(tester); - Future actAndExpect({ String initialValue, SemanticsAction action, String finalValue }) async { + Future actAndExpect({ required String initialValue, required SemanticsAction action, required String finalValue }) async { final SemanticsNode elevenHours = semantics.nodesWith( value: 'Select hours $initialValue', ancestor: tester.renderObject(_hourControl).debugSemantics, ).single; - tester.binding.pipelineOwner.semanticsOwner.performAction(elevenHours.id, action); + tester.binding.pipelineOwner.semanticsOwner!.performAction(elevenHours.id, action); await tester.pumpAndSettle(); expect( find.descendant(of: _hourControl, matching: find.text(finalValue)), @@ -430,7 +428,7 @@ void _tests() { ); // Ensure we preserve day period as we roll over. - final dynamic pickerState = tester.state(_timePickerDialog); + final dynamic pickerState = tester.state(_timePickerDialog); // ignore: unnecessary_nullable_for_final_variable_declarations expect(pickerState.selectedTime, const TimeOfDay(hour: 1, minute: 0)); await actAndExpect( @@ -469,12 +467,12 @@ void _tests() { testWidgets('can increment and decrement minutes', (WidgetTester tester) async { final SemanticsTester semantics = SemanticsTester(tester); - Future actAndExpect({ String initialValue, SemanticsAction action, String finalValue }) async { + Future actAndExpect({ required String initialValue, required SemanticsAction action, required String finalValue }) async { final SemanticsNode elevenHours = semantics.nodesWith( value: 'Select minutes $initialValue', ancestor: tester.renderObject(_minuteControl).debugSemantics, ).single; - tester.binding.pipelineOwner.semanticsOwner.performAction(elevenHours.id, action); + tester.binding.pipelineOwner.semanticsOwner!.performAction(elevenHours.id, action); await tester.pumpAndSettle(); expect( find.descendant(of: _minuteControl, matching: find.text(finalValue)), @@ -495,7 +493,7 @@ void _tests() { ); // Ensure we preserve hour period as we roll over. - final dynamic pickerState = tester.state(_timePickerDialog); + final dynamic pickerState = tester.state(_timePickerDialog); // ignore: unnecessary_nullable_for_final_variable_declarations expect(pickerState.selectedTime, const TimeOfDay(hour: 11, minute: 0)); await actAndExpect( @@ -554,10 +552,10 @@ void _tests() { showTimePicker( context: context, initialTime: const TimeOfDay(hour: 7, minute: 0), - builder: (BuildContext context, Widget child) { + builder: (BuildContext context, Widget? child) { return Directionality( textDirection: textDirection, - child: child, + child: child!, ); }, ); @@ -705,10 +703,10 @@ void _tests() { showTimePicker( context: context, initialTime: const TimeOfDay(hour: 7, minute: 0), - builder: (BuildContext context, Widget child) { + builder: (BuildContext context, Widget? child) { return Directionality( textDirection: textDirection, - child: child, + child: child!, ); }, ); @@ -795,7 +793,7 @@ void _testsInput() { }); testWidgets('Initial time is the default', (WidgetTester tester) async { - TimeOfDay result; + late TimeOfDay result; await startPicker(tester, (TimeOfDay time) { result = time; }, entryMode: TimePickerEntryMode.input); await finishPicker(tester); expect(result, equals(const TimeOfDay(hour: 7, minute: 0))); @@ -899,7 +897,7 @@ void _testsInput() { }); testWidgets('Entered text returns time', (WidgetTester tester) async { - TimeOfDay result; + late TimeOfDay result; await startPicker(tester, (TimeOfDay time) { result = time; }, entryMode: TimePickerEntryMode.input); await tester.enterText(find.byType(TextField).first, '9'); await tester.enterText(find.byType(TextField).last, '12'); @@ -908,7 +906,7 @@ void _testsInput() { }); testWidgets('Toggle to dial mode keeps selected time', (WidgetTester tester) async { - TimeOfDay result; + late TimeOfDay result; await startPicker(tester, (TimeOfDay time) { result = time; }, entryMode: TimePickerEntryMode.input); await tester.enterText(find.byType(TextField).first, '8'); await tester.enterText(find.byType(TextField).last, '15'); @@ -918,7 +916,7 @@ void _testsInput() { }); testWidgets('Invalid text prevents dismissing', (WidgetTester tester) async { - TimeOfDay result; + TimeOfDay? result; await startPicker(tester, (TimeOfDay time) { result = time; }, entryMode: TimePickerEntryMode.input); // Invalid hour. @@ -959,7 +957,7 @@ class PickerObserver extends NavigatorObserver { int pickerCount = 0; @override - void didPush(Route route, Route previousRoute) { + void didPush(Route route, Route? previousRoute) { if (route.toString().contains('_DialogRoute')) { pickerCount++; } @@ -973,7 +971,7 @@ Future mediaQueryBoilerplate( TimeOfDay initialTime = const TimeOfDay(hour: 7, minute: 0), double textScaleFactor = 1.0, TimePickerEntryMode entryMode = TimePickerEntryMode.dial, - String helpText, + String? helpText, bool accessibleNavigation = false, }) async { await tester.pumpWidget( diff --git a/packages/flutter/test/material/time_picker_theme_test.dart b/packages/flutter/test/material/time_picker_theme_test.dart index abca346af0..a4243e8bdc 100644 --- a/packages/flutter/test/material/time_picker_theme_test.dart +++ b/packages/flutter/test/material/time_picker_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/painting.dart'; import 'package:flutter/rendering.dart'; @@ -117,7 +115,7 @@ void main() { final RenderParagraph hourText = _textRenderParagraph(tester, '7'); expect( hourText.text.style, - Typography.material2014().englishLike.headline2 + Typography.material2014().englishLike.headline2! .merge(Typography.material2014().black.headline2) .copyWith(color: defaultTheme.colorScheme.primary), ); @@ -125,7 +123,7 @@ void main() { final RenderParagraph minuteText = _textRenderParagraph(tester, '15'); expect( minuteText.text.style, - Typography.material2014().englishLike.headline2 + Typography.material2014().englishLike.headline2! .merge(Typography.material2014().black.headline2) .copyWith(color: defaultTheme.colorScheme.onSurface), ); @@ -133,7 +131,7 @@ void main() { final RenderParagraph amText = _textRenderParagraph(tester, 'AM'); expect( amText.text.style, - Typography.material2014().englishLike.subtitle1 + Typography.material2014().englishLike.subtitle1! .merge(Typography.material2014().black.subtitle1) .copyWith(color: defaultTheme.colorScheme.primary), ); @@ -141,7 +139,7 @@ void main() { final RenderParagraph pmText = _textRenderParagraph(tester, 'PM'); expect( pmText.text.style, - Typography.material2014().englishLike.subtitle1 + Typography.material2014().englishLike.subtitle1! .merge(Typography.material2014().black.subtitle1) .copyWith(color: defaultTheme.colorScheme.onSurface.withOpacity(0.6)), ); @@ -149,7 +147,7 @@ void main() { final RenderParagraph helperText = _textRenderParagraph(tester, 'SELECT TIME'); expect( helperText.text.style, - Typography.material2014().englishLike.overline + Typography.material2014().englishLike.overline! .merge(Typography.material2014().black.overline), ); @@ -158,14 +156,14 @@ void main() { final List primaryLabels = dialPainter.primaryLabels as List; expect( primaryLabels.first.painter.text.style, - Typography.material2014().englishLike.bodyText1 + Typography.material2014().englishLike.bodyText1! .merge(Typography.material2014().black.bodyText1) .copyWith(color: defaultTheme.colorScheme.onSurface), ); final List secondaryLabels = dialPainter.secondaryLabels as List; expect( secondaryLabels.first.painter.text.style, - Typography.material2014().englishLike.bodyText1 + Typography.material2014().englishLike.bodyText1! .merge(Typography.material2014().white.bodyText1) .copyWith(color: defaultTheme.colorScheme.onPrimary), ); @@ -217,7 +215,7 @@ void main() { await tester.tap(find.text('X')); await tester.pumpAndSettle(const Duration(seconds: 1)); - final InputDecoration hourDecoration = _textField(tester, '7').decoration; + final InputDecoration hourDecoration = _textField(tester, '7').decoration!; expect(hourDecoration.filled, true); expect(hourDecoration.fillColor, defaultTheme.colorScheme.onSurface.withOpacity(0.12)); expect(hourDecoration.enabledBorder, const OutlineInputBorder(borderSide: BorderSide(color: Colors.transparent))); @@ -226,8 +224,8 @@ void main() { expect(hourDecoration.focusedErrorBorder, OutlineInputBorder(borderSide: BorderSide(color: defaultTheme.colorScheme.error, width: 2))); expect( hourDecoration.hintStyle, - Typography.material2014().englishLike.headline2 - .merge(defaultTheme.textTheme.headline2.copyWith(color: defaultTheme.colorScheme.onSurface.withOpacity(0.36))), + Typography.material2014().englishLike.headline2! + .merge(defaultTheme.textTheme.headline2!.copyWith(color: defaultTheme.colorScheme.onSurface.withOpacity(0.36))), ); }); @@ -246,14 +244,14 @@ void main() { expect( dial, paints - ..circle(color: Color(timePickerTheme.dialBackgroundColor.value)) // Dial background color. - ..circle(color: Color(timePickerTheme.dialHandColor.value)), // Dial hand color. + ..circle(color: Color(timePickerTheme.dialBackgroundColor!.value)) // Dial background color. + ..circle(color: Color(timePickerTheme.dialHandColor!.value)), // Dial hand color. ); final RenderParagraph hourText = _textRenderParagraph(tester, '7'); expect( hourText.text.style, - Typography.material2014().englishLike.bodyText2 + Typography.material2014().englishLike.bodyText2! .merge(Typography.material2014().black.bodyText2) .merge(timePickerTheme.hourMinuteTextStyle) .copyWith(color: _selectedColor), @@ -262,7 +260,7 @@ void main() { final RenderParagraph minuteText = _textRenderParagraph(tester, '15'); expect( minuteText.text.style, - Typography.material2014().englishLike.bodyText2 + Typography.material2014().englishLike.bodyText2! .merge(Typography.material2014().black.bodyText2) .merge(timePickerTheme.hourMinuteTextStyle) .copyWith(color: _unselectedColor), @@ -271,7 +269,7 @@ void main() { final RenderParagraph amText = _textRenderParagraph(tester, 'AM'); expect( amText.text.style, - Typography.material2014().englishLike.subtitle1 + Typography.material2014().englishLike.subtitle1! .merge(Typography.material2014().black.subtitle1) .merge(timePickerTheme.dayPeriodTextStyle) .copyWith(color: _selectedColor), @@ -280,7 +278,7 @@ void main() { final RenderParagraph pmText = _textRenderParagraph(tester, 'PM'); expect( pmText.text.style, - Typography.material2014().englishLike.subtitle1 + Typography.material2014().englishLike.subtitle1! .merge(Typography.material2014().black.subtitle1) .merge(timePickerTheme.dayPeriodTextStyle) .copyWith(color: _unselectedColor), @@ -289,7 +287,7 @@ void main() { final RenderParagraph helperText = _textRenderParagraph(tester, 'SELECT TIME'); expect( helperText.text.style, - Typography.material2014().englishLike.bodyText2 + Typography.material2014().englishLike.bodyText2! .merge(Typography.material2014().black.bodyText2) .merge(timePickerTheme.helpTextStyle), ); @@ -299,14 +297,14 @@ void main() { final List primaryLabels = dialPainter.primaryLabels as List; expect( primaryLabels.first.painter.text.style, - Typography.material2014().englishLike.bodyText1 + Typography.material2014().englishLike.bodyText1! .merge(Typography.material2014().black.bodyText1) .copyWith(color: _unselectedColor), ); final List secondaryLabels = dialPainter.secondaryLabels as List; expect( secondaryLabels.first.painter.text.style, - Typography.material2014().englishLike.bodyText1 + Typography.material2014().englishLike.bodyText1! .merge(Typography.material2014().white.bodyText1) .copyWith(color: _selectedColor), ); @@ -328,13 +326,13 @@ void main() { final Material dayPeriodMaterial = _dayPeriodMaterial(tester); expect( dayPeriodMaterial.shape, - timePickerTheme.dayPeriodShape.copyWith(side: timePickerTheme.dayPeriodBorderSide), + timePickerTheme.dayPeriodShape!.copyWith(side: timePickerTheme.dayPeriodBorderSide), ); final Container dayPeriodDivider = _dayPeriodDivider(tester); expect( dayPeriodDivider.decoration, - BoxDecoration(border: Border(left: timePickerTheme.dayPeriodBorderSide)), + BoxDecoration(border: Border(left: timePickerTheme.dayPeriodBorderSide!)), ); final IconButton entryModeIconButton = _entryModeIconButton(tester); @@ -351,14 +349,14 @@ void main() { await tester.tap(find.text('X')); await tester.pumpAndSettle(const Duration(seconds: 1)); - final InputDecoration hourDecoration = _textField(tester, '7').decoration; - expect(hourDecoration.filled, timePickerTheme.inputDecorationTheme.filled); - expect(hourDecoration.fillColor, timePickerTheme.inputDecorationTheme.fillColor); - expect(hourDecoration.enabledBorder, timePickerTheme.inputDecorationTheme.enabledBorder); - expect(hourDecoration.errorBorder, timePickerTheme.inputDecorationTheme.errorBorder); - expect(hourDecoration.focusedBorder, timePickerTheme.inputDecorationTheme.focusedBorder); - expect(hourDecoration.focusedErrorBorder, timePickerTheme.inputDecorationTheme.focusedErrorBorder); - expect(hourDecoration.hintStyle, timePickerTheme.inputDecorationTheme.hintStyle); + final InputDecoration hourDecoration = _textField(tester, '7').decoration!; + expect(hourDecoration.filled, timePickerTheme.inputDecorationTheme!.filled); + expect(hourDecoration.fillColor, timePickerTheme.inputDecorationTheme!.fillColor); + expect(hourDecoration.enabledBorder, timePickerTheme.inputDecorationTheme!.enabledBorder); + expect(hourDecoration.errorBorder, timePickerTheme.inputDecorationTheme!.errorBorder); + expect(hourDecoration.focusedBorder, timePickerTheme.inputDecorationTheme!.focusedBorder); + expect(hourDecoration.focusedErrorBorder, timePickerTheme.inputDecorationTheme!.focusedErrorBorder); + expect(hourDecoration.hintStyle, timePickerTheme.inputDecorationTheme!.hintStyle); }); testWidgets('Time picker uses values from TimePickerThemeData without InputDecorationTheme - input mode', (WidgetTester tester) async { @@ -368,13 +366,13 @@ void main() { await tester.tap(find.text('X')); await tester.pumpAndSettle(const Duration(seconds: 1)); - final InputDecoration hourDecoration = _textField(tester, '7').decoration; + final InputDecoration hourDecoration = _textField(tester, '7').decoration!; expect(hourDecoration.fillColor, timePickerTheme.hourMinuteColor); }); } -final Color _selectedColor = Colors.green[100]; -final Color _unselectedColor = Colors.green[200]; +final Color _selectedColor = Colors.green[100]!; +final Color _unselectedColor = Colors.green[200]!; TimePickerThemeData _timePickerTheme({bool includeInputDecoration = false}) { Color getColor(Set states) { @@ -412,12 +410,12 @@ TimePickerThemeData _timePickerTheme({bool includeInputDecoration = false}) { class _TimePickerLauncher extends StatelessWidget { const _TimePickerLauncher({ - Key key, + Key? key, this.themeData, this.entryMode = TimePickerEntryMode.dial, }) : super(key: key); - final ThemeData themeData; + final ThemeData? themeData; final TimePickerEntryMode entryMode; @override @@ -471,7 +469,7 @@ IconButton _entryModeIconButton(WidgetTester tester) { } RenderParagraph _textRenderParagraph(WidgetTester tester, String text) { - return tester.element(find.text(text).first).renderObject as RenderParagraph; + return tester.element(find.text(text).first).renderObject! as RenderParagraph; } final Finder findDialPaint = find.descendant( diff --git a/packages/flutter/test/material/time_test.dart b/packages/flutter/test/material/time_test.dart index 9e74ec5186..7e5ada049d 100644 --- a/packages/flutter/test/material/time_test.dart +++ b/packages/flutter/test/material/time_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'; @@ -11,7 +9,7 @@ void main() { group('TimeOfDay.format', () { testWidgets('respects alwaysUse24HourFormat option', (WidgetTester tester) async { Future pumpTest(bool alwaysUse24HourFormat) async { - String formattedValue; + late String formattedValue; await tester.pumpWidget(MaterialApp( home: MediaQuery( data: MediaQueryData(alwaysUse24HourFormat: alwaysUse24HourFormat), diff --git a/packages/flutter/test/material/toggle_buttons_test.dart b/packages/flutter/test/material/toggle_buttons_test.dart index 09609d05f7..010e71f4c5 100644 --- a/packages/flutter/test/material/toggle_buttons_test.dart +++ b/packages/flutter/test/material/toggle_buttons_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'; @@ -13,7 +11,7 @@ import '../rendering/mock_canvas.dart'; const double _defaultBorderWidth = 1.0; -Widget boilerplate({Widget child}) { +Widget boilerplate({required Widget child}) { return Directionality( textDirection: TextDirection.ltr, child: Center(child: child), @@ -170,50 +168,6 @@ void main() { }, ); - testWidgets('children property cannot be null', (WidgetTester tester) async { - try { - await tester.pumpWidget( - Material( - child: boilerplate( - child: ToggleButtons( - isSelected: const [false, true], - onPressed: (int index) {}, - children: null, - ), - ), - ), - ); - fail('Should not be possible to create a toggle button with no children.'); - } on AssertionError catch (e) { - expect(e.toString(), contains('children != null')); - } - }); - - testWidgets( - 'isSelected property cannot be null', - (WidgetTester tester) async { - try { - await tester.pumpWidget( - Material( - child: boilerplate( - child: ToggleButtons( - isSelected: null, - onPressed: (int index) {}, - children: const [ - Text('First child'), - Text('Second child'), - ], - ), - ), - ), - ); - fail('Should not be possible to create a toggle button with no isSelected.'); - } on AssertionError catch (e) { - expect(e.toString(), contains('isSelected != null')); - } - }, - ); - testWidgets( 'children and isSelected properties have to be the same length', (WidgetTester tester) async { @@ -262,15 +216,15 @@ void main() { of: find.widgetWithText(RawMaterialButton, 'First child'), matching: find.byType(DefaultTextStyle), )).style; - expect(textStyle.fontFamily, theme.textTheme.bodyText2.fontFamily); - expect(textStyle.decoration, theme.textTheme.bodyText2.decoration); + expect(textStyle.fontFamily, theme.textTheme.bodyText2!.fontFamily); + expect(textStyle.decoration, theme.textTheme.bodyText2!.decoration); textStyle = tester.widget(find.descendant( of: find.widgetWithText(RawMaterialButton, 'Second child'), matching: find.byType(DefaultTextStyle), )).style; - expect(textStyle.fontFamily, theme.textTheme.bodyText2.fontFamily); - expect(textStyle.decoration, theme.textTheme.bodyText2.decoration); + expect(textStyle.fontFamily, theme.textTheme.bodyText2!.fontFamily); + expect(textStyle.decoration, theme.textTheme.bodyText2!.decoration); }); testWidgets('Custom text style except color is applied', (WidgetTester tester) async { @@ -1470,7 +1424,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( @@ -1491,7 +1445,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( @@ -1511,6 +1465,6 @@ void main() { ), ); - expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.basic); + expect(RendererBinding.instance!.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.basic); }); } diff --git a/packages/flutter/test/material/toggle_buttons_theme_test.dart b/packages/flutter/test/material/toggle_buttons_theme_test.dart index 510900673e..1914d63fa8 100644 --- a/packages/flutter/test/material/toggle_buttons_theme_test.dart +++ b/packages/flutter/test/material/toggle_buttons_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'; @@ -11,7 +9,7 @@ import 'package:flutter_test/flutter_test.dart'; import '../rendering/mock_canvas.dart'; -Widget boilerplate({Widget child}) { +Widget boilerplate({required Widget child}) { return Directionality( textDirection: TextDirection.ltr, child: Center(child: child), diff --git a/packages/flutter/test/material/tooltip_test.dart b/packages/flutter/test/material/tooltip_test.dart index 90d45bae23..04ecd2bdd4 100644 --- a/packages/flutter/test/material/tooltip_test.dart +++ b/packages/flutter/test/material/tooltip_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/services.dart'; @@ -581,7 +579,7 @@ void main() { (key.currentState as dynamic).ensureTooltipVisible(); // Before using "as dynamic" in your code, see note at the top of the file. await tester.pump(const Duration(seconds: 2)); // faded in, show timer started (and at 0.0) - final TextStyle textStyle = tester.widget(find.text(tooltipText)).style; + final TextStyle textStyle = tester.widget(find.text(tooltipText)).style!; expect(textStyle.color, Colors.white); expect(textStyle.fontFamily, 'Roboto'); expect(textStyle.decoration, TextDecoration.none); @@ -607,7 +605,7 @@ void main() { (key.currentState as dynamic).ensureTooltipVisible(); // Before using "as dynamic" in your code, see note at the top of the file. await tester.pump(const Duration(seconds: 2)); // faded in, show timer started (and at 0.0) - final TextStyle textStyle = tester.widget(find.text(tooltipText)).style; + final TextStyle textStyle = tester.widget(find.text(tooltipText)).style!; expect(textStyle.color, Colors.black); expect(textStyle.fontFamily, 'Roboto'); expect(textStyle.decoration, TextDecoration.none); @@ -634,7 +632,7 @@ void main() { (key.currentState as dynamic).ensureTooltipVisible(); // Before using "as dynamic" in your code, see note at the top of the file. await tester.pump(const Duration(seconds: 2)); // faded in, show timer started (and at 0.0) - final TextStyle textStyle = tester.widget(find.text(tooltipText)).style; + final TextStyle textStyle = tester.widget(find.text(tooltipText)).style!; expect(textStyle.color, Colors.orange); expect(textStyle.fontFamily, null); expect(textStyle.decoration, TextDecoration.underline); @@ -833,12 +831,12 @@ void main() { testWidgets('Tooltip shows/hides when hovered', (WidgetTester tester) async { const Duration waitDuration = Duration(milliseconds: 0); - TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse); + TestGesture? gesture = await tester.createGesture(kind: PointerDeviceKind.mouse); addTearDown(() async { if (gesture != null) return gesture.removePointer(); }); - await gesture.addPointer(); + await gesture!.addPointer(); await gesture.moveTo(const Offset(1.0, 1.0)); await tester.pump(); await gesture.moveTo(Offset.zero); @@ -1013,7 +1011,7 @@ void main() { }); testWidgets('Tooltip text scales with textScaleFactor', (WidgetTester tester) async { - Widget buildApp(String text, { double textScaleFactor }) { + Widget buildApp(String text, { required double textScaleFactor }) { return MediaQuery( data: MediaQueryData(textScaleFactor: textScaleFactor), child: Directionality( @@ -1254,6 +1252,6 @@ void main() { SemanticsNode findDebugSemantics(RenderObject object) { if (object.debugSemantics != null) - return object.debugSemantics; - return findDebugSemantics(object.parent as RenderObject); + return object.debugSemantics!; + return findDebugSemantics(object.parent! as RenderObject); } diff --git a/packages/flutter/test/material/tooltip_theme_test.dart b/packages/flutter/test/material/tooltip_theme_test.dart index daa900fb85..b0b2dd3aaa 100644 --- a/packages/flutter/test/material/tooltip_theme_test.dart +++ b/packages/flutter/test/material/tooltip_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/services.dart'; import 'package:flutter/src/material/tooltip_theme.dart'; import 'package:flutter/gestures.dart'; @@ -151,7 +149,7 @@ void main() { * * *********************/ - final RenderBox tip = tester.renderObject(find.text(tooltipText)).parent as RenderBox; + final RenderBox tip = tester.renderObject(find.text(tooltipText)).parent! as RenderBox; expect(tip.size.height, equals(100.0)); expect(tip.localToGlobal(tip.size.topLeft(Offset.zero)).dy, equals(100.0)); expect(tip.localToGlobal(tip.size.bottomRight(Offset.zero)).dy, equals(200.0)); @@ -209,7 +207,7 @@ void main() { * * *********************/ - final RenderBox tip = tester.renderObject(find.text(tooltipText)).parent as RenderBox; + final RenderBox tip = tester.renderObject(find.text(tooltipText)).parent! as RenderBox; expect(tip.size.height, equals(100.0)); expect(tip.localToGlobal(tip.size.topLeft(Offset.zero)).dy, equals(100.0)); expect(tip.localToGlobal(tip.size.bottomRight(Offset.zero)).dy, equals(200.0)); @@ -280,7 +278,7 @@ void main() { * * }- 10.0 margin *********************/ - final RenderBox tip = tester.renderObject(find.text(tooltipText)).parent as RenderBox; + final RenderBox tip = tester.renderObject(find.text(tooltipText)).parent! as RenderBox; expect(tip.size.height, equals(190.0)); expect(tip.localToGlobal(tip.size.topLeft(Offset.zero)).dy, equals(399.0)); expect(tip.localToGlobal(tip.size.bottomRight(Offset.zero)).dy, equals(589.0)); @@ -349,7 +347,7 @@ void main() { * * }- 10.0 margin *********************/ - final RenderBox tip = tester.renderObject(find.text(tooltipText)).parent as RenderBox; + final RenderBox tip = tester.renderObject(find.text(tooltipText)).parent! as RenderBox; expect(tip.size.height, equals(190.0)); expect(tip.localToGlobal(tip.size.topLeft(Offset.zero)).dy, equals(399.0)); expect(tip.localToGlobal(tip.size.bottomRight(Offset.zero)).dy, equals(589.0)); @@ -408,7 +406,7 @@ void main() { * * }- 10.0 margin *********************/ - final RenderBox tip = tester.renderObject(find.text(tooltipText)).parent as RenderBox; + final RenderBox tip = tester.renderObject(find.text(tooltipText)).parent! as RenderBox; expect(tip.size.height, equals(190.0)); expect(tip.localToGlobal(tip.size.topLeft(Offset.zero)).dy, equals(400.0)); expect(tip.localToGlobal(tip.size.bottomRight(Offset.zero)).dy, equals(590.0)); @@ -465,7 +463,7 @@ void main() { * * }- 10.0 margin *********************/ - final RenderBox tip = tester.renderObject(find.text(tooltipText)).parent as RenderBox; + final RenderBox tip = tester.renderObject(find.text(tooltipText)).parent! as RenderBox; expect(tip.size.height, equals(190.0)); expect(tip.localToGlobal(tip.size.topLeft(Offset.zero)).dy, equals(400.0)); expect(tip.localToGlobal(tip.size.bottomRight(Offset.zero)).dy, equals(590.0)); @@ -505,7 +503,7 @@ void main() { (key.currentState as dynamic).ensureTooltipVisible(); // Before using "as dynamic" in your code, see note at the top of the file. await tester.pump(const Duration(seconds: 2)); // faded in, show timer started (and at 0.0) - final RenderBox tip = tester.renderObject(find.text(tooltipText)).parent.parent.parent.parent.parent as RenderBox; + final RenderBox tip = tester.renderObject(find.text(tooltipText)).parent!.parent!.parent!.parent!.parent! as RenderBox; final RenderBox tooltipContent = tester.renderObject(find.text(tooltipText)); final Offset topLeftTipInGlobal = tip.localToGlobal(tip.size.topLeft(Offset.zero)); @@ -561,7 +559,7 @@ void main() { (key.currentState as dynamic).ensureTooltipVisible(); // Before using "as dynamic" in your code, see note at the top of the file. await tester.pump(const Duration(seconds: 2)); // faded in, show timer started (and at 0.0) - final RenderBox tip = tester.renderObject(find.text(tooltipText)).parent.parent.parent.parent.parent as RenderBox; + final RenderBox tip = tester.renderObject(find.text(tooltipText)).parent!.parent!.parent!.parent!.parent! as RenderBox; final RenderBox tooltipContent = tester.renderObject(find.text(tooltipText)); final Offset topLeftTipInGlobal = tip.localToGlobal(tip.size.topLeft(Offset.zero)); @@ -609,7 +607,7 @@ void main() { (key.currentState as dynamic).ensureTooltipVisible(); // Before using "as dynamic" in your code, see note at the top of the file. await tester.pump(const Duration(seconds: 2)); // faded in, show timer started (and at 0.0) - final TextStyle textStyle = tester.widget(find.text(tooltipText)).style; + final TextStyle textStyle = tester.widget(find.text(tooltipText)).style!; expect(textStyle.color, Colors.orange); expect(textStyle.fontFamily, null); expect(textStyle.decoration, TextDecoration.underline); @@ -638,7 +636,7 @@ void main() { (key.currentState as dynamic).ensureTooltipVisible(); // Before using "as dynamic" in your code, see note at the top of the file. await tester.pump(const Duration(seconds: 2)); // faded in, show timer started (and at 0.0) - final TextStyle textStyle = tester.widget(find.text(tooltipText)).style; + final TextStyle textStyle = tester.widget(find.text(tooltipText)).style!; expect(textStyle.color, Colors.orange); expect(textStyle.fontFamily, null); expect(textStyle.decoration, TextDecoration.underline); @@ -681,7 +679,7 @@ void main() { (key.currentState as dynamic).ensureTooltipVisible(); // Before using "as dynamic" in your code, see note at the top of the file. await tester.pump(const Duration(seconds: 2)); // faded in, show timer started (and at 0.0) - final RenderBox tip = tester.renderObject(find.text(tooltipText)).parent.parent.parent.parent as RenderBox; + final RenderBox tip = tester.renderObject(find.text(tooltipText)).parent!.parent!.parent!.parent! as RenderBox; expect(tip.size.height, equals(32.0)); expect(tip.size.width, equals(74.0)); @@ -723,7 +721,7 @@ void main() { (key.currentState as dynamic).ensureTooltipVisible(); // Before using "as dynamic" in your code, see note at the top of the file. await tester.pump(const Duration(seconds: 2)); // faded in, show timer started (and at 0.0) - final RenderBox tip = tester.renderObject(find.text(tooltipText)).parent.parent.parent.parent as RenderBox; + final RenderBox tip = tester.renderObject(find.text(tooltipText)).parent!.parent!.parent!.parent! as RenderBox; expect(tip.size.height, equals(32.0)); expect(tip.size.width, equals(74.0)); @@ -1259,6 +1257,6 @@ void main() { SemanticsNode findDebugSemantics(RenderObject object) { if (object.debugSemantics != null) - return object.debugSemantics; - return findDebugSemantics(object.parent as RenderObject); + return object.debugSemantics!; + return findDebugSemantics(object.parent! as RenderObject); } diff --git a/packages/flutter/test/material/typography_test.dart b/packages/flutter/test/material/typography_test.dart index a612f95818..202ba1633d 100644 --- a/packages/flutter/test/material/typography_test.dart +++ b/packages/flutter/test/material/typography_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'; @@ -19,16 +17,16 @@ void main() { }); test('Typography on non-Apple platforms defaults to the correct font', () { - expect(Typography.material2018(platform: TargetPlatform.android).black.headline6.fontFamily, 'Roboto'); - expect(Typography.material2018(platform: TargetPlatform.fuchsia).black.headline6.fontFamily, 'Roboto'); - expect(Typography.material2018(platform: TargetPlatform.linux).black.headline6.fontFamily, 'Roboto'); - expect(Typography.material2018(platform: TargetPlatform.linux).black.headline6.fontFamilyFallback, ['Ubuntu', 'Cantarell', 'DejaVu Sans', 'Liberation Sans', 'Arial']); - expect(Typography.material2018(platform: TargetPlatform.windows).black.headline6.fontFamily, 'Segoe UI'); - expect(Typography.material2018(platform: TargetPlatform.android).white.headline6.fontFamily, 'Roboto'); - expect(Typography.material2018(platform: TargetPlatform.fuchsia).white.headline6.fontFamily, 'Roboto'); - expect(Typography.material2018(platform: TargetPlatform.linux).white.headline6.fontFamily, 'Roboto'); - expect(Typography.material2018(platform: TargetPlatform.linux).white.headline6.fontFamilyFallback, ['Ubuntu', 'Cantarell', 'DejaVu Sans', 'Liberation Sans', 'Arial']); - expect(Typography.material2018(platform: TargetPlatform.windows).white.headline6.fontFamily, 'Segoe UI'); + expect(Typography.material2018(platform: TargetPlatform.android).black.headline6!.fontFamily, 'Roboto'); + expect(Typography.material2018(platform: TargetPlatform.fuchsia).black.headline6!.fontFamily, 'Roboto'); + expect(Typography.material2018(platform: TargetPlatform.linux).black.headline6!.fontFamily, 'Roboto'); + expect(Typography.material2018(platform: TargetPlatform.linux).black.headline6!.fontFamilyFallback, ['Ubuntu', 'Cantarell', 'DejaVu Sans', 'Liberation Sans', 'Arial']); + expect(Typography.material2018(platform: TargetPlatform.windows).black.headline6!.fontFamily, 'Segoe UI'); + expect(Typography.material2018(platform: TargetPlatform.android).white.headline6!.fontFamily, 'Roboto'); + expect(Typography.material2018(platform: TargetPlatform.fuchsia).white.headline6!.fontFamily, 'Roboto'); + expect(Typography.material2018(platform: TargetPlatform.linux).white.headline6!.fontFamily, 'Roboto'); + expect(Typography.material2018(platform: TargetPlatform.linux).white.headline6!.fontFamilyFallback, ['Ubuntu', 'Cantarell', 'DejaVu Sans', 'Liberation Sans', 'Arial']); + expect(Typography.material2018(platform: TargetPlatform.windows).white.headline6!.fontFamily, 'Segoe UI'); }); // Ref: https://developer.apple.com/ios/human-interface-guidelines/visual-design/typography/ @@ -91,7 +89,7 @@ void main() { final List nonDefaultPropertyNames = builder.properties .where((DiagnosticsNode node) => !node.isFiltered(DiagnosticLevel.info)) - .map((DiagnosticsNode node) => node.name).toList(); + .map((DiagnosticsNode node) => node.name!).toList(); expect(nonDefaultPropertyNames, ['black', 'white', 'englishLike', 'dense', 'tall']); }); @@ -106,81 +104,81 @@ void main() { const FontWeight medium = FontWeight.w500; // H1 Roboto light 96 -1.5 - expect(theme.headline1.fontFamily, 'Roboto'); - expect(theme.headline1.fontWeight, light); - expect(theme.headline1.fontSize, 96); - expect(theme.headline1.letterSpacing, -1.5); + expect(theme.headline1!.fontFamily, 'Roboto'); + expect(theme.headline1!.fontWeight, light); + expect(theme.headline1!.fontSize, 96); + expect(theme.headline1!.letterSpacing, -1.5); // H2 Roboto light 60 -0.5 - expect(theme.headline2.fontFamily, 'Roboto'); - expect(theme.headline2.fontWeight, light); - expect(theme.headline2.fontSize, 60); - expect(theme.headline2.letterSpacing, -0.5); + expect(theme.headline2!.fontFamily, 'Roboto'); + expect(theme.headline2!.fontWeight, light); + expect(theme.headline2!.fontSize, 60); + expect(theme.headline2!.letterSpacing, -0.5); // H3 Roboto regular 48 0 - expect(theme.headline3.fontFamily, 'Roboto'); - expect(theme.headline3.fontWeight, regular); - expect(theme.headline3.fontSize, 48); - expect(theme.headline3.letterSpacing, 0); + expect(theme.headline3!.fontFamily, 'Roboto'); + expect(theme.headline3!.fontWeight, regular); + expect(theme.headline3!.fontSize, 48); + expect(theme.headline3!.letterSpacing, 0); // H4 Roboto regular 34 0.25 - expect(theme.headline4.fontFamily, 'Roboto'); - expect(theme.headline4.fontWeight, regular); - expect(theme.headline4.fontSize, 34); - expect(theme.headline4.letterSpacing, 0.25); + expect(theme.headline4!.fontFamily, 'Roboto'); + expect(theme.headline4!.fontWeight, regular); + expect(theme.headline4!.fontSize, 34); + expect(theme.headline4!.letterSpacing, 0.25); // H5 Roboto regular 24 0 - expect(theme.headline5.fontFamily, 'Roboto'); - expect(theme.headline5.fontWeight, regular); - expect(theme.headline5.fontSize, 24); - expect(theme.headline5.letterSpacing, 0); + expect(theme.headline5!.fontFamily, 'Roboto'); + expect(theme.headline5!.fontWeight, regular); + expect(theme.headline5!.fontSize, 24); + expect(theme.headline5!.letterSpacing, 0); // H6 Roboto medium 20 0.15 - expect(theme.headline6.fontFamily, 'Roboto'); - expect(theme.headline6.fontWeight, medium); - expect(theme.headline6.fontSize, 20); - expect(theme.headline6.letterSpacing, 0.15); + expect(theme.headline6!.fontFamily, 'Roboto'); + expect(theme.headline6!.fontWeight, medium); + expect(theme.headline6!.fontSize, 20); + expect(theme.headline6!.letterSpacing, 0.15); // Subtitle1 Roboto regular 16 0.15 - expect(theme.subtitle1.fontFamily, 'Roboto'); - expect(theme.subtitle1.fontWeight, regular); - expect(theme.subtitle1.fontSize, 16); - expect(theme.subtitle1.letterSpacing, 0.15); + expect(theme.subtitle1!.fontFamily, 'Roboto'); + expect(theme.subtitle1!.fontWeight, regular); + expect(theme.subtitle1!.fontSize, 16); + expect(theme.subtitle1!.letterSpacing, 0.15); // Subtitle2 Roboto medium 14 0.1 - expect(theme.subtitle2.fontFamily, 'Roboto'); - expect(theme.subtitle2.fontWeight, medium); - expect(theme.subtitle2.fontSize, 14); - expect(theme.subtitle2.letterSpacing, 0.1); + expect(theme.subtitle2!.fontFamily, 'Roboto'); + expect(theme.subtitle2!.fontWeight, medium); + expect(theme.subtitle2!.fontSize, 14); + expect(theme.subtitle2!.letterSpacing, 0.1); // Body1 Roboto regular 16 0.5 - expect(theme.bodyText1.fontFamily, 'Roboto'); - expect(theme.bodyText1.fontWeight, regular); - expect(theme.bodyText1.fontSize, 16); - expect(theme.bodyText1.letterSpacing, 0.5); + expect(theme.bodyText1!.fontFamily, 'Roboto'); + expect(theme.bodyText1!.fontWeight, regular); + expect(theme.bodyText1!.fontSize, 16); + expect(theme.bodyText1!.letterSpacing, 0.5); // Body2 Roboto regular 14 0.25 - expect(theme.bodyText2.fontFamily, 'Roboto'); - expect(theme.bodyText2.fontWeight, regular); - expect(theme.bodyText2.fontSize, 14); - expect(theme.bodyText2.letterSpacing, 0.25); + expect(theme.bodyText2!.fontFamily, 'Roboto'); + expect(theme.bodyText2!.fontWeight, regular); + expect(theme.bodyText2!.fontSize, 14); + expect(theme.bodyText2!.letterSpacing, 0.25); // BUTTON Roboto medium 14 1.25 - expect(theme.button.fontFamily, 'Roboto'); - expect(theme.button.fontWeight, medium); - expect(theme.button.fontSize, 14); - expect(theme.button.letterSpacing, 1.25); + expect(theme.button!.fontFamily, 'Roboto'); + expect(theme.button!.fontWeight, medium); + expect(theme.button!.fontSize, 14); + expect(theme.button!.letterSpacing, 1.25); // Caption Roboto regular 12 0.4 - expect(theme.caption.fontFamily, 'Roboto'); - expect(theme.caption.fontWeight, regular); - expect(theme.caption.fontSize, 12); - expect(theme.caption.letterSpacing, 0.4); + expect(theme.caption!.fontFamily, 'Roboto'); + expect(theme.caption!.fontWeight, regular); + expect(theme.caption!.fontSize, 12); + expect(theme.caption!.letterSpacing, 0.4); // OVERLINE Roboto regular 10 1.5 - expect(theme.overline.fontFamily, 'Roboto'); - expect(theme.overline.fontWeight, regular); - expect(theme.overline.fontSize, 10); - expect(theme.overline.letterSpacing, 1.5); + expect(theme.overline!.fontFamily, 'Roboto'); + expect(theme.overline!.fontWeight, regular); + expect(theme.overline!.fontSize, 10); + expect(theme.overline!.letterSpacing, 1.5); }); } diff --git a/packages/flutter/test/material/user_accounts_drawer_header_test.dart b/packages/flutter/test/material/user_accounts_drawer_header_test.dart index dfe9a20d2a..b66530fda0 100644 --- a/packages/flutter/test/material/user_accounts_drawer_header_test.dart +++ b/packages/flutter/test/material/user_accounts_drawer_header_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'; @@ -143,7 +141,7 @@ void main() { // Regression test for https://github.com/flutter/flutter/issues/25801. testWidgets('UserAccountsDrawerHeader icon does not rotate after setState', (WidgetTester tester) async { - StateSetter testSetState; + late StateSetter testSetState; await tester.pumpWidget(MaterialApp( home: Material( child: StatefulBuilder( @@ -251,12 +249,12 @@ void main() { testWidgets('UserAccountsDrawerHeader null parameters LTR', (WidgetTester tester) async { Widget buildFrame({ - Widget currentAccountPicture, - List otherAccountsPictures, - Widget accountName, - Widget accountEmail, - VoidCallback onDetailsPressed, - EdgeInsets margin, + Widget? currentAccountPicture, + List? otherAccountsPictures, + Widget? accountName, + Widget? accountEmail, + VoidCallback? onDetailsPressed, + EdgeInsets? margin, }) { return MaterialApp( home: Material( @@ -359,12 +357,12 @@ void main() { testWidgets('UserAccountsDrawerHeader null parameters RTL', (WidgetTester tester) async { Widget buildFrame({ - Widget currentAccountPicture, - List otherAccountsPictures, - Widget accountName, - Widget accountEmail, - VoidCallback onDetailsPressed, - EdgeInsets margin, + Widget? currentAccountPicture, + List? otherAccountsPictures, + Widget? accountName, + Widget? accountEmail, + VoidCallback? onDetailsPressed, + EdgeInsets? margin, }) { return MaterialApp( home: Directionality( diff --git a/packages/flutter/test/material/will_pop_test.dart b/packages/flutter/test/material/will_pop_test.dart index e0484396d5..c1c05a1bbd 100644 --- a/packages/flutter/test/material/will_pop_test.dart +++ b/packages/flutter/test/material/will_pop_test.dart @@ -2,21 +2,19 @@ // 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'; bool willPopValue = false; class SamplePage extends StatefulWidget { - const SamplePage({ Key key }) : super(key: key); + const SamplePage({ Key? key }) : super(key: key); @override SamplePageState createState() => SamplePageState(); } class SamplePageState extends State { - ModalRoute _route; + ModalRoute? _route; Future _callback() async => willPopValue; @@ -45,7 +43,7 @@ class SamplePageState extends State { int willPopCount = 0; class SampleForm extends StatelessWidget { - const SampleForm({ Key key, this.callback }) : super(key: key); + const SampleForm({ Key? key, required this.callback }) : super(key: key); final WillPopCallback callback; @@ -68,7 +66,7 @@ class SampleForm extends StatelessWidget { // Expose the protected hasScopedWillPopCallback getter class TestPageRoute extends MaterialPageRoute { - TestPageRoute({ WidgetBuilder builder }) + TestPageRoute({ required WidgetBuilder builder }) : super(builder: builder, maintainState: true); bool get hasCallback => super.hasScopedWillPopCallback; @@ -118,7 +116,7 @@ void main() { // Use didPopRoute() to simulate the system back button. Check that // didPopRoute() indicates that the notification was handled. - final dynamic widgetsAppState = tester.state(find.byType(WidgetsApp)); + final dynamic widgetsAppState = tester.state(find.byType(WidgetsApp)); // ignore: unnecessary_nullable_for_final_variable_declarations expect(await widgetsAppState.didPopRoute(), isTrue); expect(find.text('Sample Page'), findsOneWidget); @@ -141,7 +139,7 @@ void main() { child: TextButton( child: const Text('X'), onPressed: () { - Navigator.of(context).push(MaterialPageRoute( + Navigator.of(context)!.push(MaterialPageRoute( builder: (BuildContext context) { return SampleForm( callback: () => Future.value(willPopValue), @@ -162,12 +160,6 @@ void main() { await tester.pumpAndSettle(); expect(find.text('Sample Form'), findsOneWidget); - // Should not pop if callback returns null - willPopValue = null; - await tester.tap(find.byTooltip('Back')); - await tester.pumpAndSettle(); - expect(find.text('Sample Form'), findsOneWidget); - // Should pop if callback returns true willPopValue = true; await tester.tap(find.byTooltip('Back')); @@ -186,7 +178,7 @@ void main() { child: TextButton( child: const Text('X'), onPressed: () { - Navigator.of(context).push(MaterialPageRoute( + Navigator.of(context)!.push(MaterialPageRoute( builder: (BuildContext context) { return SampleForm( callback: () => Future.value(willPopValue), @@ -238,11 +230,11 @@ void main() { actions: [ TextButton( child: const Text('YES'), - onPressed: () { Navigator.of(context).pop(true); }, + onPressed: () { Navigator.of(context)!.pop(true); }, ), TextButton( child: const Text('NO'), - onPressed: () { Navigator.of(context).pop(false); }, + onPressed: () { Navigator.of(context)!.pop(false); }, ), ], ); @@ -260,7 +252,7 @@ void main() { child: TextButton( child: const Text('X'), onPressed: () { - Navigator.of(context).push(MaterialPageRoute( + Navigator.of(context)!.push(MaterialPageRoute( builder: (BuildContext context) { return SampleForm( callback: () => showYesNoAlert(context), @@ -322,7 +314,7 @@ void main() { }); testWidgets('Route.scopedWillPop callbacks do not accumulate', (WidgetTester tester) async { - StateSetter contentsSetState; // call this to rebuild the route's SampleForm contents + late StateSetter contentsSetState; // call this to rebuild the route's SampleForm contents bool contentsEmpty = false; // when true, don't include the SampleForm in the route final TestPageRoute route = TestPageRoute( @@ -330,7 +322,7 @@ void main() { return StatefulBuilder( builder: (BuildContext context, StateSetter setState) { contentsSetState = setState; - return contentsEmpty ? Container() : SampleForm(key: UniqueKey()); + return contentsEmpty ? Container() : SampleForm(key: UniqueKey(), callback: () async => false); } ); }, @@ -346,7 +338,7 @@ void main() { child: TextButton( child: const Text('X'), onPressed: () { - Navigator.of(context).push(route); + Navigator.of(context)!.push(route); }, ), ); diff --git a/packages/flutter/test/widgets/app_overrides_test.dart b/packages/flutter/test/widgets/app_overrides_test.dart index 6d2564c2c5..7d5dfe3681 100644 --- a/packages/flutter/test/widgets/app_overrides_test.dart +++ b/packages/flutter/test/widgets/app_overrides_test.dart @@ -2,13 +2,11 @@ // 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/widgets.dart'; class TestRoute extends PageRoute { - TestRoute({ this.child, RouteSettings settings }) : super(settings: settings); + TestRoute({ required this.child, RouteSettings? settings }) : super(settings: settings); final Widget child; @@ -16,10 +14,10 @@ class TestRoute extends PageRoute { Duration get transitionDuration => const Duration(milliseconds: 150); @override - Color get barrierColor => null; + Color? get barrierColor => null; @override - String get barrierLabel => null; + String? get barrierLabel => null; @override bool get maintainState => false; diff --git a/packages/flutter/test/widgets/app_test.dart b/packages/flutter/test/widgets/app_test.dart index 9cfd065420..c309232c22 100644 --- a/packages/flutter/test/widgets/app_test.dart +++ b/packages/flutter/test/widgets/app_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/services.dart'; @@ -33,7 +31,7 @@ void main() { await tester.pumpWidget( WidgetsApp( key: key, - builder: (BuildContext context, Widget child) { + builder: (BuildContext context, Widget? child) { return const Placeholder(); }, color: const Color(0xFF123456), @@ -43,17 +41,17 @@ void main() { }); testWidgets('WidgetsApp can override default key bindings', (WidgetTester tester) async { - bool checked = false; + bool? checked = false; final GlobalKey key = GlobalKey(); await tester.pumpWidget( WidgetsApp( key: key, - builder: (BuildContext context, Widget child) { + builder: (BuildContext context, Widget? child) { return Material( child: Checkbox( value: checked, autofocus: true, - onChanged: (bool value) { + onChanged: (bool? value) { checked = value; }, ), @@ -79,12 +77,12 @@ void main() { shortcuts: { LogicalKeySet(LogicalKeyboardKey.space): const TestIntent(), }, - builder: (BuildContext context, Widget child) { + builder: (BuildContext context, Widget? child) { return Material( child: Checkbox( value: checked, autofocus: true, - onChanged: (bool value) { + onChanged: (bool? value) { checked = value; }, ), @@ -104,16 +102,16 @@ void main() { }); testWidgets('WidgetsApp default activation key mappings work', (WidgetTester tester) async { - bool checked = false; + bool? checked = false; await tester.pumpWidget( WidgetsApp( - builder: (BuildContext context, Widget child) { + builder: (BuildContext context, Widget? child) { return Material( child: Checkbox( value: checked, autofocus: true, - onChanged: (bool value) { + onChanged: (bool? value) { checked = value; }, ), @@ -147,15 +145,15 @@ void main() { group('error control test', () { Future expectFlutterError({ - GlobalKey key, - Widget widget, - WidgetTester tester, - String errorMessage, + required GlobalKey key, + required Widget widget, + required WidgetTester tester, + required String errorMessage, }) async { await tester.pumpWidget(widget); - FlutterError error; + late FlutterError error; try { - key.currentState.pushNamed('/path'); + key.currentState!.pushNamed('/path'); } on FlutterError catch (e) { error = e; } finally { @@ -258,7 +256,7 @@ void main() { expect(find.text('non-regular page two'), findsOneWidget); expect(find.text('non-regular page one'), findsNothing); expect(find.text('regular page'), findsNothing); - navigatorKey.currentState.pop(); + navigatorKey.currentState!.pop(); await tester.pumpAndSettle(); expect(find.text('non-regular page two'), findsNothing); expect(find.text('non-regular page one'), findsOneWidget); @@ -273,7 +271,7 @@ void main() { ); final SimpleNavigatorRouterDelegate delegate = SimpleNavigatorRouterDelegate( builder: (BuildContext context, RouteInformation information) { - return Text(information.location); + return Text(information.location!); }, onPopPage: (Route route, void result, SimpleNavigatorRouterDelegate delegate) { delegate.routeInformation = const RouteInformation( @@ -292,7 +290,7 @@ void main() { // Simulate android back button intent. final ByteData message = const JSONMethodCodec().encodeMethodCall(const MethodCall('popRoute')); - await ServicesBinding.instance.defaultBinaryMessenger.handlePlatformMessage('flutter/navigation', message, (_) { }); + await ServicesBinding.instance!.defaultBinaryMessenger.handlePlatformMessage('flutter/navigation', message, (_) { }); await tester.pumpAndSettle(); expect(find.text('popped'), findsOneWidget); }); @@ -300,8 +298,9 @@ void main() { testWidgets('WidgetsApp.router has correct default', (WidgetTester tester) async { final SimpleNavigatorRouterDelegate delegate = SimpleNavigatorRouterDelegate( builder: (BuildContext context, RouteInformation information) { - return Text(information.location); + return Text(information.location!); }, + onPopPage: (Route route, Object? result, SimpleNavigatorRouterDelegate delegate) => true, ); await tester.pumpWidget(WidgetsApp.router( routeInformationParser: SimpleRouteInformationParser(), @@ -331,22 +330,22 @@ class SimpleRouteInformationParser extends RouteInformationParser with PopNavigatorRouterDelegateMixin, ChangeNotifier { SimpleNavigatorRouterDelegate({ - @required this.builder, - this.onPopPage, + required this.builder, + required this.onPopPage, }); @override GlobalKey navigatorKey = GlobalKey(); RouteInformation get routeInformation => _routeInformation; - RouteInformation _routeInformation; + late RouteInformation _routeInformation; set routeInformation(RouteInformation newValue) { _routeInformation = newValue; notifyListeners(); } - SimpleRouterDelegateBuilder builder; - SimpleNavigatorRouterDelegatePopPage onPopPage; + final SimpleRouterDelegateBuilder builder; + final SimpleNavigatorRouterDelegatePopPage onPopPage; @override Future setNewRoutePath(RouteInformation configuration) { @@ -370,7 +369,7 @@ class SimpleNavigatorRouterDelegate extends RouterDelegate wit child: Text('base'), ), MaterialPage( - key: ValueKey(routeInformation?.location), + key: ValueKey(routeInformation.location!), child: builder(context, routeInformation), ) ], diff --git a/packages/flutter/test/widgets/app_title_test.dart b/packages/flutter/test/widgets/app_title_test.dart index 1662f22e96..cc8ad295ce 100644 --- a/packages/flutter/test/widgets/app_title_test.dart +++ b/packages/flutter/test/widgets/app_title_test.dart @@ -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.8 - import 'package:flutter_test/flutter_test.dart'; import 'package:flutter/widgets.dart'; const Color kTitleColor = Color(0xFF333333); const String kTitleString = 'Hello World'; -Future pumpApp(WidgetTester tester, { GenerateAppTitle onGenerateTitle }) async { +Future pumpApp(WidgetTester tester, { GenerateAppTitle? onGenerateTitle }) async { await tester.pumpWidget( WidgetsApp( supportedLocales: const [ diff --git a/packages/flutter/test/widgets/aspect_ratio_test.dart b/packages/flutter/test/widgets/aspect_ratio_test.dart index 8917cba09b..aad114d061 100644 --- a/packages/flutter/test/widgets/aspect_ratio_test.dart +++ b/packages/flutter/test/widgets/aspect_ratio_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_test/flutter_test.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter/widgets.dart'; diff --git a/packages/flutter/test/widgets/async_lifecycle_test.dart b/packages/flutter/test/widgets/async_lifecycle_test.dart index 19637d08bf..aca40d8a3e 100644 --- a/packages/flutter/test/widgets/async_lifecycle_test.dart +++ b/packages/flutter/test/widgets/async_lifecycle_test.dart @@ -2,13 +2,11 @@ // 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/widgets.dart'; import 'package:flutter_test/flutter_test.dart'; class InvalidOnInitLifecycleWidget extends StatefulWidget { - const InvalidOnInitLifecycleWidget({Key key}) : super(key: key); + const InvalidOnInitLifecycleWidget({Key? key}) : super(key: key); @override InvalidOnInitLifecycleWidgetState createState() => InvalidOnInitLifecycleWidgetState(); @@ -27,7 +25,7 @@ class InvalidOnInitLifecycleWidgetState extends State