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