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

Migrate more Material framework tests to null safety. (#67790)

* Migrate more Material framework tests to null safety.
parent ef119187
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
...@@ -12,7 +10,7 @@ import 'package:flutter_test/flutter_test.dart'; ...@@ -12,7 +10,7 @@ import 'package:flutter_test/flutter_test.dart';
import '../widgets/semantics_tester.dart'; import '../widgets/semantics_tester.dart';
class MockClipboard { class MockClipboard {
Object _clipboardData = <String, dynamic>{ dynamic _clipboardData = <String, dynamic>{
'text': null, 'text': null,
}; };
...@@ -66,7 +64,7 @@ void main() { ...@@ -66,7 +64,7 @@ void main() {
expect(selectedResults, hasLength(0)); expect(selectedResults, hasLength(0));
final TextField textField = tester.widget(find.byType(TextField)); final TextField textField = tester.widget(find.byType(TextField));
expect(textField.focusNode.hasFocus, isTrue); expect(textField.focusNode!.hasFocus, isTrue);
// Close search // Close search
await tester.tap(find.byTooltip('Back')); await tester.tap(find.byTooltip('Back'));
...@@ -104,7 +102,7 @@ void main() { ...@@ -104,7 +102,7 @@ void main() {
// Simulate system back button // Simulate system back button
final ByteData message = const JSONMethodCodec().encodeMethodCall(const MethodCall('popRoute')); 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(); await tester.pumpAndSettle();
expect(selectedResults, <void>[null]); expect(selectedResults, <void>[null]);
...@@ -133,7 +131,7 @@ void main() { ...@@ -133,7 +131,7 @@ void main() {
await tester.pumpAndSettle(); await tester.pumpAndSettle();
final TextField textField = tester.widget<TextField>(find.byType(TextField)); final TextField textField = tester.widget<TextField>(find.byType(TextField));
final Color hintColor = textField.decoration.hintStyle.color; final Color hintColor = textField.decoration!.hintStyle!.color!;
expect(hintColor, delegate.hintTextColor); expect(hintColor, delegate.hintTextColor);
}); });
...@@ -188,7 +186,7 @@ void main() { ...@@ -188,7 +186,7 @@ void main() {
expect(find.text('Results'), findsOneWidget); expect(find.text('Results'), findsOneWidget);
final TextField textField = tester.widget(find.byType(TextField)); final TextField textField = tester.widget(find.byType(TextField));
expect(textField.focusNode.hasFocus, isFalse); expect(textField.focusNode!.hasFocus, isFalse);
expect(delegate.queriesForResults, <String>['Wow']); expect(delegate.queriesForResults, <String>['Wow']);
// Close search // Close search
...@@ -236,14 +234,14 @@ void main() { ...@@ -236,14 +234,14 @@ void main() {
expect(delegate.queriesForResults, <String>['Wow']); expect(delegate.queriesForResults, <String>['Wow']);
TextField textField = tester.widget(find.byType(TextField)); TextField textField = tester.widget(find.byType(TextField));
expect(textField.focusNode.hasFocus, isFalse); expect(textField.focusNode!.hasFocus, isFalse);
// Tapping search field to go back to suggestions // Tapping search field to go back to suggestions
await tester.tap(find.byType(TextField)); await tester.tap(find.byType(TextField));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
textField = tester.widget(find.byType(TextField)); textField = tester.widget(find.byType(TextField));
expect(textField.focusNode.hasFocus, isTrue); expect(textField.focusNode!.hasFocus, isTrue);
expect(find.text('Suggestions'), findsOneWidget); expect(find.text('Suggestions'), findsOneWidget);
expect(find.text('Results'), findsNothing); expect(find.text('Results'), findsNothing);
...@@ -269,7 +267,7 @@ void main() { ...@@ -269,7 +267,7 @@ void main() {
expect(delegate.queriesForResults, <String>['Wow', 'Foo']); expect(delegate.queriesForResults, <String>['Wow', 'Foo']);
textField = tester.widget(find.byType(TextField)); textField = tester.widget(find.byType(TextField));
expect(textField.focusNode.hasFocus, isFalse); expect(textField.focusNode!.hasFocus, isFalse);
}); });
testWidgets('Fresh search always starts with empty query', (WidgetTester tester) async { testWidgets('Fresh search always starts with empty query', (WidgetTester tester) async {
...@@ -440,8 +438,8 @@ void main() { ...@@ -440,8 +438,8 @@ void main() {
}); });
testWidgets('Closing search with nested search shown goes back to underlying route', (WidgetTester tester) async { testWidgets('Closing search with nested search shown goes back to underlying route', (WidgetTester tester) async {
_TestSearchDelegate delegate; late _TestSearchDelegate delegate;
final List<String> nestedSearchResults = <String>[]; final List<String?> nestedSearchResults = <String?>[];
final _TestSearchDelegate nestedSearchDelegate = _TestSearchDelegate( final _TestSearchDelegate nestedSearchDelegate = _TestSearchDelegate(
suggestions: 'Nested Suggestions', suggestions: 'Nested Suggestions',
result: 'Nested Result', result: 'Nested Result',
...@@ -507,7 +505,7 @@ void main() { ...@@ -507,7 +505,7 @@ void main() {
expect(find.text('HomeBody'), findsOneWidget); expect(find.text('HomeBody'), findsOneWidget);
expect(find.text('Suggestions'), findsNothing); expect(find.text('Suggestions'), findsNothing);
expect(find.text('Nested Suggestions'), findsNothing); expect(find.text('Nested Suggestions'), findsNothing);
expect(nestedSearchResults, <String>[null]); expect(nestedSearchResults, <String?>[null]);
expect(selectedResults, <String>['Result Foo']); expect(selectedResults, <String>['Result Foo']);
}); });
...@@ -554,7 +552,7 @@ void main() { ...@@ -554,7 +552,7 @@ void main() {
await tester.pumpAndSettle(); await tester.pumpAndSettle();
final TextField textField = tester.widget<TextField>(find.byType(TextField)); final TextField textField = tester.widget<TextField>(find.byType(TextField));
final TextStyle hintStyle = textField.decoration.hintStyle; final TextStyle hintStyle = textField.decoration!.hintStyle!;
expect(hintStyle, delegate.searchFieldStyle); expect(hintStyle, delegate.searchFieldStyle);
}); });
...@@ -569,7 +567,7 @@ void main() { ...@@ -569,7 +567,7 @@ void main() {
await tester.showKeyboard(find.byType(TextField)); await tester.showKeyboard(find.byType(TextField));
expect(tester.testTextInput.setClientArgs['inputAction'], TextInputAction.search.toString()); expect(tester.testTextInput.setClientArgs!['inputAction'], TextInputAction.search.toString());
}); });
testWidgets('Custom textInputAction results in keyboard with corresponding button', (WidgetTester tester) async { testWidgets('Custom textInputAction results in keyboard with corresponding button', (WidgetTester tester) async {
...@@ -581,11 +579,11 @@ void main() { ...@@ -581,11 +579,11 @@ void main() {
await tester.tap(find.byTooltip('Search')); await tester.tap(find.byTooltip('Search'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
await tester.showKeyboard(find.byType(TextField)); await tester.showKeyboard(find.byType(TextField));
expect(tester.testTextInput.setClientArgs['inputAction'], TextInputAction.done.toString()); expect(tester.testTextInput.setClientArgs!['inputAction'], TextInputAction.done.toString());
}); });
group('contributes semantics', () { group('contributes semantics', () {
TestSemantics buildExpected({ String routeName }) { TestSemantics buildExpected({ required String routeName }) {
return TestSemantics.root( return TestSemantics.root(
children: <TestSemantics>[ children: <TestSemantics>[
TestSemantics( TestSemantics(
...@@ -697,17 +695,17 @@ void main() { ...@@ -697,17 +695,17 @@ void main() {
class TestHomePage extends StatelessWidget { class TestHomePage extends StatelessWidget {
const TestHomePage({ const TestHomePage({
Key key, Key? key,
this.results, this.results,
this.delegate, required this.delegate,
this.passInInitialQuery = false, this.passInInitialQuery = false,
this.initialQuery, this.initialQuery,
}) : super(key: key); }) : super(key: key);
final List<String> results; final List<String>? results;
final SearchDelegate<String> delegate; final SearchDelegate<String> delegate;
final bool passInInitialQuery; final bool passInInitialQuery;
final String initialQuery; final String? initialQuery;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
...@@ -751,8 +749,8 @@ class _TestSearchDelegate extends SearchDelegate<String> { ...@@ -751,8 +749,8 @@ class _TestSearchDelegate extends SearchDelegate<String> {
this.suggestions = 'Suggestions', this.suggestions = 'Suggestions',
this.result = 'Result', this.result = 'Result',
this.actions = const <Widget>[], this.actions = const <Widget>[],
TextStyle searchFieldStyle, TextStyle? searchFieldStyle,
String searchHint, String? searchHint,
TextInputAction textInputAction = TextInputAction.search, TextInputAction textInputAction = TextInputAction.search,
}) : super(searchFieldLabel: searchHint, textInputAction: textInputAction, searchFieldStyle: searchFieldStyle); }) : super(searchFieldLabel: searchHint, textInputAction: textInputAction, searchFieldStyle: searchFieldStyle);
...@@ -763,7 +761,7 @@ class _TestSearchDelegate extends SearchDelegate<String> { ...@@ -763,7 +761,7 @@ class _TestSearchDelegate extends SearchDelegate<String> {
@override @override
ThemeData appBarTheme(BuildContext context) { ThemeData appBarTheme(BuildContext context) {
final ThemeData theme = Theme.of(context); final ThemeData theme = Theme.of(context)!;
return theme.copyWith( return theme.copyWith(
inputDecorationTheme: InputDecorationTheme(hintStyle: TextStyle(color: hintTextColor)), inputDecorationTheme: InputDecorationTheme(hintStyle: TextStyle(color: hintTextColor)),
); );
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'dart:ui' show window; import 'dart:ui' show window;
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
...@@ -108,7 +106,7 @@ void main() { ...@@ -108,7 +106,7 @@ void main() {
); );
await tester.pumpWidget(_buildApp(sliderTheme, value: 0.5, enabled: false)); await tester.pumpWidget(_buildApp(sliderTheme, value: 0.5, enabled: false));
final MaterialInkController material = Material.of(tester.element(find.byType(Slider))); final MaterialInkController material = Material.of(tester.element(find.byType(Slider)))!;
expect( expect(
material, material,
...@@ -130,7 +128,7 @@ void main() { ...@@ -130,7 +128,7 @@ void main() {
); );
await tester.pumpWidget(_buildApp(sliderTheme, value: 0.5, enabled: false)); await tester.pumpWidget(_buildApp(sliderTheme, value: 0.5, enabled: false));
final MaterialInkController material = Material.of(tester.element(find.byType(Slider))); final MaterialInkController material = Material.of(tester.element(find.byType(Slider)))!;
expect( expect(
material, material,
...@@ -150,7 +148,7 @@ void main() { ...@@ -150,7 +148,7 @@ void main() {
primaryColor: customColor1, primaryColor: customColor1,
primaryColorDark: customColor2, primaryColorDark: customColor2,
primaryColorLight: customColor3, primaryColorLight: customColor3,
valueIndicatorTextStyle: ThemeData.fallback().textTheme.bodyText1.copyWith(color: customColor4), valueIndicatorTextStyle: ThemeData.fallback().textTheme.bodyText1!.copyWith(color: customColor4),
); );
expect(sliderTheme.activeTrackColor, equals(customColor1.withAlpha(0xff))); expect(sliderTheme.activeTrackColor, equals(customColor1.withAlpha(0xff)));
...@@ -165,7 +163,7 @@ void main() { ...@@ -165,7 +163,7 @@ void main() {
expect(sliderTheme.disabledThumbColor, equals(customColor2.withAlpha(0x52))); expect(sliderTheme.disabledThumbColor, equals(customColor2.withAlpha(0x52)));
expect(sliderTheme.overlayColor, equals(customColor1.withAlpha(0x1f))); expect(sliderTheme.overlayColor, equals(customColor1.withAlpha(0x1f)));
expect(sliderTheme.valueIndicatorColor, equals(customColor1.withAlpha(0xff))); expect(sliderTheme.valueIndicatorColor, equals(customColor1.withAlpha(0xff)));
expect(sliderTheme.valueIndicatorTextStyle.color, equals(customColor4)); expect(sliderTheme.valueIndicatorTextStyle!.color, equals(customColor4));
}); });
testWidgets('SliderThemeData generates correct shapes for fromPrimaryColors', (WidgetTester tester) async { testWidgets('SliderThemeData generates correct shapes for fromPrimaryColors', (WidgetTester tester) async {
...@@ -178,7 +176,7 @@ void main() { ...@@ -178,7 +176,7 @@ void main() {
primaryColor: customColor1, primaryColor: customColor1,
primaryColorDark: customColor2, primaryColorDark: customColor2,
primaryColorLight: customColor3, primaryColorLight: customColor3,
valueIndicatorTextStyle: ThemeData.fallback().textTheme.bodyText1.copyWith(color: customColor4), valueIndicatorTextStyle: ThemeData.fallback().textTheme.bodyText1!.copyWith(color: customColor4),
); );
expect(sliderTheme.overlayShape, const RoundSliderOverlayShape()); expect(sliderTheme.overlayShape, const RoundSliderOverlayShape());
...@@ -197,13 +195,13 @@ void main() { ...@@ -197,13 +195,13 @@ void main() {
primaryColor: Colors.black, primaryColor: Colors.black,
primaryColorDark: Colors.black, primaryColorDark: Colors.black,
primaryColorLight: Colors.black, primaryColorLight: Colors.black,
valueIndicatorTextStyle: ThemeData.fallback().textTheme.bodyText1.copyWith(color: Colors.black), valueIndicatorTextStyle: ThemeData.fallback().textTheme.bodyText1!.copyWith(color: Colors.black),
).copyWith(trackHeight: 2.0); ).copyWith(trackHeight: 2.0);
final SliderThemeData sliderThemeWhite = SliderThemeData.fromPrimaryColors( final SliderThemeData sliderThemeWhite = SliderThemeData.fromPrimaryColors(
primaryColor: Colors.white, primaryColor: Colors.white,
primaryColorDark: Colors.white, primaryColorDark: Colors.white,
primaryColorLight: Colors.white, primaryColorLight: Colors.white,
valueIndicatorTextStyle: ThemeData.fallback().textTheme.bodyText1.copyWith(color: Colors.white), valueIndicatorTextStyle: ThemeData.fallback().textTheme.bodyText1!.copyWith(color: Colors.white),
).copyWith(trackHeight: 6.0); ).copyWith(trackHeight: 6.0);
final SliderThemeData lerp = SliderThemeData.lerp(sliderThemeBlack, sliderThemeWhite, 0.5); final SliderThemeData lerp = SliderThemeData.lerp(sliderThemeBlack, sliderThemeWhite, 0.5);
const Color middleGrey = Color(0xff7f7f7f); const Color middleGrey = Color(0xff7f7f7f);
...@@ -221,7 +219,7 @@ void main() { ...@@ -221,7 +219,7 @@ void main() {
expect(lerp.disabledThumbColor, equals(middleGrey.withAlpha(0x52))); expect(lerp.disabledThumbColor, equals(middleGrey.withAlpha(0x52)));
expect(lerp.overlayColor, equals(middleGrey.withAlpha(0x1f))); expect(lerp.overlayColor, equals(middleGrey.withAlpha(0x1f)));
expect(lerp.valueIndicatorColor, equals(middleGrey.withAlpha(0xff))); expect(lerp.valueIndicatorColor, equals(middleGrey.withAlpha(0xff)));
expect(lerp.valueIndicatorTextStyle.color, equals(middleGrey.withAlpha(0xff))); expect(lerp.valueIndicatorTextStyle!.color, equals(middleGrey.withAlpha(0xff)));
}); });
testWidgets('Default slider track draws correctly', (WidgetTester tester) async { testWidgets('Default slider track draws correctly', (WidgetTester tester) async {
...@@ -232,7 +230,7 @@ void main() { ...@@ -232,7 +230,7 @@ void main() {
final SliderThemeData sliderTheme = theme.sliderTheme.copyWith(thumbColor: Colors.red.shade500); final SliderThemeData sliderTheme = theme.sliderTheme.copyWith(thumbColor: Colors.red.shade500);
await tester.pumpWidget(_buildApp(sliderTheme, value: 0.25)); await tester.pumpWidget(_buildApp(sliderTheme, value: 0.25));
final MaterialInkController material = Material.of(tester.element(find.byType(Slider))); final MaterialInkController material = Material.of(tester.element(find.byType(Slider)))!;
const Radius radius = Radius.circular(2); const Radius radius = Radius.circular(2);
const Radius activatedRadius = Radius.circular(3); const Radius activatedRadius = Radius.circular(3);
...@@ -266,7 +264,7 @@ void main() { ...@@ -266,7 +264,7 @@ void main() {
final SliderThemeData sliderTheme = theme.sliderTheme.copyWith(thumbColor: Colors.red.shade500); final SliderThemeData sliderTheme = theme.sliderTheme.copyWith(thumbColor: Colors.red.shade500);
await tester.pumpWidget(_buildApp(sliderTheme, value: 0.25)); await tester.pumpWidget(_buildApp(sliderTheme, value: 0.25));
final MaterialInkController material = Material.of(tester.element(find.byType(Slider))); final MaterialInkController material = Material.of(tester.element(find.byType(Slider)))!;
// With no touch, paints only the thumb. // With no touch, paints only the thumb.
expect( expect(
...@@ -327,7 +325,7 @@ void main() { ...@@ -327,7 +325,7 @@ void main() {
final SliderThemeData sliderTheme = theme.sliderTheme.copyWith(thumbColor: Colors.red.shade500); final SliderThemeData sliderTheme = theme.sliderTheme.copyWith(thumbColor: Colors.red.shade500);
await tester.pumpWidget(_buildApp(sliderTheme, value: 0.45)); await tester.pumpWidget(_buildApp(sliderTheme, value: 0.45));
final MaterialInkController material = Material.of(tester.element(find.byType(Slider))); final MaterialInkController material = Material.of(tester.element(find.byType(Slider)))!;
expect(material, paints..circle(color: sliderTheme.thumbColor, radius: 10.0)); expect(material, paints..circle(color: sliderTheme.thumbColor, radius: 10.0));
...@@ -724,7 +722,7 @@ void main() { ...@@ -724,7 +722,7 @@ void main() {
await tester.pumpWidget(_buildApp(sliderTheme, value: 0.25)); await tester.pumpWidget(_buildApp(sliderTheme, value: 0.25));
final MaterialInkController material = Material.of(tester.element(find.byType(Slider))); final MaterialInkController material = Material.of(tester.element(find.byType(Slider)))!;
// Top and bottom are centerY (300) + and - trackRadius (8). // Top and bottom are centerY (300) + and - trackRadius (8).
expect( expect(
...@@ -756,7 +754,7 @@ void main() { ...@@ -756,7 +754,7 @@ void main() {
); );
await tester.pumpWidget(_buildApp(sliderTheme, value: 0.25)); await tester.pumpWidget(_buildApp(sliderTheme, value: 0.25));
final MaterialInkController material = Material.of(tester.element(find.byType(Slider))); final MaterialInkController material = Material.of(tester.element(find.byType(Slider)))!;
expect( expect(
material, material,
...@@ -780,7 +778,7 @@ void main() { ...@@ -780,7 +778,7 @@ void main() {
); );
await tester.pumpWidget(_buildApp(sliderTheme, value: 0.25)); await tester.pumpWidget(_buildApp(sliderTheme, value: 0.25));
final MaterialInkController material = Material.of(tester.element(find.byType(Slider))); final MaterialInkController material = Material.of(tester.element(find.byType(Slider)))!;
expect( expect(
material, material,
...@@ -806,7 +804,7 @@ void main() { ...@@ -806,7 +804,7 @@ void main() {
await tester.pumpWidget(_buildApp(sliderTheme, value: 0.5, divisions: 2)); await tester.pumpWidget(_buildApp(sliderTheme, value: 0.5, divisions: 2));
final MaterialInkController material = Material.of(tester.element(find.byType(Slider))); final MaterialInkController material = Material.of(tester.element(find.byType(Slider)))!;
expect( expect(
material, material,
...@@ -842,7 +840,7 @@ void main() { ...@@ -842,7 +840,7 @@ void main() {
await tester.startGesture(center); await tester.startGesture(center);
await tester.pumpAndSettle(); await tester.pumpAndSettle();
final MaterialInkController material = Material.of(tester.element(find.byType(Slider))); final MaterialInkController material = Material.of(tester.element(find.byType(Slider)))!;
expect( expect(
material, material,
paints..circle( paints..circle(
...@@ -875,7 +873,7 @@ void main() { ...@@ -875,7 +873,7 @@ void main() {
divisions: 4, divisions: 4,
)); ));
final MaterialInkController material = Material.of(tester.element(find.byType(Slider))); final MaterialInkController material = Material.of(tester.element(find.byType(Slider)))!;
expect(material, paintsExactlyCountTimes(#drawRect, 0)); expect(material, paintsExactlyCountTimes(#drawRect, 0));
expect(material, paintsExactlyCountTimes(#drawCircle, 0)); expect(material, paintsExactlyCountTimes(#drawCircle, 0));
...@@ -895,7 +893,7 @@ void main() { ...@@ -895,7 +893,7 @@ void main() {
divisions: 4, divisions: 4,
)); ));
final MaterialInkController material = Material.of(tester.element(find.byType(Slider))); final MaterialInkController material = Material.of(tester.element(find.byType(Slider)))!;
// Only 2 track segments. // Only 2 track segments.
expect(material, paintsExactlyCountTimes(#drawRRect, 2)); expect(material, paintsExactlyCountTimes(#drawRRect, 2));
...@@ -919,7 +917,7 @@ void main() { ...@@ -919,7 +917,7 @@ void main() {
divisions: 4, divisions: 4,
)); ));
final MaterialInkController material = Material.of(tester.element(find.byType(Slider))); final MaterialInkController material = Material.of(tester.element(find.byType(Slider)))!;
// Only 5 tick marks. // Only 5 tick marks.
expect(material, paintsExactlyCountTimes(#drawRect, 0)); expect(material, paintsExactlyCountTimes(#drawRect, 0));
...@@ -940,7 +938,7 @@ void main() { ...@@ -940,7 +938,7 @@ void main() {
divisions: 4, divisions: 4,
)); ));
final MaterialInkController material = Material.of(tester.element(find.byType(Slider))); final MaterialInkController material = Material.of(tester.element(find.byType(Slider)))!;
// Only 1 thumb. // Only 1 thumb.
expect(material, paintsExactlyCountTimes(#drawRect, 0)); expect(material, paintsExactlyCountTimes(#drawRect, 0));
...@@ -961,7 +959,7 @@ void main() { ...@@ -961,7 +959,7 @@ void main() {
divisions: 4, divisions: 4,
)); ));
final MaterialInkController material = Material.of(tester.element(find.byType(Slider))); final MaterialInkController material = Material.of(tester.element(find.byType(Slider)))!;
// Tap the center of the track and wait for animations to finish. // Tap the center of the track and wait for animations to finish.
final Offset center = tester.getCenter(find.byType(Slider)); final Offset center = tester.getCenter(find.byType(Slider));
...@@ -990,7 +988,7 @@ void main() { ...@@ -990,7 +988,7 @@ void main() {
divisions: 4, divisions: 4,
)); ));
final MaterialInkController material = Material.of(tester.element(find.byType(Slider))); final MaterialInkController material = Material.of(tester.element(find.byType(Slider)))!;
final RenderBox valueIndicatorBox = tester.renderObject(find.byType(Overlay)); final RenderBox valueIndicatorBox = tester.renderObject(find.byType(Overlay));
// Tap the center of the track and wait for animations to finish. // Tap the center of the track and wait for animations to finish.
...@@ -1021,7 +1019,7 @@ void main() { ...@@ -1021,7 +1019,7 @@ void main() {
divisions: 4, divisions: 4,
)); ));
final MaterialInkController material = Material.of(tester.element(find.byType(Slider))); final MaterialInkController material = Material.of(tester.element(find.byType(Slider)))!;
final RenderBox valueIndicatorBox = tester.renderObject(find.byType(Overlay)); final RenderBox valueIndicatorBox = tester.renderObject(find.byType(Overlay));
// Tap the center of the track to kick off the animation of the value indicator. // Tap the center of the track to kick off the animation of the value indicator.
...@@ -1186,9 +1184,9 @@ Widget _buildApp( ...@@ -1186,9 +1184,9 @@ Widget _buildApp(
SliderThemeData sliderTheme, { SliderThemeData sliderTheme, {
double value = 0.0, double value = 0.0,
bool enabled = true, bool enabled = true,
int divisions, int? divisions,
}) { }) {
final ValueChanged<double> onChanged = enabled ? (double d) => value = d : null; final ValueChanged<double>? onChanged = enabled ? (double d) => value = d : null;
return MaterialApp( return MaterialApp(
home: Scaffold( home: Scaffold(
body: Center( body: Center(
...@@ -1210,9 +1208,9 @@ Widget _buildRangeApp( ...@@ -1210,9 +1208,9 @@ Widget _buildRangeApp(
SliderThemeData sliderTheme, { SliderThemeData sliderTheme, {
RangeValues values = const RangeValues(0, 0), RangeValues values = const RangeValues(0, 0),
bool enabled = true, bool enabled = true,
int divisions, int? divisions,
}) { }) {
final ValueChanged<RangeValues> onChanged = enabled ? (RangeValues d) => values = d : null; final ValueChanged<RangeValues>? onChanged = enabled ? (RangeValues d) => values = d : null;
return MaterialApp( return MaterialApp(
home: Scaffold( home: Scaffold(
body: Center( body: Center(
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/foundation.dart' show FlutterExceptionHandler; import 'package:flutter/foundation.dart' show FlutterExceptionHandler;
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
...@@ -19,7 +17,7 @@ void main() { ...@@ -19,7 +17,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
Scaffold.of(context).showSnackBar(const SnackBar( Scaffold.of(context)!.showSnackBar(const SnackBar(
content: Text(helloSnackBar), content: Text(helloSnackBar),
duration: Duration(seconds: 2), duration: Duration(seconds: 2),
)); ));
...@@ -64,7 +62,7 @@ void main() { ...@@ -64,7 +62,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
ScaffoldMessenger.of(context).showSnackBar(const SnackBar( ScaffoldMessenger.of(context)!.showSnackBar(const SnackBar(
content: Text(helloSnackBar), content: Text(helloSnackBar),
duration: Duration(seconds: 2), duration: Duration(seconds: 2),
)); ));
...@@ -110,7 +108,7 @@ void main() { ...@@ -110,7 +108,7 @@ void main() {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
snackBarCount += 1; snackBarCount += 1;
Scaffold.of(context).showSnackBar(SnackBar( Scaffold.of(context)!.showSnackBar(SnackBar(
content: Text('bar$snackBarCount'), content: Text('bar$snackBarCount'),
duration: const Duration(seconds: 2), duration: const Duration(seconds: 2),
)); ));
...@@ -185,7 +183,7 @@ void main() { ...@@ -185,7 +183,7 @@ void main() {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
snackBarCount += 1; snackBarCount += 1;
ScaffoldMessenger.of(context).showSnackBar(SnackBar( ScaffoldMessenger.of(context)!.showSnackBar(SnackBar(
content: Text('bar$snackBarCount'), content: Text('bar$snackBarCount'),
duration: const Duration(seconds: 2), duration: const Duration(seconds: 2),
)); ));
...@@ -253,8 +251,8 @@ void main() { ...@@ -253,8 +251,8 @@ void main() {
testWidgets('SnackBar cancel test', (WidgetTester tester) async { testWidgets('SnackBar cancel test', (WidgetTester tester) async {
int snackBarCount = 0; int snackBarCount = 0;
const Key tapTarget = Key('tap-target'); const Key tapTarget = Key('tap-target');
int time; late int time;
ScaffoldFeatureController<SnackBar, SnackBarClosedReason> lastController; late ScaffoldFeatureController<SnackBar, SnackBarClosedReason> lastController;
await tester.pumpWidget(MaterialApp( await tester.pumpWidget(MaterialApp(
home: Scaffold( home: Scaffold(
body: Builder( body: Builder(
...@@ -262,7 +260,7 @@ void main() { ...@@ -262,7 +260,7 @@ void main() {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
snackBarCount += 1; snackBarCount += 1;
lastController = Scaffold.of(context).showSnackBar(SnackBar( lastController = Scaffold.of(context)!.showSnackBar(SnackBar(
content: Text('bar$snackBarCount'), content: Text('bar$snackBarCount'),
duration: Duration(seconds: time), duration: Duration(seconds: time),
)); ));
...@@ -339,8 +337,8 @@ void main() { ...@@ -339,8 +337,8 @@ void main() {
testWidgets('SnackBar cancel test - ScaffoldMessenger', (WidgetTester tester) async { testWidgets('SnackBar cancel test - ScaffoldMessenger', (WidgetTester tester) async {
int snackBarCount = 0; int snackBarCount = 0;
const Key tapTarget = Key('tap-target'); const Key tapTarget = Key('tap-target');
int time; late int time;
ScaffoldFeatureController<SnackBar, SnackBarClosedReason> lastController; late ScaffoldFeatureController<SnackBar, SnackBarClosedReason> lastController;
await tester.pumpWidget(MaterialApp( await tester.pumpWidget(MaterialApp(
home: Scaffold( home: Scaffold(
body: Builder( body: Builder(
...@@ -348,7 +346,7 @@ void main() { ...@@ -348,7 +346,7 @@ void main() {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
snackBarCount += 1; snackBarCount += 1;
lastController = ScaffoldMessenger.of(context).showSnackBar(SnackBar( lastController = ScaffoldMessenger.of(context)!.showSnackBar(SnackBar(
content: Text('bar$snackBarCount'), content: Text('bar$snackBarCount'),
duration: Duration(seconds: time), duration: Duration(seconds: time),
)); ));
...@@ -432,7 +430,7 @@ void main() { ...@@ -432,7 +430,7 @@ void main() {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
snackBarCount += 1; snackBarCount += 1;
Scaffold.of(context).showSnackBar(SnackBar( Scaffold.of(context)!.showSnackBar(SnackBar(
content: Text('bar$snackBarCount'), content: Text('bar$snackBarCount'),
duration: const Duration(seconds: 2), duration: const Duration(seconds: 2),
)); ));
...@@ -477,7 +475,7 @@ void main() { ...@@ -477,7 +475,7 @@ void main() {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
snackBarCount += 1; snackBarCount += 1;
ScaffoldMessenger.of(context).showSnackBar(SnackBar( ScaffoldMessenger.of(context)!.showSnackBar(SnackBar(
content: Text('bar$snackBarCount'), content: Text('bar$snackBarCount'),
duration: const Duration(seconds: 2), duration: const Duration(seconds: 2),
)); ));
...@@ -520,7 +518,7 @@ void main() { ...@@ -520,7 +518,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
Scaffold.of(context).showSnackBar(SnackBar( Scaffold.of(context)!.showSnackBar(SnackBar(
content: const Text('I am a snack bar.'), content: const Text('I am a snack bar.'),
duration: const Duration(seconds: 2), duration: const Duration(seconds: 2),
action: SnackBarAction( action: SnackBarAction(
...@@ -559,7 +557,7 @@ void main() { ...@@ -559,7 +557,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
ScaffoldMessenger.of(context).showSnackBar(SnackBar( ScaffoldMessenger.of(context)!.showSnackBar(SnackBar(
content: const Text('I am a snack bar.'), content: const Text('I am a snack bar.'),
duration: const Duration(seconds: 2), duration: const Duration(seconds: 2),
action: SnackBarAction( action: SnackBarAction(
...@@ -600,7 +598,7 @@ void main() { ...@@ -600,7 +598,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
Scaffold.of(context).showSnackBar( Scaffold.of(context)!.showSnackBar(
SnackBar( SnackBar(
content: const Text('I am a snack bar.'), content: const Text('I am a snack bar.'),
duration: const Duration(seconds: 2), duration: const Duration(seconds: 2),
...@@ -642,7 +640,7 @@ void main() { ...@@ -642,7 +640,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
Scaffold.of(context).showSnackBar( Scaffold.of(context)!.showSnackBar(
SnackBar( SnackBar(
content: const Text('I am a snack bar.'), content: const Text('I am a snack bar.'),
duration: const Duration(seconds: 2), duration: const Duration(seconds: 2),
...@@ -680,7 +678,7 @@ void main() { ...@@ -680,7 +678,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
Scaffold.of(context).showSnackBar( Scaffold.of(context)!.showSnackBar(
SnackBar( SnackBar(
content: const Text('I am a snack bar.'), content: const Text('I am a snack bar.'),
margin: const EdgeInsets.all(padding), margin: const EdgeInsets.all(padding),
...@@ -726,7 +724,7 @@ void main() { ...@@ -726,7 +724,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
Scaffold.of(context).showSnackBar( Scaffold.of(context)!.showSnackBar(
const SnackBar( const SnackBar(
content: Text('I am a snack bar.'), content: Text('I am a snack bar.'),
behavior: SnackBarBehavior.floating, behavior: SnackBarBehavior.floating,
...@@ -773,7 +771,7 @@ void main() { ...@@ -773,7 +771,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context)!.showSnackBar(
const SnackBar( const SnackBar(
content: Text('I am a snack bar.'), content: Text('I am a snack bar.'),
behavior: SnackBarBehavior.floating, behavior: SnackBarBehavior.floating,
...@@ -814,7 +812,7 @@ void main() { ...@@ -814,7 +812,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context)!.showSnackBar(
const SnackBar( const SnackBar(
content: Text('I am a snack bar.'), content: Text('I am a snack bar.'),
padding: EdgeInsets.all(padding), padding: EdgeInsets.all(padding),
...@@ -858,7 +856,7 @@ void main() { ...@@ -858,7 +856,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context)!.showSnackBar(
SnackBar( SnackBar(
content: const Text('I am a snack bar.'), content: const Text('I am a snack bar.'),
width: width, width: width,
...@@ -896,7 +894,7 @@ void main() { ...@@ -896,7 +894,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context)!.showSnackBar(
SnackBar( SnackBar(
content: const Text('I am a snack bar.'), content: const Text('I am a snack bar.'),
duration: const Duration(seconds: 2), duration: const Duration(seconds: 2),
...@@ -925,8 +923,7 @@ void main() { ...@@ -925,8 +923,7 @@ void main() {
final Widget textWidget = actionTextBox.widget; final Widget textWidget = actionTextBox.widget;
final DefaultTextStyle defaultTextStyle = DefaultTextStyle.of(actionTextBox); final DefaultTextStyle defaultTextStyle = DefaultTextStyle.of(actionTextBox);
if (textWidget is Text) { if (textWidget is Text) {
TextStyle effectiveStyle = textWidget.style; final TextStyle effectiveStyle = defaultTextStyle.style.merge(textWidget.style);
effectiveStyle = defaultTextStyle.style.merge(textWidget.style);
expect(effectiveStyle.color, Colors.lightBlue); expect(effectiveStyle.color, Colors.lightBlue);
} else { } else {
expect(false, true); expect(false, true);
...@@ -949,7 +946,7 @@ void main() { ...@@ -949,7 +946,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
ScaffoldMessenger.of(context).showSnackBar(SnackBar( ScaffoldMessenger.of(context)!.showSnackBar(SnackBar(
content: const Text('I am a snack bar.'), content: const Text('I am a snack bar.'),
duration: const Duration(seconds: 2), duration: const Duration(seconds: 2),
action: SnackBarAction(label: 'ACTION', onPressed: () { }), action: SnackBarAction(label: 'ACTION', onPressed: () { }),
...@@ -1004,7 +1001,7 @@ void main() { ...@@ -1004,7 +1001,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
ScaffoldMessenger.of(context).showSnackBar(SnackBar( ScaffoldMessenger.of(context)!.showSnackBar(SnackBar(
content: const Text('I am a snack bar.'), content: const Text('I am a snack bar.'),
duration: const Duration(seconds: 2), duration: const Duration(seconds: 2),
action: SnackBarAction(label: 'ACTION', onPressed: () {}), action: SnackBarAction(label: 'ACTION', onPressed: () {}),
...@@ -1055,7 +1052,7 @@ void main() { ...@@ -1055,7 +1052,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
ScaffoldMessenger.of(context).showSnackBar(SnackBar( ScaffoldMessenger.of(context)!.showSnackBar(SnackBar(
content: const Text('I am a snack bar.'), content: const Text('I am a snack bar.'),
duration: const Duration(seconds: 2), duration: const Duration(seconds: 2),
action: SnackBarAction(label: 'ACTION', onPressed: () {}), action: SnackBarAction(label: 'ACTION', onPressed: () {}),
...@@ -1109,7 +1106,7 @@ void main() { ...@@ -1109,7 +1106,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
ScaffoldMessenger.of(context).showSnackBar(SnackBar( ScaffoldMessenger.of(context)!.showSnackBar(SnackBar(
content: const Text('I am a snack bar.'), content: const Text('I am a snack bar.'),
duration: const Duration(seconds: 2), duration: const Duration(seconds: 2),
action: SnackBarAction(label: 'ACTION', onPressed: () {}), action: SnackBarAction(label: 'ACTION', onPressed: () {}),
...@@ -1167,7 +1164,7 @@ void main() { ...@@ -1167,7 +1164,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
ScaffoldMessenger.of(context).showSnackBar(SnackBar( ScaffoldMessenger.of(context)!.showSnackBar(SnackBar(
content: const Text('I am a snack bar.'), content: const Text('I am a snack bar.'),
duration: const Duration(seconds: 2), duration: const Duration(seconds: 2),
action: SnackBarAction(label: 'ACTION', onPressed: () {}), action: SnackBarAction(label: 'ACTION', onPressed: () {}),
...@@ -1201,7 +1198,7 @@ void main() { ...@@ -1201,7 +1198,7 @@ void main() {
testWidgets('SnackBarClosedReason', (WidgetTester tester) async { testWidgets('SnackBarClosedReason', (WidgetTester tester) async {
final GlobalKey<ScaffoldMessengerState> scaffoldMessengerKey = GlobalKey<ScaffoldMessengerState>(); final GlobalKey<ScaffoldMessengerState> scaffoldMessengerKey = GlobalKey<ScaffoldMessengerState>();
bool actionPressed = false; bool actionPressed = false;
SnackBarClosedReason closedReason; SnackBarClosedReason? closedReason;
await tester.pumpWidget(MaterialApp( await tester.pumpWidget(MaterialApp(
scaffoldMessengerKey: scaffoldMessengerKey, scaffoldMessengerKey: scaffoldMessengerKey,
...@@ -1210,7 +1207,7 @@ void main() { ...@@ -1210,7 +1207,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
ScaffoldMessenger.of(context).showSnackBar(SnackBar( ScaffoldMessenger.of(context)!.showSnackBar(SnackBar(
content: const Text('snack'), content: const Text('snack'),
duration: const Duration(seconds: 2), duration: const Duration(seconds: 2),
action: SnackBarAction( action: SnackBarAction(
...@@ -1255,14 +1252,14 @@ void main() { ...@@ -1255,14 +1252,14 @@ void main() {
// Pop up the snack bar and then remove it. // Pop up the snack bar and then remove it.
await tester.tap(find.text('X')); await tester.tap(find.text('X'));
await tester.pump(const Duration(milliseconds: 750)); await tester.pump(const Duration(milliseconds: 750));
scaffoldMessengerKey.currentState.removeCurrentSnackBar(); scaffoldMessengerKey.currentState!.removeCurrentSnackBar();
await tester.pumpAndSettle(const Duration(seconds: 1)); await tester.pumpAndSettle(const Duration(seconds: 1));
expect(closedReason, equals(SnackBarClosedReason.remove)); expect(closedReason, equals(SnackBarClosedReason.remove));
// Pop up the snack bar and then hide it. // Pop up the snack bar and then hide it.
await tester.tap(find.text('X')); await tester.tap(find.text('X'));
await tester.pump(const Duration(milliseconds: 750)); await tester.pump(const Duration(milliseconds: 750));
scaffoldMessengerKey.currentState.hideCurrentSnackBar(); scaffoldMessengerKey.currentState!.hideCurrentSnackBar();
await tester.pumpAndSettle(const Duration(seconds: 1)); await tester.pumpAndSettle(const Duration(seconds: 1));
expect(closedReason, equals(SnackBarClosedReason.hide)); expect(closedReason, equals(SnackBarClosedReason.hide));
...@@ -1288,7 +1285,7 @@ void main() { ...@@ -1288,7 +1285,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
Scaffold.of(context).showSnackBar(SnackBar( Scaffold.of(context)!.showSnackBar(SnackBar(
content: const Text('snack'), content: const Text('snack'),
duration: const Duration(seconds: 1), duration: const Duration(seconds: 1),
action: SnackBarAction( action: SnackBarAction(
...@@ -1330,7 +1327,7 @@ void main() { ...@@ -1330,7 +1327,7 @@ void main() {
key: scaffoldKey, key: scaffoldKey,
body: GestureDetector( body: GestureDetector(
onTap: () { onTap: () {
ScaffoldMessenger.of(context).showSnackBar(SnackBar( ScaffoldMessenger.of(context)!.showSnackBar(SnackBar(
content: const Text('snack'), content: const Text('snack'),
duration: const Duration(seconds: 1), duration: const Duration(seconds: 1),
action: SnackBarAction( action: SnackBarAction(
...@@ -1372,7 +1369,7 @@ void main() { ...@@ -1372,7 +1369,7 @@ void main() {
body: Builder(builder: (BuildContext context) { body: Builder(builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
Scaffold.of(context).showSnackBar(SnackBar( Scaffold.of(context)!.showSnackBar(SnackBar(
content: const Text('snack'), content: const Text('snack'),
duration: const Duration(seconds: 1), duration: const Duration(seconds: 1),
action: SnackBarAction( action: SnackBarAction(
...@@ -1414,7 +1411,7 @@ void main() { ...@@ -1414,7 +1411,7 @@ void main() {
key: scaffoldKey, key: scaffoldKey,
body: GestureDetector( body: GestureDetector(
onTap: () { onTap: () {
ScaffoldMessenger.of(context).showSnackBar(SnackBar( ScaffoldMessenger.of(context)!.showSnackBar(SnackBar(
content: const Text('snack'), content: const Text('snack'),
duration: const Duration(seconds: 1), duration: const Duration(seconds: 1),
action: SnackBarAction( action: SnackBarAction(
...@@ -1453,7 +1450,7 @@ void main() { ...@@ -1453,7 +1450,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
ScaffoldMessenger.of(context).showSnackBar(const SnackBar( ScaffoldMessenger.of(context)!.showSnackBar(const SnackBar(
content: Text(helloSnackBar), content: Text(helloSnackBar),
)); ));
}, },
...@@ -1493,7 +1490,7 @@ void main() { ...@@ -1493,7 +1490,7 @@ void main() {
}); });
testWidgets('SnackBar handles updates to accessibleNavigation', (WidgetTester tester) async { testWidgets('SnackBar handles updates to accessibleNavigation', (WidgetTester tester) async {
Future<void> boilerplate({ bool accessibleNavigation }) { Future<void> boilerplate({ required bool accessibleNavigation }) {
return tester.pumpWidget(MaterialApp( return tester.pumpWidget(MaterialApp(
home: MediaQuery( home: MediaQuery(
data: MediaQueryData(accessibleNavigation: accessibleNavigation), data: MediaQueryData(accessibleNavigation: accessibleNavigation),
...@@ -1502,7 +1499,7 @@ void main() { ...@@ -1502,7 +1499,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
Scaffold.of(context).showSnackBar(SnackBar( Scaffold.of(context)!.showSnackBar(SnackBar(
content: const Text('test'), content: const Text('test'),
action: SnackBarAction(label: 'foo', onPressed: () { }), action: SnackBarAction(label: 'foo', onPressed: () { }),
)); ));
...@@ -1541,7 +1538,7 @@ void main() { ...@@ -1541,7 +1538,7 @@ void main() {
}); });
testWidgets('SnackBar handles updates to accessibleNavigation - ScaffoldMessenger', (WidgetTester tester) async { testWidgets('SnackBar handles updates to accessibleNavigation - ScaffoldMessenger', (WidgetTester tester) async {
Future<void> boilerplate({ bool accessibleNavigation }) { Future<void> boilerplate({ required bool accessibleNavigation }) {
return tester.pumpWidget(MaterialApp( return tester.pumpWidget(MaterialApp(
home: MediaQuery( home: MediaQuery(
data: MediaQueryData(accessibleNavigation: accessibleNavigation), data: MediaQueryData(accessibleNavigation: accessibleNavigation),
...@@ -1550,7 +1547,7 @@ void main() { ...@@ -1550,7 +1547,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
ScaffoldMessenger.of(context).showSnackBar(SnackBar( ScaffoldMessenger.of(context)!.showSnackBar(SnackBar(
content: const Text('test'), content: const Text('test'),
action: SnackBarAction(label: 'foo', onPressed: () { }), action: SnackBarAction(label: 'foo', onPressed: () { }),
)); ));
...@@ -1588,35 +1585,6 @@ void main() { ...@@ -1588,35 +1585,6 @@ void main() {
expect(find.text('test'), findsNothing); expect(find.text('test'), findsNothing);
}); });
testWidgets('Snackbar asserts if passed a null duration', (WidgetTester tester) async {
const Key tapTarget = Key('tap-target');
await tester.pumpWidget(MaterialApp(
home: Scaffold(
body: Builder(
builder: (BuildContext context) {
return GestureDetector(
onTap: () {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(nonconst('hello')),
duration: null,
));
},
behavior: HitTestBehavior.opaque,
child: Container(
height: 100.0,
width: 100.0,
key: tapTarget,
),
);
},
),
),
));
await tester.tap(find.byKey(tapTarget));
expect(tester.takeException(), isNotNull);
});
testWidgets('Snackbar calls onVisible once', (WidgetTester tester) async { testWidgets('Snackbar calls onVisible once', (WidgetTester tester) async {
const Key tapTarget = Key('tap-target'); const Key tapTarget = Key('tap-target');
int called = 0; int called = 0;
...@@ -1626,7 +1594,7 @@ void main() { ...@@ -1626,7 +1594,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
ScaffoldMessenger.of(context).showSnackBar(SnackBar( ScaffoldMessenger.of(context)!.showSnackBar(SnackBar(
content: const Text('hello'), content: const Text('hello'),
duration: const Duration(seconds: 1), duration: const Duration(seconds: 1),
onVisible: () { onVisible: () {
...@@ -1663,14 +1631,14 @@ void main() { ...@@ -1663,14 +1631,14 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
ScaffoldMessenger.of(context).showSnackBar(SnackBar( ScaffoldMessenger.of(context)!.showSnackBar(SnackBar(
content: const Text('hello'), content: const Text('hello'),
duration: const Duration(seconds: 1), duration: const Duration(seconds: 1),
onVisible: () { onVisible: () {
called += 1; called += 1;
}, },
)); ));
ScaffoldMessenger.of(context).showSnackBar(SnackBar( ScaffoldMessenger.of(context)!.showSnackBar(SnackBar(
content: const Text('hello 2'), content: const Text('hello 2'),
duration: const Duration(seconds: 1), duration: const Duration(seconds: 1),
onVisible: () { onVisible: () {
...@@ -1779,7 +1747,7 @@ void main() { ...@@ -1779,7 +1747,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context)!.showSnackBar(
SnackBar( SnackBar(
content: const Text('I am a snack bar.'), content: const Text('I am a snack bar.'),
duration: const Duration(seconds: 2), duration: const Duration(seconds: 2),
...@@ -1879,7 +1847,7 @@ void main() { ...@@ -1879,7 +1847,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
ScaffoldMessenger.of(context).showSnackBar(SnackBar( ScaffoldMessenger.of(context)!.showSnackBar(SnackBar(
content: const Text('I am a snack bar.'), content: const Text('I am a snack bar.'),
duration: const Duration(seconds: 2), duration: const Duration(seconds: 2),
action: SnackBarAction(label: 'ACTION', onPressed: () {}), action: SnackBarAction(label: 'ACTION', onPressed: () {}),
...@@ -1994,14 +1962,14 @@ void main() { ...@@ -1994,14 +1962,14 @@ void main() {
key: transitionTarget, key: transitionTarget,
child: const Text('PUSH'), child: const Text('PUSH'),
onPressed: () { onPressed: () {
Navigator.of(context).pushNamed('/second'); Navigator.of(context)!.pushNamed('/second');
}, },
), ),
), ),
floatingActionButton: FloatingActionButton( floatingActionButton: FloatingActionButton(
key: snackTarget, key: snackTarget,
onPressed: () async { onPressed: () async {
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context)!.showSnackBar(
const SnackBar( const SnackBar(
content: Text(snackBarText), content: Text(snackBarText),
), ),
...@@ -2067,7 +2035,7 @@ void main() { ...@@ -2067,7 +2035,7 @@ void main() {
)); ));
final List<dynamic> exceptions = <dynamic>[]; final List<dynamic> exceptions = <dynamic>[];
final FlutterExceptionHandler oldHandler = FlutterError.onError; final FlutterExceptionHandler? oldHandler = FlutterError.onError;
FlutterError.onError = (FlutterErrorDetails details) { FlutterError.onError = (FlutterErrorDetails details) {
exceptions.add(details.exception); exceptions.add(details.exception);
}; };
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
...@@ -73,7 +71,7 @@ void main() { ...@@ -73,7 +71,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
ScaffoldMessenger.of(context).showSnackBar(SnackBar( ScaffoldMessenger.of(context)!.showSnackBar(SnackBar(
content: const Text(text), content: const Text(text),
duration: const Duration(seconds: 2), duration: const Duration(seconds: 2),
action: SnackBarAction(label: 'ACTION', onPressed: () {}), action: SnackBarAction(label: 'ACTION', onPressed: () {}),
...@@ -111,7 +109,7 @@ void main() { ...@@ -111,7 +109,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
ScaffoldMessenger.of(context).showSnackBar(SnackBar( ScaffoldMessenger.of(context)!.showSnackBar(SnackBar(
content: const Text(text), content: const Text(text),
duration: const Duration(seconds: 2), duration: const Duration(seconds: 2),
action: SnackBarAction(label: action, onPressed: () {}), action: SnackBarAction(label: action, onPressed: () {}),
...@@ -136,7 +134,7 @@ void main() { ...@@ -136,7 +134,7 @@ void main() {
expect(material.color, snackBarTheme.backgroundColor); expect(material.color, snackBarTheme.backgroundColor);
expect(material.elevation, snackBarTheme.elevation); expect(material.elevation, snackBarTheme.elevation);
expect(material.shape, snackBarTheme.shape); expect(material.shape, snackBarTheme.shape);
expect(button.text.style.color, snackBarTheme.actionTextColor); expect(button.text.style!.color, snackBarTheme.actionTextColor);
}); });
testWidgets('SnackBar widget properties take priority over theme', (WidgetTester tester) async { testWidgets('SnackBar widget properties take priority over theme', (WidgetTester tester) async {
...@@ -155,7 +153,7 @@ void main() { ...@@ -155,7 +153,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
ScaffoldMessenger.of(context).showSnackBar(SnackBar( ScaffoldMessenger.of(context)!.showSnackBar(SnackBar(
backgroundColor: backgroundColor, backgroundColor: backgroundColor,
elevation: elevation, elevation: elevation,
shape: shape, shape: shape,
...@@ -185,7 +183,7 @@ void main() { ...@@ -185,7 +183,7 @@ void main() {
expect(material.color, backgroundColor); expect(material.color, backgroundColor);
expect(material.elevation, elevation); expect(material.elevation, elevation);
expect(material.shape, shape); expect(material.shape, shape);
expect(button.text.style.color, textColor); expect(button.text.style!.color, textColor);
}); });
testWidgets('SnackBar theme behavior is correct for floating', (WidgetTester tester) async { testWidgets('SnackBar theme behavior is correct for floating', (WidgetTester tester) async {
...@@ -202,7 +200,7 @@ void main() { ...@@ -202,7 +200,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
ScaffoldMessenger.of(context).showSnackBar(SnackBar( ScaffoldMessenger.of(context)!.showSnackBar(SnackBar(
content: const Text('I am a snack bar.'), content: const Text('I am a snack bar.'),
duration: const Duration(seconds: 2), duration: const Duration(seconds: 2),
action: SnackBarAction(label: 'ACTION', onPressed: () {}), action: SnackBarAction(label: 'ACTION', onPressed: () {}),
...@@ -244,7 +242,7 @@ void main() { ...@@ -244,7 +242,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
ScaffoldMessenger.of(context).showSnackBar(SnackBar( ScaffoldMessenger.of(context)!.showSnackBar(SnackBar(
content: const Text('I am a snack bar.'), content: const Text('I am a snack bar.'),
duration: const Duration(seconds: 2), duration: const Duration(seconds: 2),
action: SnackBarAction(label: 'ACTION', onPressed: () {}), action: SnackBarAction(label: 'ACTION', onPressed: () {}),
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
...@@ -383,7 +381,7 @@ void main() { ...@@ -383,7 +381,7 @@ void main() {
} }
final ControlsWidgetBuilder builder = final ControlsWidgetBuilder builder =
(BuildContext context, { VoidCallback onStepContinue, VoidCallback onStepCancel }) { (BuildContext context, { VoidCallback? onStepContinue, VoidCallback? onStepCancel }) {
return Container( return Container(
margin: const EdgeInsets.only(top: 16.0), margin: const EdgeInsets.only(top: 16.0),
child: ConstrainedBox( child: ConstrainedBox(
...@@ -477,8 +475,8 @@ void main() { ...@@ -477,8 +475,8 @@ void main() {
}); });
testWidgets('Nested stepper error test', (WidgetTester tester) async { testWidgets('Nested stepper error test', (WidgetTester tester) async {
FlutterErrorDetails errorDetails; late FlutterErrorDetails errorDetails;
final FlutterExceptionHandler oldHandler = FlutterError.onError; final FlutterExceptionHandler? oldHandler = FlutterError.onError;
FlutterError.onError = (FlutterErrorDetails details) { FlutterError.onError = (FlutterErrorDetails details) {
errorDetails = details; errorDetails = details;
}; };
...@@ -518,7 +516,6 @@ void main() { ...@@ -518,7 +516,6 @@ void main() {
FlutterError.onError = oldHandler; FlutterError.onError = oldHandler;
} }
expect(errorDetails, isNotNull);
expect(errorDetails.stack, isNotNull); expect(errorDetails.stack, isNotNull);
// Check the ErrorDetails without the stack trace // Check the ErrorDetails without the stack trace
final String fullErrorMessage = errorDetails.toString(); final String fullErrorMessage = errorDetails.toString();
...@@ -627,7 +624,7 @@ void main() { ...@@ -627,7 +624,7 @@ void main() {
); );
await tester.pump(); await tester.pump();
final FocusNode disabledNode = Focus.of(tester.element(find.text('Step 0')), nullOk: true, scopeOk: true); final FocusNode disabledNode = Focus.of(tester.element(find.text('Step 0')), nullOk: true, scopeOk: true)!;
disabledNode.requestFocus(); disabledNode.requestFocus();
await tester.pump(); await tester.pump();
expect(disabledNode.hasPrimaryFocus, isFalse); expect(disabledNode.hasPrimaryFocus, isFalse);
...@@ -653,7 +650,7 @@ void main() { ...@@ -653,7 +650,7 @@ void main() {
); );
await tester.pump(); await tester.pump();
final FocusNode disabledNode = Focus.of(tester.element(find.text('Step 0')), nullOk: true, scopeOk: true); final FocusNode disabledNode = Focus.of(tester.element(find.text('Step 0')), nullOk: true, scopeOk: true)!;
disabledNode.requestFocus(); disabledNode.requestFocus();
await tester.pump(); await tester.pump();
expect(disabledNode.hasPrimaryFocus, isFalse); expect(disabledNode.hasPrimaryFocus, isFalse);
...@@ -748,26 +745,26 @@ void main() { ...@@ -748,26 +745,26 @@ void main() {
await tester.pumpWidget(buildFrame(ThemeData.light())); await tester.pumpWidget(buildFrame(ThemeData.light()));
expect(buttonMaterial('CONTINUE').color.value, 0xff2196f3); expect(buttonMaterial('CONTINUE').color!.value, 0xff2196f3);
expect(buttonMaterial('CONTINUE').textStyle.color.value, 0xffffffff); expect(buttonMaterial('CONTINUE').textStyle!.color!.value, 0xffffffff);
expect(buttonMaterial('CONTINUE').shape, buttonShape); expect(buttonMaterial('CONTINUE').shape, buttonShape);
expect(tester.getRect(find.widgetWithText(TextButton, 'CONTINUE')), continueButtonRect); expect(tester.getRect(find.widgetWithText(TextButton, 'CONTINUE')), continueButtonRect);
expect(buttonMaterial('CANCEL').color.value, 0); expect(buttonMaterial('CANCEL').color!.value, 0);
expect(buttonMaterial('CANCEL').textStyle.color.value, 0x8a000000); expect(buttonMaterial('CANCEL').textStyle!.color!.value, 0x8a000000);
expect(buttonMaterial('CANCEL').shape, buttonShape); expect(buttonMaterial('CANCEL').shape, buttonShape);
expect(tester.getRect(find.widgetWithText(TextButton, 'CANCEL')), cancelButtonRect); expect(tester.getRect(find.widgetWithText(TextButton, 'CANCEL')), cancelButtonRect);
await tester.pumpWidget(buildFrame(ThemeData.dark())); await tester.pumpWidget(buildFrame(ThemeData.dark()));
await tester.pumpAndSettle(); // Complete the theme animation. await tester.pumpAndSettle(); // Complete the theme animation.
expect(buttonMaterial('CONTINUE').color.value, 0); expect(buttonMaterial('CONTINUE').color!.value, 0);
expect(buttonMaterial('CONTINUE').textStyle.color.value, 0xffffffff); expect(buttonMaterial('CONTINUE').textStyle!.color!.value, 0xffffffff);
expect(buttonMaterial('CONTINUE').shape, buttonShape); expect(buttonMaterial('CONTINUE').shape, buttonShape);
expect(tester.getRect(find.widgetWithText(TextButton, 'CONTINUE')), continueButtonRect); expect(tester.getRect(find.widgetWithText(TextButton, 'CONTINUE')), continueButtonRect);
expect(buttonMaterial('CANCEL').color.value, 0); expect(buttonMaterial('CANCEL').color!.value, 0);
expect(buttonMaterial('CANCEL').textStyle.color.value, 0xb3ffffff); expect(buttonMaterial('CANCEL').textStyle!.color!.value, 0xb3ffffff);
expect(buttonMaterial('CANCEL').shape, buttonShape); expect(buttonMaterial('CANCEL').shape, buttonShape);
expect(tester.getRect(find.widgetWithText(TextButton, 'CANCEL')), cancelButtonRect); expect(tester.getRect(find.widgetWithText(TextButton, 'CANCEL')), cancelButtonRect);
}); });
...@@ -802,20 +799,20 @@ void main() { ...@@ -802,20 +799,20 @@ void main() {
await tester.pumpWidget(buildFrame(ThemeData.light())); await tester.pumpWidget(buildFrame(ThemeData.light()));
expect(buttonMaterial('CONTINUE').color.value, 0); expect(buttonMaterial('CONTINUE').color!.value, 0);
expect(buttonMaterial('CONTINUE').textStyle.color.value, 0x61000000); expect(buttonMaterial('CONTINUE').textStyle!.color!.value, 0x61000000);
expect(buttonMaterial('CANCEL').color.value, 0); expect(buttonMaterial('CANCEL').color!.value, 0);
expect(buttonMaterial('CANCEL').textStyle.color.value, 0x61000000); expect(buttonMaterial('CANCEL').textStyle!.color!.value, 0x61000000);
await tester.pumpWidget(buildFrame(ThemeData.dark())); await tester.pumpWidget(buildFrame(ThemeData.dark()));
await tester.pumpAndSettle(); // Complete the theme animation. await tester.pumpAndSettle(); // Complete the theme animation.
expect(buttonMaterial('CONTINUE').color.value, 0); expect(buttonMaterial('CONTINUE').color!.value, 0);
expect(buttonMaterial('CONTINUE').textStyle.color.value, 0x61ffffff); expect(buttonMaterial('CONTINUE').textStyle!.color!.value, 0x61ffffff);
expect(buttonMaterial('CANCEL').color.value, 0); expect(buttonMaterial('CANCEL').color!.value, 0);
expect(buttonMaterial('CANCEL').textStyle.color.value, 0x61ffffff); expect(buttonMaterial('CANCEL').textStyle!.color!.value, 0x61ffffff);
}); });
testWidgets('Vertical and Horizontal Stepper physics test', (WidgetTester tester) async { testWidgets('Vertical and Horizontal Stepper physics test', (WidgetTester tester) async {
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
...@@ -26,7 +24,7 @@ final List<SizedBox> _sizedTabs = <SizedBox>[ ...@@ -26,7 +24,7 @@ final List<SizedBox> _sizedTabs = <SizedBox>[
]; ];
Widget _withTheme( Widget _withTheme(
TabBarTheme theme, { TabBarTheme? theme, {
List<Widget> tabs = _tabs, List<Widget> tabs = _tabs,
bool isScrollable = false, bool isScrollable = false,
}) { }) {
...@@ -56,21 +54,21 @@ void main() { ...@@ -56,21 +54,21 @@ void main() {
await tester.pumpWidget(_withTheme(null)); await tester.pumpWidget(_withTheme(null));
final RenderParagraph selectedRenderObject = tester.renderObject<RenderParagraph>(find.text(_tab1Text)); final RenderParagraph selectedRenderObject = tester.renderObject<RenderParagraph>(find.text(_tab1Text));
expect(selectedRenderObject.text.style.fontFamily, equals('Roboto')); expect(selectedRenderObject.text.style!.fontFamily, equals('Roboto'));
expect(selectedRenderObject.text.style.fontSize, equals(14.0)); expect(selectedRenderObject.text.style!.fontSize, equals(14.0));
expect(selectedRenderObject.text.style.color, equals(Colors.white)); expect(selectedRenderObject.text.style!.color, equals(Colors.white));
final RenderParagraph unselectedRenderObject = tester.renderObject<RenderParagraph>(find.text(_tab2Text)); final RenderParagraph unselectedRenderObject = tester.renderObject<RenderParagraph>(find.text(_tab2Text));
expect(unselectedRenderObject.text.style.fontFamily, equals('Roboto')); expect(unselectedRenderObject.text.style!.fontFamily, equals('Roboto'));
expect(unselectedRenderObject.text.style.fontSize, equals(14.0)); expect(unselectedRenderObject.text.style!.fontSize, equals(14.0));
expect(unselectedRenderObject.text.style.color, equals(Colors.white.withAlpha(0xB2))); expect(unselectedRenderObject.text.style!.color, equals(Colors.white.withAlpha(0xB2)));
// tests for the default value of labelPadding when tabBarTheme and tabBar do not provide one // tests for the default value of labelPadding when tabBarTheme and tabBar do not provide one
await tester.pumpWidget(_withTheme(null, tabs: _sizedTabs, isScrollable: true)); await tester.pumpWidget(_withTheme(null, tabs: _sizedTabs, isScrollable: true));
const double indicatorWeight = 2.0; const double indicatorWeight = 2.0;
final Rect tabBar = tester.getRect(find.byType(TabBar)); final Rect tabBar = tester.getRect(find.byType(TabBar));
final Rect tabOneRect = tester.getRect(find.byKey(_sizedTabs[0].key)); final Rect tabOneRect = tester.getRect(find.byKey(_sizedTabs[0].key!));
final Rect tabTwoRect = tester.getRect(find.byKey(_sizedTabs[1].key)); final Rect tabTwoRect = tester.getRect(find.byKey(_sizedTabs[1].key!));
// verify coordinates of tabOne // verify coordinates of tabOne
expect(tabOneRect.left, equals(kTabLabelPadding.left)); expect(tabOneRect.left, equals(kTabLabelPadding.left));
...@@ -92,9 +90,9 @@ void main() { ...@@ -92,9 +90,9 @@ void main() {
await tester.pumpWidget(_withTheme(tabBarTheme)); await tester.pumpWidget(_withTheme(tabBarTheme));
final RenderParagraph textRenderObject = tester.renderObject<RenderParagraph>(find.text(_tab1Text)); final RenderParagraph textRenderObject = tester.renderObject<RenderParagraph>(find.text(_tab1Text));
expect(textRenderObject.text.style.color, equals(labelColor)); expect(textRenderObject.text.style!.color, equals(labelColor));
final RenderParagraph iconRenderObject = _iconRenderObject(tester, Icons.looks_one); final RenderParagraph iconRenderObject = _iconRenderObject(tester, Icons.looks_one);
expect(iconRenderObject.text.style.color, equals(labelColor)); expect(iconRenderObject.text.style!.color, equals(labelColor));
}); });
testWidgets('Tab bar theme overrides label padding', (WidgetTester tester) async { testWidgets('Tab bar theme overrides label padding', (WidgetTester tester) async {
...@@ -117,8 +115,8 @@ void main() { ...@@ -117,8 +115,8 @@ void main() {
)); ));
final Rect tabBar = tester.getRect(find.byType(TabBar)); final Rect tabBar = tester.getRect(find.byType(TabBar));
final Rect tabOneRect = tester.getRect(find.byKey(_sizedTabs[0].key)); final Rect tabOneRect = tester.getRect(find.byKey(_sizedTabs[0].key!));
final Rect tabTwoRect = tester.getRect(find.byKey(_sizedTabs[1].key)); final Rect tabTwoRect = tester.getRect(find.byKey(_sizedTabs[1].key!));
// verify coordinates of tabOne // verify coordinates of tabOne
expect(tabOneRect.left, equals(leftPadding)); expect(tabOneRect.left, equals(leftPadding));
...@@ -145,9 +143,9 @@ void main() { ...@@ -145,9 +143,9 @@ void main() {
await tester.pumpWidget(_withTheme(tabBarTheme)); await tester.pumpWidget(_withTheme(tabBarTheme));
final RenderParagraph selectedRenderObject = tester.renderObject<RenderParagraph>(find.text(_tab1Text)); final RenderParagraph selectedRenderObject = tester.renderObject<RenderParagraph>(find.text(_tab1Text));
expect(selectedRenderObject.text.style.fontFamily, equals(labelStyle.fontFamily)); expect(selectedRenderObject.text.style!.fontFamily, equals(labelStyle.fontFamily));
final RenderParagraph unselectedRenderObject = tester.renderObject<RenderParagraph>(find.text(_tab2Text)); final RenderParagraph unselectedRenderObject = tester.renderObject<RenderParagraph>(find.text(_tab2Text));
expect(unselectedRenderObject.text.style.fontFamily, equals(unselectedLabelStyle.fontFamily)); expect(unselectedRenderObject.text.style!.fontFamily, equals(unselectedLabelStyle.fontFamily));
}); });
testWidgets('Tab bar theme with just label style specified', (WidgetTester tester) async { testWidgets('Tab bar theme with just label style specified', (WidgetTester tester) async {
...@@ -160,11 +158,11 @@ void main() { ...@@ -160,11 +158,11 @@ void main() {
await tester.pumpWidget(_withTheme(tabBarTheme)); await tester.pumpWidget(_withTheme(tabBarTheme));
final RenderParagraph selectedRenderObject = tester.renderObject<RenderParagraph>(find.text(_tab1Text)); final RenderParagraph selectedRenderObject = tester.renderObject<RenderParagraph>(find.text(_tab1Text));
expect(selectedRenderObject.text.style.fontFamily, equals(labelStyle.fontFamily)); expect(selectedRenderObject.text.style!.fontFamily, equals(labelStyle.fontFamily));
final RenderParagraph unselectedRenderObject = tester.renderObject<RenderParagraph>(find.text(_tab2Text)); final RenderParagraph unselectedRenderObject = tester.renderObject<RenderParagraph>(find.text(_tab2Text));
expect(unselectedRenderObject.text.style.fontFamily, equals('Roboto')); expect(unselectedRenderObject.text.style!.fontFamily, equals('Roboto'));
expect(unselectedRenderObject.text.style.fontSize, equals(14.0)); expect(unselectedRenderObject.text.style!.fontSize, equals(14.0));
expect(unselectedRenderObject.text.style.color, equals(Colors.white.withAlpha(0xB2))); expect(unselectedRenderObject.text.style!.color, equals(Colors.white.withAlpha(0xB2)));
}); });
testWidgets('Tab bar label styles override theme label styles', (WidgetTester tester) async { testWidgets('Tab bar label styles override theme label styles', (WidgetTester tester) async {
...@@ -191,9 +189,9 @@ void main() { ...@@ -191,9 +189,9 @@ void main() {
); );
final RenderParagraph selectedRenderObject = tester.renderObject<RenderParagraph>(find.text(_tab1Text)); final RenderParagraph selectedRenderObject = tester.renderObject<RenderParagraph>(find.text(_tab1Text));
expect(selectedRenderObject.text.style.fontFamily, equals(labelStyle.fontFamily)); expect(selectedRenderObject.text.style!.fontFamily, equals(labelStyle.fontFamily));
final RenderParagraph unselectedRenderObject = tester.renderObject<RenderParagraph>(find.text(_tab2Text)); final RenderParagraph unselectedRenderObject = tester.renderObject<RenderParagraph>(find.text(_tab2Text));
expect(unselectedRenderObject.text.style.fontFamily, equals(unselectedLabelStyle.fontFamily)); expect(unselectedRenderObject.text.style!.fontFamily, equals(unselectedLabelStyle.fontFamily));
}); });
testWidgets('Tab bar label padding overrides theme label padding', (WidgetTester tester) async { testWidgets('Tab bar label padding overrides theme label padding', (WidgetTester tester) async {
...@@ -233,8 +231,8 @@ void main() { ...@@ -233,8 +231,8 @@ void main() {
); );
final Rect tabBar = tester.getRect(find.byType(TabBar)); final Rect tabBar = tester.getRect(find.byType(TabBar));
final Rect tabOneRect = tester.getRect(find.byKey(_sizedTabs[0].key)); final Rect tabOneRect = tester.getRect(find.byKey(_sizedTabs[0].key!));
final Rect tabTwoRect = tester.getRect(find.byKey(_sizedTabs[1].key)); final Rect tabTwoRect = tester.getRect(find.byKey(_sizedTabs[1].key!));
// verify coordinates of tabOne // verify coordinates of tabOne
expect(tabOneRect.left, equals(horizontalPadding)); expect(tabOneRect.left, equals(horizontalPadding));
...@@ -257,9 +255,9 @@ void main() { ...@@ -257,9 +255,9 @@ void main() {
await tester.pumpWidget(_withTheme(tabBarTheme)); await tester.pumpWidget(_withTheme(tabBarTheme));
final RenderParagraph textRenderObject = tester.renderObject<RenderParagraph>(find.text(_tab2Text)); final RenderParagraph textRenderObject = tester.renderObject<RenderParagraph>(find.text(_tab2Text));
expect(textRenderObject.text.style.color, equals(unselectedLabelColor)); expect(textRenderObject.text.style!.color, equals(unselectedLabelColor));
final RenderParagraph iconRenderObject = _iconRenderObject(tester, Icons.looks_two); final RenderParagraph iconRenderObject = _iconRenderObject(tester, Icons.looks_two);
expect(iconRenderObject.text.style.color, equals(unselectedLabelColor)); expect(iconRenderObject.text.style!.color, equals(unselectedLabelColor));
}); });
testWidgets('Tab bar theme overrides tab indicator size (tab)', (WidgetTester tester) async { testWidgets('Tab bar theme overrides tab indicator size (tab)', (WidgetTester tester) async {
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
...@@ -26,7 +24,7 @@ class MySliverPersistentHeaderDelegate extends SliverPersistentHeaderDelegate { ...@@ -26,7 +24,7 @@ class MySliverPersistentHeaderDelegate extends SliverPersistentHeaderDelegate {
} }
class MyHomePage extends StatefulWidget { class MyHomePage extends StatefulWidget {
const MyHomePage({ Key key }) : super(key: key); const MyHomePage({ Key? key }) : super(key: key);
@override @override
_MyHomePageState createState() => _MyHomePageState(); _MyHomePageState createState() => _MyHomePageState();
...@@ -34,7 +32,7 @@ class MyHomePage extends StatefulWidget { ...@@ -34,7 +32,7 @@ class MyHomePage extends StatefulWidget {
class _MyHomePageState extends State<MyHomePage> with TickerProviderStateMixin { class _MyHomePageState extends State<MyHomePage> with TickerProviderStateMixin {
static const int tabCount = 3; static const int tabCount = 3;
TabController tabController; late TabController tabController;
@override @override
void initState() { void initState() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment