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 '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