Unverified Commit b93f71f9 authored by Justin McCandless's avatar Justin McCandless Committed by GitHub

NNDB TextField tests (#67696)

Just another nnbd conversion PR.
parent 23c7ee9d
...@@ -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
@TestOn('!chrome') // This whole test suite needs triage. @TestOn('!chrome') // This whole test suite needs triage.
import 'dart:math' as math; import 'dart:math' as math;
import 'dart:ui' as ui show window, BoxHeightStyle, BoxWidthStyle; import 'dart:ui' as ui show window, BoxHeightStyle, BoxWidthStyle;
...@@ -31,7 +29,7 @@ class MockClipboard { ...@@ -31,7 +29,7 @@ class MockClipboard {
case 'Clipboard.getData': case 'Clipboard.getData':
return _clipboardData; return _clipboardData;
case 'Clipboard.setData': case 'Clipboard.setData':
_clipboardData = methodCall.arguments; _clipboardData = methodCall.arguments as Object;
break; break;
} }
} }
...@@ -59,7 +57,7 @@ class WidgetsLocalizationsDelegate extends LocalizationsDelegate<WidgetsLocaliza ...@@ -59,7 +57,7 @@ class WidgetsLocalizationsDelegate extends LocalizationsDelegate<WidgetsLocaliza
bool shouldReload(WidgetsLocalizationsDelegate old) => false; bool shouldReload(WidgetsLocalizationsDelegate old) => false;
} }
Widget overlay({ Widget child }) { Widget overlay({ required Widget child }) {
final OverlayEntry entry = OverlayEntry( final OverlayEntry entry = OverlayEntry(
builder: (BuildContext context) { builder: (BuildContext context) {
return Center( return Center(
...@@ -93,7 +91,7 @@ Widget overlayWithEntry(OverlayEntry entry) { ...@@ -93,7 +91,7 @@ Widget overlayWithEntry(OverlayEntry entry) {
); );
} }
Widget boilerplate({ Widget child }) { Widget boilerplate({ required Widget child }) {
return MaterialApp( return MaterialApp(
home: Localizations( home: Localizations(
locale: const Locale('en', 'US'), locale: const Locale('en', 'US'),
...@@ -154,8 +152,8 @@ void main() { ...@@ -154,8 +152,8 @@ void main() {
final Key textFieldKey = UniqueKey(); final Key textFieldKey = UniqueKey();
Widget textFieldBuilder({ Widget textFieldBuilder({
int maxLines = 1, int? maxLines = 1,
int minLines, int? minLines,
}) { }) {
return boilerplate( return boilerplate(
child: TextField( child: TextField(
...@@ -192,7 +190,7 @@ void main() { ...@@ -192,7 +190,7 @@ void main() {
testWidgets('TextField has consistent size', (WidgetTester tester) async { testWidgets('TextField has consistent size', (WidgetTester tester) async {
final Key textFieldKey = UniqueKey(); final Key textFieldKey = UniqueKey();
String textFieldValue; late String textFieldValue;
await tester.pumpWidget( await tester.pumpWidget(
overlay( overlay(
...@@ -288,24 +286,24 @@ void main() { ...@@ -288,24 +286,24 @@ void main() {
final EditableTextState editableTextState = tester.firstState(find.byType(EditableText)); final EditableTextState editableTextState = tester.firstState(find.byType(EditableText));
final RenderEditable renderEditable = editableTextState.renderEditable; final RenderEditable renderEditable = editableTextState.renderEditable;
expect(renderEditable.cursorColor.alpha, 255); expect(renderEditable.cursorColor!.alpha, 255);
await tester.pump(const Duration(milliseconds: 100)); await tester.pump(const Duration(milliseconds: 100));
await tester.pump(const Duration(milliseconds: 400)); await tester.pump(const Duration(milliseconds: 400));
expect(renderEditable.cursorColor.alpha, 255); expect(renderEditable.cursorColor!.alpha, 255);
await tester.pump(const Duration(milliseconds: 200)); await tester.pump(const Duration(milliseconds: 200));
await tester.pump(const Duration(milliseconds: 100)); await tester.pump(const Duration(milliseconds: 100));
expect(renderEditable.cursorColor.alpha, 110); expect(renderEditable.cursorColor!.alpha, 110);
await tester.pump(const Duration(milliseconds: 100)); await tester.pump(const Duration(milliseconds: 100));
expect(renderEditable.cursorColor.alpha, 16); expect(renderEditable.cursorColor!.alpha, 16);
await tester.pump(const Duration(milliseconds: 50)); await tester.pump(const Duration(milliseconds: 50));
expect(renderEditable.cursorColor.alpha, 0); expect(renderEditable.cursorColor!.alpha, 0);
}, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS })); }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
testWidgets('Cursor radius is 2.0', (WidgetTester tester) async { testWidgets('Cursor radius is 2.0', (WidgetTester tester) async {
...@@ -400,7 +398,7 @@ void main() { ...@@ -400,7 +398,7 @@ void main() {
await expectLater( await expectLater(
find.byKey(const ValueKey<int>(1)), find.byKey(const ValueKey<int>(1)),
matchesGoldenFile( matchesGoldenFile(
'text_field_cursor_test_${describeEnum(debugDefaultTargetPlatformOverride).toLowerCase()}.material.1.png', 'text_field_cursor_test_${describeEnum(debugDefaultTargetPlatformOverride!).toLowerCase()}.material.1.png',
), ),
); );
}, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS })); }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
...@@ -812,12 +810,12 @@ void main() { ...@@ -812,12 +810,12 @@ void main() {
await tester.pump(); await tester.pump();
String editText = findRenderEditable(tester).text.text; String editText = findRenderEditable(tester).text!.text!;
expect(editText.substring(editText.length - 1), newChar); expect(editText.substring(editText.length - 1), newChar);
await tester.pump(const Duration(seconds: 2)); await tester.pump(const Duration(seconds: 2));
editText = findRenderEditable(tester).text.text; editText = findRenderEditable(tester).text!.text!;
expect(editText.substring(editText.length - 1), '\u2022'); expect(editText.substring(editText.length - 1), '\u2022');
}, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.android })); }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.android }));
...@@ -852,7 +850,7 @@ void main() { ...@@ -852,7 +850,7 @@ void main() {
await tester.pump(); await tester.pump();
final String editText = findRenderEditable(tester).text.text; final String editText = findRenderEditable(tester).text!.text!;
expect(editText.substring(editText.length - 1), '\u2022'); expect(editText.substring(editText.length - 1), '\u2022');
}, variant: const TargetPlatformVariant(<TargetPlatform>{ }, variant: const TargetPlatformVariant(<TargetPlatform>{
TargetPlatform.macOS, TargetPlatform.macOS,
...@@ -1105,7 +1103,7 @@ void main() { ...@@ -1105,7 +1103,7 @@ void main() {
expect(tester.testTextInput.hasAnyClients, false); expect(tester.testTextInput.hasAnyClients, false);
final EditableTextState editableText = tester.state(find.byType(EditableText)); final EditableTextState editableText = tester.state(find.byType(EditableText));
// Collapse selection should not paint. // Collapse selection should not paint.
expect(editableText.selectionOverlay.handlesAreVisible, isFalse); expect(editableText.selectionOverlay!.handlesAreVisible, isFalse);
// Long press on the 'd' character of text 'readOnly' to show context menu. // Long press on the 'd' character of text 'readOnly' to show context menu.
const int dIndex = 3; const int dIndex = 3;
final Offset dPos = textOffsetToPosition(tester, dIndex); final Offset dPos = textOffsetToPosition(tester, dIndex);
...@@ -1184,7 +1182,7 @@ void main() { ...@@ -1184,7 +1182,7 @@ void main() {
await tester.pumpAndSettle(); await tester.pumpAndSettle();
final EditableTextState state = tester.state(find.byType(EditableText)); final EditableTextState state = tester.state(find.byType(EditableText));
TextSelection currentOverlaySelection = TextSelection currentOverlaySelection =
state.selectionOverlay.value.selection; state.selectionOverlay!.value.selection;
expect(currentOverlaySelection.baseOffset, 0); expect(currentOverlaySelection.baseOffset, 0);
expect(currentOverlaySelection.extentOffset, 8); expect(currentOverlaySelection.extentOffset, 8);
...@@ -1200,7 +1198,7 @@ void main() { ...@@ -1200,7 +1198,7 @@ void main() {
entry.markNeedsBuild(); entry.markNeedsBuild();
await tester.pump(); await tester.pump();
currentOverlaySelection = state.selectionOverlay.value.selection; currentOverlaySelection = state.selectionOverlay!.value.selection;
expect(currentOverlaySelection.baseOffset, 1); expect(currentOverlaySelection.baseOffset, 1);
expect(currentOverlaySelection.extentOffset, 7); expect(currentOverlaySelection.extentOffset, 7);
}); });
...@@ -1224,7 +1222,7 @@ void main() { ...@@ -1224,7 +1222,7 @@ void main() {
final RenderEditable renderEditable = findRenderEditable(tester); final RenderEditable renderEditable = findRenderEditable(tester);
// There should be no composing. // There should be no composing.
expect(renderEditable.text, TextSpan(text:'readonly', style: renderEditable.text.style)); expect(renderEditable.text, TextSpan(text:'readonly', style: renderEditable.text!.style));
}); });
testWidgets('Dynamically switching between read only and not read only should hide or show collapse cursor', (WidgetTester tester) async { testWidgets('Dynamically switching between read only and not read only should hide or show collapse cursor', (WidgetTester tester) async {
...@@ -1248,18 +1246,18 @@ void main() { ...@@ -1248,18 +1246,18 @@ void main() {
final EditableTextState editableText = tester.state(find.byType(EditableText)); final EditableTextState editableText = tester.state(find.byType(EditableText));
// Collapse selection should not paint. // Collapse selection should not paint.
expect(editableText.selectionOverlay.handlesAreVisible, isFalse); expect(editableText.selectionOverlay!.handlesAreVisible, isFalse);
readOnly = false; readOnly = false;
// Mark entry to be dirty in order to trigger overlay update. // Mark entry to be dirty in order to trigger overlay update.
entry.markNeedsBuild(); entry.markNeedsBuild();
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(editableText.selectionOverlay.handlesAreVisible, isTrue); expect(editableText.selectionOverlay!.handlesAreVisible, isTrue);
readOnly = true; readOnly = true;
entry.markNeedsBuild(); entry.markNeedsBuild();
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(editableText.selectionOverlay.handlesAreVisible, isFalse); expect(editableText.selectionOverlay!.handlesAreVisible, isFalse);
}); });
testWidgets('Dynamically switching to read only should close input connection', (WidgetTester tester) async { testWidgets('Dynamically switching to read only should close input connection', (WidgetTester tester) async {
...@@ -1854,13 +1852,12 @@ void main() { ...@@ -1854,13 +1852,12 @@ void main() {
// Toolbar should fade in. Starting at 0% opacity. // Toolbar should fade in. Starting at 0% opacity.
final Element target = tester.element(find.text('Select all')); final Element target = tester.element(find.text('Select all'));
final FadeTransition opacity = target.findAncestorWidgetOfExactType<FadeTransition>(); final FadeTransition opacity = target.findAncestorWidgetOfExactType<FadeTransition>()!;
expect(opacity, isNotNull);
expect(opacity.opacity.value, equals(0.0)); expect(opacity.opacity.value, equals(0.0));
// Still fading in. // Still fading in.
await tester.pump(const Duration(milliseconds: 50)); await tester.pump(const Duration(milliseconds: 50));
final FadeTransition opacity2 = target.findAncestorWidgetOfExactType<FadeTransition>(); final FadeTransition opacity2 = target.findAncestorWidgetOfExactType<FadeTransition>()!;
expect(opacity, same(opacity2)); expect(opacity, same(opacity2));
expect(opacity.opacity.value, greaterThan(0.0)); expect(opacity.opacity.value, greaterThan(0.0));
expect(opacity.opacity.value, lessThan(1.0)); expect(opacity.opacity.value, lessThan(1.0));
...@@ -2098,8 +2095,8 @@ void main() { ...@@ -2098,8 +2095,8 @@ void main() {
testWidgets('Multiline text when wrapped in Expanded', (WidgetTester tester) async { testWidgets('Multiline text when wrapped in Expanded', (WidgetTester tester) async {
Widget expandedTextFieldBuilder({ Widget expandedTextFieldBuilder({
int maxLines = 1, int? maxLines = 1,
int minLines, int? minLines,
bool expands = false, bool expands = false,
}) { }) {
return boilerplate( return boilerplate(
...@@ -2191,7 +2188,7 @@ void main() { ...@@ -2191,7 +2188,7 @@ void main() {
// Regression test for https://github.com/flutter/flutter/pull/29093 // Regression test for https://github.com/flutter/flutter/pull/29093
testWidgets('errorText empty string', (WidgetTester tester) async { testWidgets('errorText empty string', (WidgetTester tester) async {
Widget textFormFieldBuilder(String errorText) { Widget textFormFieldBuilder(String? errorText) {
return boilerplate( return boilerplate(
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
...@@ -2240,10 +2237,10 @@ void main() { ...@@ -2240,10 +2237,10 @@ void main() {
const double padding = 24.0; const double padding = 24.0;
Widget containedTextFieldBuilder({ Widget containedTextFieldBuilder({
Widget counter, Widget? counter,
String helperText, String? helperText,
String labelText, String? labelText,
Widget prefix, Widget? prefix,
}) { }) {
return boilerplate( return boilerplate(
child: Container( child: Container(
...@@ -2346,7 +2343,7 @@ void main() { ...@@ -2346,7 +2343,7 @@ void main() {
testWidgets('Multiline hint text will wrap up to maxLines', (WidgetTester tester) async { testWidgets('Multiline hint text will wrap up to maxLines', (WidgetTester tester) async {
final Key textFieldKey = UniqueKey(); final Key textFieldKey = UniqueKey();
Widget builder(int maxLines, final String hintMsg) { Widget builder(int? maxLines, final String hintMsg) {
return boilerplate( return boilerplate(
child: TextField( child: TextField(
key: textFieldKey, key: textFieldKey,
...@@ -2562,7 +2559,7 @@ void main() { ...@@ -2562,7 +2559,7 @@ void main() {
}); });
testWidgets('TextField smoke test', (WidgetTester tester) async { testWidgets('TextField smoke test', (WidgetTester tester) async {
String textFieldValue; late String textFieldValue;
await tester.pumpWidget( await tester.pumpWidget(
overlay( overlay(
...@@ -2591,7 +2588,7 @@ void main() { ...@@ -2591,7 +2588,7 @@ void main() {
testWidgets('TextField with global key', (WidgetTester tester) async { testWidgets('TextField with global key', (WidgetTester tester) async {
final GlobalKey textFieldKey = GlobalKey(debugLabel: 'textFieldKey'); final GlobalKey textFieldKey = GlobalKey(debugLabel: 'textFieldKey');
String textFieldValue; late String textFieldValue;
await tester.pumpWidget( await tester.pumpWidget(
overlay( overlay(
...@@ -2649,8 +2646,8 @@ void main() { ...@@ -2649,8 +2646,8 @@ void main() {
), ),
); );
final Text helperText = tester.widget(find.text('helper text')); final Text helperText = tester.widget(find.text('helper text'));
expect(helperText.style.color, themeData.hintColor); expect(helperText.style!.color, themeData.hintColor);
expect(helperText.style.fontSize, Typography.englishLike2014.caption.fontSize); expect(helperText.style!.fontSize, Typography.englishLike2014.caption!.fontSize);
}); });
testWidgets('TextField with specified helperStyle', (WidgetTester tester) async { testWidgets('TextField with specified helperStyle', (WidgetTester tester) async {
...@@ -2698,8 +2695,8 @@ void main() { ...@@ -2698,8 +2695,8 @@ void main() {
); );
final Text hintText = tester.widget(find.text('Placeholder')); final Text hintText = tester.widget(find.text('Placeholder'));
expect(hintText.style.color, themeData.hintColor); expect(hintText.style!.color, themeData.hintColor);
expect(hintText.style.fontSize, style.fontSize); expect(hintText.style!.fontSize, style.fontSize);
}); });
testWidgets('TextField with specified hintStyle', (WidgetTester tester) async { testWidgets('TextField with specified hintStyle', (WidgetTester tester) async {
...@@ -3088,8 +3085,8 @@ void main() { ...@@ -3088,8 +3085,8 @@ void main() {
text: 'More Text', text: 'More Text',
); );
TextEditingController currentController; TextEditingController? currentController;
StateSetter setState; late StateSetter setState;
await tester.pumpWidget( await tester.pumpWidget(
overlay( overlay(
...@@ -3106,61 +3103,61 @@ void main() { ...@@ -3106,61 +3103,61 @@ void main() {
// Initial state with null controller. // Initial state with null controller.
await tester.tap(find.byType(TextField)); await tester.tap(find.byType(TextField));
await tester.pump(); await tester.pump();
expect(tester.testTextInput.editingState['text'], isEmpty); expect(tester.testTextInput.editingState!['text'], isEmpty);
// Update the controller from null to controller1. // Update the controller from null to controller1.
setState(() { setState(() {
currentController = controller1; currentController = controller1;
}); });
await tester.pump(); await tester.pump();
expect(tester.testTextInput.editingState['text'], equals('Initial Text')); expect(tester.testTextInput.editingState!['text'], equals('Initial Text'));
// Verify that updates to controller1 are handled. // Verify that updates to controller1 are handled.
controller1.text = 'Updated Text'; controller1.text = 'Updated Text';
await tester.idle(); await tester.idle();
expect(tester.testTextInput.editingState['text'], equals('Updated Text')); expect(tester.testTextInput.editingState!['text'], equals('Updated Text'));
// Verify that switching from controller1 to controller2 is handled. // Verify that switching from controller1 to controller2 is handled.
setState(() { setState(() {
currentController = controller2; currentController = controller2;
}); });
await tester.pump(); await tester.pump();
expect(tester.testTextInput.editingState['text'], equals('More Text')); expect(tester.testTextInput.editingState!['text'], equals('More Text'));
// Verify that updates to controller1 are ignored. // Verify that updates to controller1 are ignored.
controller1.text = 'Ignored Text'; controller1.text = 'Ignored Text';
await tester.idle(); await tester.idle();
expect(tester.testTextInput.editingState['text'], equals('More Text')); expect(tester.testTextInput.editingState!['text'], equals('More Text'));
// Verify that updates to controller text are handled. // Verify that updates to controller text are handled.
controller2.text = 'Additional Text'; controller2.text = 'Additional Text';
await tester.idle(); await tester.idle();
expect(tester.testTextInput.editingState['text'], equals('Additional Text')); expect(tester.testTextInput.editingState!['text'], equals('Additional Text'));
// Verify that updates to controller selection are handled. // Verify that updates to controller selection are handled.
controller2.selection = const TextSelection(baseOffset: 0, extentOffset: 5); controller2.selection = const TextSelection(baseOffset: 0, extentOffset: 5);
await tester.idle(); await tester.idle();
expect(tester.testTextInput.editingState['selectionBase'], equals(0)); expect(tester.testTextInput.editingState!['selectionBase'], equals(0));
expect(tester.testTextInput.editingState['selectionExtent'], equals(5)); expect(tester.testTextInput.editingState!['selectionExtent'], equals(5));
// Verify that calling clear() clears the text. // Verify that calling clear() clears the text.
controller2.clear(); controller2.clear();
await tester.idle(); await tester.idle();
expect(tester.testTextInput.editingState['text'], equals('')); expect(tester.testTextInput.editingState!['text'], equals(''));
// Verify that switching from controller2 to null preserves current text. // Verify that switching from controller2 to null preserves current text.
controller2.text = 'The Final Cut'; controller2.text = 'The Final Cut';
await tester.idle(); await tester.idle();
expect(tester.testTextInput.editingState['text'], equals('The Final Cut')); expect(tester.testTextInput.editingState!['text'], equals('The Final Cut'));
setState(() { setState(() {
currentController = null; currentController = null;
}); });
await tester.pump(); await tester.pump();
expect(tester.testTextInput.editingState['text'], equals('The Final Cut')); expect(tester.testTextInput.editingState!['text'], equals('The Final Cut'));
// Verify that changes to controller2 are ignored. // Verify that changes to controller2 are ignored.
controller2.text = 'Goodbye Cruel World'; controller2.text = 'Goodbye Cruel World';
expect(tester.testTextInput.editingState['text'], equals('The Final Cut')); expect(tester.testTextInput.editingState!['text'], equals('The Final Cut'));
}); });
testWidgets('Cannot enter new lines onto single line TextField', (WidgetTester tester) async { testWidgets('Cannot enter new lines onto single line TextField', (WidgetTester tester) async {
...@@ -3482,13 +3479,12 @@ void main() { ...@@ -3482,13 +3479,12 @@ void main() {
expect(controller.selection.start, lessThanOrEqualTo(0)); expect(controller.selection.start, lessThanOrEqualTo(0));
expect(controller.selection.end, lessThanOrEqualTo(0)); expect(controller.selection.end, lessThanOrEqualTo(0));
FlutterError error; late FlutterError error;
try { try {
controller.selection = const TextSelection.collapsed(offset: 10); controller.selection = const TextSelection.collapsed(offset: 10);
} on FlutterError catch (e) { } on FlutterError catch (e) {
error = e; error = e;
} finally { } finally {
expect(error, isNotNull);
expect(error.diagnostics.length, 1); expect(error.diagnostics.length, 1);
expect( expect(
error.toStringDeep(), error.toStringDeep(),
...@@ -3686,7 +3682,7 @@ void main() { ...@@ -3686,7 +3682,7 @@ void main() {
expect(textController.text, '0123456789101112'); expect(textController.text, '0123456789101112');
expect(find.text('16/10'), findsOneWidget); expect(find.text('16/10'), findsOneWidget);
Text counterTextWidget = tester.widget(find.text('16/10')); Text counterTextWidget = tester.widget(find.text('16/10'));
expect(counterTextWidget.style.color, equals(Colors.deepPurpleAccent)); expect(counterTextWidget.style!.color, equals(Colors.deepPurpleAccent));
await tester.enterText(find.byType(TextField), '0123456789'); await tester.enterText(find.byType(TextField), '0123456789');
await tester.pump(); await tester.pump();
...@@ -3694,7 +3690,7 @@ void main() { ...@@ -3694,7 +3690,7 @@ void main() {
expect(textController.text, '0123456789'); expect(textController.text, '0123456789');
expect(find.text('10/10'), findsOneWidget); expect(find.text('10/10'), findsOneWidget);
counterTextWidget = tester.widget(find.text('10/10')); counterTextWidget = tester.widget(find.text('10/10'));
expect(counterTextWidget.style.color, isNot(equals(Colors.deepPurpleAccent))); expect(counterTextWidget.style!.color, isNot(equals(Colors.deepPurpleAccent)));
}); });
testWidgets('maxLength shows warning when maxLengthEnforced is false with surrogate pairs.', (WidgetTester tester) async { testWidgets('maxLength shows warning when maxLengthEnforced is false with surrogate pairs.', (WidgetTester tester) async {
...@@ -3716,7 +3712,7 @@ void main() { ...@@ -3716,7 +3712,7 @@ void main() {
expect(textController.text, '😆012345678910111'); expect(textController.text, '😆012345678910111');
expect(find.text('16/10'), findsOneWidget); expect(find.text('16/10'), findsOneWidget);
Text counterTextWidget = tester.widget(find.text('16/10')); Text counterTextWidget = tester.widget(find.text('16/10'));
expect(counterTextWidget.style.color, equals(Colors.deepPurpleAccent)); expect(counterTextWidget.style!.color, equals(Colors.deepPurpleAccent));
await tester.enterText(find.byType(TextField), '😆012345678'); await tester.enterText(find.byType(TextField), '😆012345678');
await tester.pump(); await tester.pump();
...@@ -3724,7 +3720,7 @@ void main() { ...@@ -3724,7 +3720,7 @@ void main() {
expect(textController.text, '😆012345678'); expect(textController.text, '😆012345678');
expect(find.text('10/10'), findsOneWidget); expect(find.text('10/10'), findsOneWidget);
counterTextWidget = tester.widget(find.text('10/10')); counterTextWidget = tester.widget(find.text('10/10'));
expect(counterTextWidget.style.color, isNot(equals(Colors.deepPurpleAccent))); expect(counterTextWidget.style!.color, isNot(equals(Colors.deepPurpleAccent)));
}); });
testWidgets('maxLength shows warning when maxLengthEnforced is false with grapheme clusters.', (WidgetTester tester) async { testWidgets('maxLength shows warning when maxLengthEnforced is false with grapheme clusters.', (WidgetTester tester) async {
...@@ -3746,7 +3742,7 @@ void main() { ...@@ -3746,7 +3742,7 @@ void main() {
expect(textController.text, '👨‍👩‍👦012345678910111'); expect(textController.text, '👨‍👩‍👦012345678910111');
expect(find.text('16/10'), findsOneWidget); expect(find.text('16/10'), findsOneWidget);
Text counterTextWidget = tester.widget(find.text('16/10')); Text counterTextWidget = tester.widget(find.text('16/10'));
expect(counterTextWidget.style.color, equals(Colors.deepPurpleAccent)); expect(counterTextWidget.style!.color, equals(Colors.deepPurpleAccent));
await tester.enterText(find.byType(TextField), '👨‍👩‍👦012345678'); await tester.enterText(find.byType(TextField), '👨‍👩‍👦012345678');
await tester.pump(); await tester.pump();
...@@ -3754,7 +3750,7 @@ void main() { ...@@ -3754,7 +3750,7 @@ void main() {
expect(textController.text, '👨‍👩‍👦012345678'); expect(textController.text, '👨‍👩‍👦012345678');
expect(find.text('10/10'), findsOneWidget); expect(find.text('10/10'), findsOneWidget);
counterTextWidget = tester.widget(find.text('10/10')); counterTextWidget = tester.widget(find.text('10/10'));
expect(counterTextWidget.style.color, isNot(equals(Colors.deepPurpleAccent))); expect(counterTextWidget.style!.color, isNot(equals(Colors.deepPurpleAccent)));
}); });
testWidgets('maxLength limits input with surrogate pairs.', (WidgetTester tester) async { testWidgets('maxLength limits input with surrogate pairs.', (WidgetTester tester) async {
...@@ -3874,7 +3870,7 @@ void main() { ...@@ -3874,7 +3870,7 @@ void main() {
home: Material( home: Material(
child: Center( child: Center(
child: TextField( child: TextField(
buildCounter: (BuildContext context, { int currentLength, int maxLength, bool isFocused }) { buildCounter: (BuildContext context, { required int currentLength, int? maxLength, required bool isFocused }) {
return Text('${currentLength.toString()} of ${maxLength.toString()}'); return Text('${currentLength.toString()} of ${maxLength.toString()}');
}, },
maxLength: 10, maxLength: 10,
...@@ -3958,25 +3954,25 @@ void main() { ...@@ -3958,25 +3954,25 @@ void main() {
await tester.pumpWidget(buildFrame(true, false)); await tester.pumpWidget(buildFrame(true, false));
Text helperWidget = tester.widget(find.text(helperText)); Text helperWidget = tester.widget(find.text(helperText));
Text counterWidget = tester.widget(find.text(counterText)); Text counterWidget = tester.widget(find.text(counterText));
expect(helperWidget.style.color, isNot(equals(Colors.transparent))); expect(helperWidget.style!.color, isNot(equals(Colors.transparent)));
expect(counterWidget.style.color, isNot(equals(Colors.transparent))); expect(counterWidget.style!.color, isNot(equals(Colors.transparent)));
await tester.pumpWidget(buildFrame(true, true)); await tester.pumpWidget(buildFrame(true, true));
counterWidget = tester.widget(find.text(counterText)); counterWidget = tester.widget(find.text(counterText));
Text errorWidget = tester.widget(find.text(errorText)); Text errorWidget = tester.widget(find.text(errorText));
expect(helperWidget.style.color, isNot(equals(Colors.transparent))); expect(helperWidget.style!.color, isNot(equals(Colors.transparent)));
expect(errorWidget.style.color, isNot(equals(Colors.transparent))); expect(errorWidget.style!.color, isNot(equals(Colors.transparent)));
// When enabled is false, the helper/error and counter are not visible. // When enabled is false, the helper/error and counter are not visible.
await tester.pumpWidget(buildFrame(false, false)); await tester.pumpWidget(buildFrame(false, false));
helperWidget = tester.widget(find.text(helperText)); helperWidget = tester.widget(find.text(helperText));
counterWidget = tester.widget(find.text(counterText)); counterWidget = tester.widget(find.text(counterText));
expect(helperWidget.style.color, equals(Colors.transparent)); expect(helperWidget.style!.color, equals(Colors.transparent));
expect(counterWidget.style.color, equals(Colors.transparent)); expect(counterWidget.style!.color, equals(Colors.transparent));
await tester.pumpWidget(buildFrame(false, true)); await tester.pumpWidget(buildFrame(false, true));
errorWidget = tester.widget(find.text(errorText)); errorWidget = tester.widget(find.text(errorText));
counterWidget = tester.widget(find.text(counterText)); counterWidget = tester.widget(find.text(counterText));
expect(counterWidget.style.color, equals(Colors.transparent)); expect(counterWidget.style!.color, equals(Colors.transparent));
expect(errorWidget.style.color, equals(Colors.transparent)); expect(errorWidget.style!.color, equals(Colors.transparent));
}); });
testWidgets('currentValueLength/maxValueLength are in the tree', (WidgetTester tester) async { testWidgets('currentValueLength/maxValueLength are in the tree', (WidgetTester tester) async {
...@@ -4083,7 +4079,7 @@ void main() { ...@@ -4083,7 +4079,7 @@ void main() {
}); });
group('Keyboard Tests', () { group('Keyboard Tests', () {
TextEditingController controller; late TextEditingController controller;
setUp( () { setUp( () {
controller = TextEditingController(); controller = TextEditingController();
...@@ -4644,7 +4640,6 @@ void main() { ...@@ -4644,7 +4640,6 @@ void main() {
), ),
); );
const String testValue = 'a big house'; const String testValue = 'a big house';
await tester.enterText(find.byType(TextField).first, testValue); await tester.enterText(find.byType(TextField).first, testValue);
await tester.idle(); await tester.idle();
...@@ -5170,7 +5165,7 @@ void main() { ...@@ -5170,7 +5165,7 @@ void main() {
testWidgets('TextField change selection with semantics', (WidgetTester tester) async { testWidgets('TextField change selection with semantics', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester); final SemanticsTester semantics = SemanticsTester(tester);
final SemanticsOwner semanticsOwner = tester.binding.pipelineOwner.semanticsOwner; final SemanticsOwner semanticsOwner = tester.binding.pipelineOwner.semanticsOwner!;
final TextEditingController controller = TextEditingController() final TextEditingController controller = TextEditingController()
..text = 'Hello'; ..text = 'Hello';
final Key key = UniqueKey(); final Key key = UniqueKey();
...@@ -5269,7 +5264,7 @@ void main() { ...@@ -5269,7 +5264,7 @@ void main() {
const String textInTextField = 'Hello'; const String textInTextField = 'Hello';
final SemanticsTester semantics = SemanticsTester(tester); final SemanticsTester semantics = SemanticsTester(tester);
final SemanticsOwner semanticsOwner = tester.binding.pipelineOwner.semanticsOwner; final SemanticsOwner semanticsOwner = tester.binding.pipelineOwner.semanticsOwner!;
final TextEditingController controller = TextEditingController() final TextEditingController controller = TextEditingController()
..text = textInTextField; ..text = textInTextField;
final Key key = UniqueKey(); final Key key = UniqueKey();
...@@ -5338,7 +5333,7 @@ void main() { ...@@ -5338,7 +5333,7 @@ void main() {
const String textInTextField = 'Hello'; const String textInTextField = 'Hello';
final SemanticsTester semantics = SemanticsTester(tester); final SemanticsTester semantics = SemanticsTester(tester);
final SemanticsOwner semanticsOwner = tester.binding.pipelineOwner.semanticsOwner; final SemanticsOwner semanticsOwner = tester.binding.pipelineOwner.semanticsOwner!;
final TextEditingController controller = TextEditingController() final TextEditingController controller = TextEditingController()
..text = textInTextField; ..text = textInTextField;
final Key key = UniqueKey(); final Key key = UniqueKey();
...@@ -5444,7 +5439,7 @@ void main() { ...@@ -5444,7 +5439,7 @@ void main() {
boilerplate( boilerplate(
child: Builder(builder: (BuildContext context) { child: Builder(builder: (BuildContext context) {
return MediaQuery( return MediaQuery(
data: MediaQuery.of(context).copyWith( data: MediaQuery.of(context)!.copyWith(
navigationMode: NavigationMode.directional, navigationMode: NavigationMode.directional,
), ),
child: TextField( child: TextField(
...@@ -5465,7 +5460,7 @@ void main() { ...@@ -5465,7 +5460,7 @@ void main() {
boilerplate( boilerplate(
child: Builder(builder: (BuildContext context) { child: Builder(builder: (BuildContext context) {
return MediaQuery( return MediaQuery(
data: MediaQuery.of(context).copyWith( data: MediaQuery.of(context)!.copyWith(
navigationMode: NavigationMode.directional, navigationMode: NavigationMode.directional,
), ),
child: TextField( child: TextField(
...@@ -5741,8 +5736,8 @@ void main() { ...@@ -5741,8 +5736,8 @@ void main() {
final Key textField2 = UniqueKey(); final Key textField2 = UniqueKey();
final ScrollController scrollController = ScrollController(); final ScrollController scrollController = ScrollController();
double minOffset; double? minOffset;
double maxOffset; double? maxOffset;
scrollController.addListener(() { scrollController.addListener(() {
final double offset = scrollController.offset; final double offset = scrollController.offset;
...@@ -5814,8 +5809,8 @@ void main() { ...@@ -5814,8 +5809,8 @@ void main() {
final Key textField2 = UniqueKey(); final Key textField2 = UniqueKey();
final ScrollController scrollController = ScrollController(); final ScrollController scrollController = ScrollController();
double minOffset; double? minOffset;
double maxOffset; double? maxOffset;
scrollController.addListener(() { scrollController.addListener(() {
final double offset = scrollController.offset; final double offset = scrollController.offset;
...@@ -5925,9 +5920,9 @@ void main() { ...@@ -5925,9 +5920,9 @@ void main() {
// This is a regression test for https://github.com/flutter/flutter/issues/24612 // This is a regression test for https://github.com/flutter/flutter/issues/24612
Widget buildFrame({ Widget buildFrame({
double stepWidth, double? stepWidth,
double cursorWidth, required double cursorWidth,
TextAlign textAlign, required TextAlign textAlign,
}) { }) {
return MaterialApp( return MaterialApp(
home: Scaffold( home: Scaffold(
...@@ -5952,7 +5947,7 @@ void main() { ...@@ -5952,7 +5947,7 @@ void main() {
// A cursor of default size doesn't cause the TextField to increase its // A cursor of default size doesn't cause the TextField to increase its
// width. // width.
const String text = '1234'; const String text = '1234';
double stepWidth = 80.0; double? stepWidth = 80.0;
await tester.pumpWidget(buildFrame( await tester.pumpWidget(buildFrame(
stepWidth: 80.0, stepWidth: 80.0,
cursorWidth: 2.0, cursorWidth: 2.0,
...@@ -6022,12 +6017,12 @@ void main() { ...@@ -6022,12 +6017,12 @@ void main() {
// Empty TextStyle is overridden by theme // Empty TextStyle is overridden by theme
await tester.pumpWidget(buildFrame(const TextStyle())); await tester.pumpWidget(buildFrame(const TextStyle()));
EditableText editableText = tester.widget(find.byType(EditableText)); EditableText editableText = tester.widget(find.byType(EditableText));
expect(editableText.style.color, themeData.textTheme.subtitle1.color); expect(editableText.style.color, themeData.textTheme.subtitle1!.color);
expect(editableText.style.background, themeData.textTheme.subtitle1.background); expect(editableText.style.background, themeData.textTheme.subtitle1!.background);
expect(editableText.style.shadows, themeData.textTheme.subtitle1.shadows); expect(editableText.style.shadows, themeData.textTheme.subtitle1!.shadows);
expect(editableText.style.decoration, themeData.textTheme.subtitle1.decoration); expect(editableText.style.decoration, themeData.textTheme.subtitle1!.decoration);
expect(editableText.style.locale, themeData.textTheme.subtitle1.locale); expect(editableText.style.locale, themeData.textTheme.subtitle1!.locale);
expect(editableText.style.wordSpacing, themeData.textTheme.subtitle1.wordSpacing); expect(editableText.style.wordSpacing, themeData.textTheme.subtitle1!.wordSpacing);
// Properties set on TextStyle override theme // Properties set on TextStyle override theme
const Color setColor = Colors.red; const Color setColor = Colors.red;
...@@ -7570,8 +7565,8 @@ void main() { ...@@ -7570,8 +7565,8 @@ void main() {
await tester.pump(); await tester.pump();
final EditableTextState editableText = tester.state(find.byType(EditableText)); final EditableTextState editableText = tester.state(find.byType(EditableText));
expect(editableText.selectionOverlay.handlesAreVisible, isTrue); expect(editableText.selectionOverlay!.handlesAreVisible, isTrue);
expect(editableText.selectionOverlay.toolbarIsVisible, isFalse); expect(editableText.selectionOverlay!.toolbarIsVisible, isFalse);
}); });
testWidgets( testWidgets(
...@@ -7592,8 +7587,8 @@ void main() { ...@@ -7592,8 +7587,8 @@ void main() {
await tester.pump(); await tester.pump();
final EditableTextState editableText = tester.state(find.byType(EditableText)); final EditableTextState editableText = tester.state(find.byType(EditableText));
expect(editableText.selectionOverlay.handlesAreVisible, isFalse); expect(editableText.selectionOverlay!.handlesAreVisible, isFalse);
expect(editableText.selectionOverlay.toolbarIsVisible, isFalse); expect(editableText.selectionOverlay!.toolbarIsVisible, isFalse);
}, },
); );
...@@ -7615,8 +7610,8 @@ void main() { ...@@ -7615,8 +7610,8 @@ void main() {
await tester.pump(); await tester.pump();
final EditableTextState editableText = tester.state(find.byType(EditableText)); final EditableTextState editableText = tester.state(find.byType(EditableText));
expect(editableText.selectionOverlay.handlesAreVisible, isTrue); expect(editableText.selectionOverlay!.handlesAreVisible, isTrue);
expect(editableText.selectionOverlay.toolbarIsVisible, isTrue); expect(editableText.selectionOverlay!.toolbarIsVisible, isTrue);
}); });
testWidgets( testWidgets(
...@@ -7637,8 +7632,8 @@ void main() { ...@@ -7637,8 +7632,8 @@ void main() {
await tester.pump(); await tester.pump();
final EditableTextState editableText = tester.state(find.byType(EditableText)); final EditableTextState editableText = tester.state(find.byType(EditableText));
expect(editableText.selectionOverlay.handlesAreVisible, isTrue); expect(editableText.selectionOverlay!.handlesAreVisible, isTrue);
expect(editableText.selectionOverlay.toolbarIsVisible, isTrue); expect(editableText.selectionOverlay!.toolbarIsVisible, isTrue);
}, },
); );
...@@ -7662,8 +7657,8 @@ void main() { ...@@ -7662,8 +7657,8 @@ void main() {
await tester.pump(); await tester.pump();
final EditableTextState editableText = tester.state(find.byType(EditableText)); final EditableTextState editableText = tester.state(find.byType(EditableText));
expect(editableText.selectionOverlay.handlesAreVisible, isTrue); expect(editableText.selectionOverlay!.handlesAreVisible, isTrue);
expect(editableText.selectionOverlay.toolbarIsVisible, isTrue); expect(editableText.selectionOverlay!.toolbarIsVisible, isTrue);
}); });
testWidgets( testWidgets(
...@@ -7686,8 +7681,8 @@ void main() { ...@@ -7686,8 +7681,8 @@ void main() {
await tester.pump(); await tester.pump();
final EditableTextState editableText = tester.state(find.byType(EditableText)); final EditableTextState editableText = tester.state(find.byType(EditableText));
expect(editableText.selectionOverlay.handlesAreVisible, isFalse); expect(editableText.selectionOverlay!.handlesAreVisible, isFalse);
expect(editableText.selectionOverlay.toolbarIsVisible, isTrue); expect(editableText.selectionOverlay!.toolbarIsVisible, isTrue);
}, },
); );
...@@ -7719,8 +7714,8 @@ void main() { ...@@ -7719,8 +7714,8 @@ void main() {
await tester.pump(); await tester.pump();
final EditableTextState editableText = tester.state(find.byType(EditableText)); final EditableTextState editableText = tester.state(find.byType(EditableText));
expect(editableText.selectionOverlay.toolbarIsVisible, isFalse); expect(editableText.selectionOverlay!.toolbarIsVisible, isFalse);
expect(editableText.selectionOverlay.handlesAreVisible, isFalse); expect(editableText.selectionOverlay!.handlesAreVisible, isFalse);
}, },
); );
...@@ -7752,8 +7747,8 @@ void main() { ...@@ -7752,8 +7747,8 @@ void main() {
await tester.pump(); await tester.pump();
final EditableTextState editableText = tester.state(find.byType(EditableText)); final EditableTextState editableText = tester.state(find.byType(EditableText));
expect(editableText.selectionOverlay.toolbarIsVisible, isFalse); expect(editableText.selectionOverlay!.toolbarIsVisible, isFalse);
expect(editableText.selectionOverlay.handlesAreVisible, isFalse); expect(editableText.selectionOverlay!.handlesAreVisible, isFalse);
}, },
); );
...@@ -7789,8 +7784,8 @@ void main() { ...@@ -7789,8 +7784,8 @@ void main() {
await tester.pump(); await tester.pump();
final EditableTextState editableText = tester.state(find.byType(EditableText)); final EditableTextState editableText = tester.state(find.byType(EditableText));
expect(editableText.selectionOverlay.toolbarIsVisible, isFalse); expect(editableText.selectionOverlay!.toolbarIsVisible, isFalse);
expect(editableText.selectionOverlay.handlesAreVisible, isFalse); expect(editableText.selectionOverlay!.handlesAreVisible, isFalse);
}, },
); );
...@@ -7819,7 +7814,7 @@ void main() { ...@@ -7819,7 +7814,7 @@ void main() {
await tester.pumpAndSettle(); await tester.pumpAndSettle();
final EditableTextState state = tester.state(find.byType(EditableText)); final EditableTextState state = tester.state(find.byType(EditableText));
expect(state.selectionOverlay.handlesAreVisible, isFalse); expect(state.selectionOverlay!.handlesAreVisible, isFalse);
expect(controller.selection, const TextSelection.collapsed(offset: 0)); expect(controller.selection, const TextSelection.collapsed(offset: 0));
if (kIsWeb) { if (kIsWeb) {
...@@ -7832,7 +7827,7 @@ void main() { ...@@ -7832,7 +7827,7 @@ void main() {
state.currentTextEditingValue.selection, state.currentTextEditingValue.selection,
const TextSelection(baseOffset: 2, extentOffset: 7), const TextSelection(baseOffset: 2, extentOffset: 7),
); );
expect(state.selectionOverlay.handlesAreVisible, isFalse); expect(state.selectionOverlay!.handlesAreVisible, isFalse);
} }
}); });
...@@ -7855,8 +7850,8 @@ void main() { ...@@ -7855,8 +7850,8 @@ void main() {
await tester.pumpAndSettle(); await tester.pumpAndSettle();
final EditableTextState editableText = tester.state(find.byType(EditableText)); final EditableTextState editableText = tester.state(find.byType(EditableText));
expect(editableText.selectionOverlay.toolbarIsVisible, isFalse); expect(editableText.selectionOverlay!.toolbarIsVisible, isFalse);
expect(editableText.selectionOverlay.handlesAreVisible, isTrue); expect(editableText.selectionOverlay!.handlesAreVisible, isTrue);
final RenderEditable renderEditable = findRenderEditable(tester); final RenderEditable renderEditable = findRenderEditable(tester);
final List<TextSelectionPoint> endpoints = globalize( final List<TextSelectionPoint> endpoints = globalize(
...@@ -7868,11 +7863,11 @@ void main() { ...@@ -7868,11 +7863,11 @@ void main() {
// Tap the handle to show the toolbar. // Tap the handle to show the toolbar.
final Offset handlePos = endpoints[0].point + const Offset(0.0, 1.0); final Offset handlePos = endpoints[0].point + const Offset(0.0, 1.0);
await tester.tapAt(handlePos, pointer: 7); await tester.tapAt(handlePos, pointer: 7);
expect(editableText.selectionOverlay.toolbarIsVisible, isTrue); expect(editableText.selectionOverlay!.toolbarIsVisible, isTrue);
// Tap the handle again to hide the toolbar. // Tap the handle again to hide the toolbar.
await tester.tapAt(handlePos, pointer: 7); await tester.tapAt(handlePos, pointer: 7);
expect(editableText.selectionOverlay.toolbarIsVisible, isFalse); expect(editableText.selectionOverlay!.toolbarIsVisible, isFalse);
}); });
testWidgets('when TextField would be blocked by keyboard, it is shown with enough space for the selection handle', (WidgetTester tester) async { testWidgets('when TextField would be blocked by keyboard, it is shown with enough space for the selection handle', (WidgetTester tester) async {
...@@ -7954,7 +7949,7 @@ void main() { ...@@ -7954,7 +7949,7 @@ void main() {
}); });
group('intrinsics', () { group('intrinsics', () {
Widget _buildTest({ bool isDense }) { Widget _buildTest({ required bool isDense }) {
return MaterialApp( return MaterialApp(
home: Scaffold( home: Scaffold(
body: CustomScrollView( body: CustomScrollView(
...@@ -8099,7 +8094,7 @@ void main() { ...@@ -8099,7 +8094,7 @@ void main() {
TextField( TextField(
key: textField2Key, key: textField2Key,
maxLength: 1, maxLength: 1,
buildCounter: (BuildContext context, {int currentLength, bool isFocused, int maxLength}) => null, buildCounter: (BuildContext context, {required int currentLength, required bool isFocused, int? maxLength}) => null,
), ),
], ],
), ),
...@@ -8228,7 +8223,7 @@ void main() { ...@@ -8228,7 +8223,7 @@ void main() {
await tester.pump(); await tester.pump();
expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.grab); expect(RendererBinding.instance!.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.grab);
// Test default cursor // Test default cursor
await tester.pumpWidget( await tester.pumpWidget(
...@@ -8246,9 +8241,9 @@ void main() { ...@@ -8246,9 +8241,9 @@ void main() {
), ),
); );
expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.text); expect(RendererBinding.instance!.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.text);
await gesture.moveTo(edge); await gesture.moveTo(edge);
expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.text); expect(RendererBinding.instance!.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.text);
await gesture.moveTo(center); await gesture.moveTo(center);
// Test default cursor when disabled // Test default cursor when disabled
...@@ -8268,14 +8263,14 @@ void main() { ...@@ -8268,14 +8263,14 @@ void main() {
), ),
); );
expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.basic); expect(RendererBinding.instance!.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.basic);
await gesture.moveTo(edge); await gesture.moveTo(edge);
expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.basic); expect(RendererBinding.instance!.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.basic);
await gesture.moveTo(center); await gesture.moveTo(center);
}); });
testWidgets('Caret rtl with changing width', (WidgetTester tester) async { testWidgets('Caret rtl with changing width', (WidgetTester tester) async {
StateSetter setState; late StateSetter setState;
bool isWide = false; bool isWide = false;
const double wideWidth = 300.0; const double wideWidth = 300.0;
const double narrowWidth = 200.0; const double narrowWidth = 200.0;
......
...@@ -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/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
...@@ -173,7 +171,7 @@ void main() { ...@@ -173,7 +171,7 @@ void main() {
}); });
testWidgets('onChanged callbacks are called', (WidgetTester tester) async { testWidgets('onChanged callbacks are called', (WidgetTester tester) async {
String _value; late String _value;
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
...@@ -203,7 +201,7 @@ void main() { ...@@ -203,7 +201,7 @@ void main() {
child: Center( child: Center(
child: TextFormField( child: TextFormField(
autovalidateMode: AutovalidateMode.always, autovalidateMode: AutovalidateMode.always,
validator: (String value) { validator: (String? value) {
_validateCalled++; _validateCalled++;
return null; return null;
}, },
...@@ -229,7 +227,7 @@ void main() { ...@@ -229,7 +227,7 @@ void main() {
child: TextFormField( child: TextFormField(
enabled: true, enabled: true,
autovalidateMode: AutovalidateMode.always, autovalidateMode: AutovalidateMode.always,
validator: (String value) { validator: (String? value) {
_validateCalled += 1; _validateCalled += 1;
return null; return null;
}, },
...@@ -272,25 +270,25 @@ void main() { ...@@ -272,25 +270,25 @@ void main() {
await tester.pumpWidget(buildFrame(true, false)); await tester.pumpWidget(buildFrame(true, false));
Text helperWidget = tester.widget(find.text(helperText)); Text helperWidget = tester.widget(find.text(helperText));
Text counterWidget = tester.widget(find.text(counterText)); Text counterWidget = tester.widget(find.text(counterText));
expect(helperWidget.style.color, isNot(equals(Colors.transparent))); expect(helperWidget.style!.color, isNot(equals(Colors.transparent)));
expect(counterWidget.style.color, isNot(equals(Colors.transparent))); expect(counterWidget.style!.color, isNot(equals(Colors.transparent)));
await tester.pumpWidget(buildFrame(true, true)); await tester.pumpWidget(buildFrame(true, true));
counterWidget = tester.widget(find.text(counterText)); counterWidget = tester.widget(find.text(counterText));
Text errorWidget = tester.widget(find.text(errorText)); Text errorWidget = tester.widget(find.text(errorText));
expect(helperWidget.style.color, isNot(equals(Colors.transparent))); expect(helperWidget.style!.color, isNot(equals(Colors.transparent)));
expect(errorWidget.style.color, isNot(equals(Colors.transparent))); expect(errorWidget.style!.color, isNot(equals(Colors.transparent)));
// When enabled is false, the helper/error and counter are not visible. // When enabled is false, the helper/error and counter are not visible.
await tester.pumpWidget(buildFrame(false, false)); await tester.pumpWidget(buildFrame(false, false));
helperWidget = tester.widget(find.text(helperText)); helperWidget = tester.widget(find.text(helperText));
counterWidget = tester.widget(find.text(counterText)); counterWidget = tester.widget(find.text(counterText));
expect(helperWidget.style.color, equals(Colors.transparent)); expect(helperWidget.style!.color, equals(Colors.transparent));
expect(counterWidget.style.color, equals(Colors.transparent)); expect(counterWidget.style!.color, equals(Colors.transparent));
await tester.pumpWidget(buildFrame(false, true)); await tester.pumpWidget(buildFrame(false, true));
errorWidget = tester.widget(find.text(errorText)); errorWidget = tester.widget(find.text(errorText));
counterWidget = tester.widget(find.text(counterText)); counterWidget = tester.widget(find.text(counterText));
expect(counterWidget.style.color, equals(Colors.transparent)); expect(counterWidget.style!.color, equals(Colors.transparent));
expect(errorWidget.style.color, equals(Colors.transparent)); expect(errorWidget.style!.color, equals(Colors.transparent));
}); });
testWidgets('passing a buildCounter shows returned widget', (WidgetTester tester) async { testWidgets('passing a buildCounter shows returned widget', (WidgetTester tester) async {
...@@ -298,7 +296,7 @@ void main() { ...@@ -298,7 +296,7 @@ void main() {
home: Material( home: Material(
child: Center( child: Center(
child: TextFormField( child: TextFormField(
buildCounter: (BuildContext context, { int currentLength, int maxLength, bool isFocused }) { buildCounter: (BuildContext context, { int? currentLength, int? maxLength, bool? isFocused }) {
return Text('${currentLength.toString()} of ${maxLength.toString()}'); return Text('${currentLength.toString()} of ${maxLength.toString()}');
}, },
maxLength: 10, maxLength: 10,
...@@ -434,7 +432,7 @@ void main() { ...@@ -434,7 +432,7 @@ void main() {
testWidgets('onChanged callbacks value and FormFieldState.value are sync', (WidgetTester tester) async { testWidgets('onChanged callbacks value and FormFieldState.value are sync', (WidgetTester tester) async {
bool _called = false; bool _called = false;
FormFieldState<String> state; late FormFieldState<String> state;
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
...@@ -484,7 +482,7 @@ void main() { ...@@ -484,7 +482,7 @@ void main() {
child: Scaffold( child: Scaffold(
body: TextFormField( body: TextFormField(
autovalidateMode: AutovalidateMode.onUserInteraction, autovalidateMode: AutovalidateMode.onUserInteraction,
validator: (String value) { validator: (String? value) {
_validateCalled++; _validateCalled++;
return null; return null;
}, },
......
...@@ -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';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
...@@ -21,7 +19,7 @@ class MockClipboard { ...@@ -21,7 +19,7 @@ class MockClipboard {
case 'Clipboard.getData': case 'Clipboard.getData':
return _clipboardData; return _clipboardData;
case 'Clipboard.setData': case 'Clipboard.setData':
_clipboardData = methodCall.arguments; _clipboardData = methodCall.arguments as Object;
break; break;
} }
} }
...@@ -38,9 +36,9 @@ void main() { ...@@ -38,9 +36,9 @@ void main() {
group('canSelectAll', () { group('canSelectAll', () {
Widget createEditableText({ Widget createEditableText({
Key key, required Key key,
String text, String? text,
TextSelection selection, TextSelection? selection,
}) { }) {
final TextEditingController controller = TextEditingController(text: text) final TextEditingController controller = TextEditingController(text: text)
..selection = selection ?? const TextSelection.collapsed(offset: -1); ..selection = selection ?? const TextSelection.collapsed(offset: -1);
...@@ -59,7 +57,7 @@ void main() { ...@@ -59,7 +57,7 @@ void main() {
testWidgets('should return false when there is no text', (WidgetTester tester) async { testWidgets('should return false when there is no text', (WidgetTester tester) async {
final GlobalKey<EditableTextState> key = GlobalKey(); final GlobalKey<EditableTextState> key = GlobalKey();
await tester.pumpWidget(createEditableText(key: key)); await tester.pumpWidget(createEditableText(key: key));
expect(materialTextSelectionControls.canSelectAll(key.currentState), false); expect(materialTextSelectionControls.canSelectAll(key.currentState!), false);
}); });
testWidgets('should return true when there is text and collapsed selection', (WidgetTester tester) async { testWidgets('should return true when there is text and collapsed selection', (WidgetTester tester) async {
...@@ -68,7 +66,7 @@ void main() { ...@@ -68,7 +66,7 @@ void main() {
key: key, key: key,
text: '123', text: '123',
)); ));
expect(materialTextSelectionControls.canSelectAll(key.currentState), true); expect(materialTextSelectionControls.canSelectAll(key.currentState!), true);
}); });
testWidgets('should return true when there is text and partial uncollapsed selection', (WidgetTester tester) async { testWidgets('should return true when there is text and partial uncollapsed selection', (WidgetTester tester) async {
...@@ -78,7 +76,7 @@ void main() { ...@@ -78,7 +76,7 @@ void main() {
text: '123', text: '123',
selection: const TextSelection(baseOffset: 1, extentOffset: 2), selection: const TextSelection(baseOffset: 1, extentOffset: 2),
)); ));
expect(materialTextSelectionControls.canSelectAll(key.currentState), true); expect(materialTextSelectionControls.canSelectAll(key.currentState!), true);
}); });
testWidgets('should return false when there is text and full selection', (WidgetTester tester) async { testWidgets('should return false when there is text and full selection', (WidgetTester tester) async {
...@@ -88,7 +86,7 @@ void main() { ...@@ -88,7 +86,7 @@ void main() {
text: '123', text: '123',
selection: const TextSelection(baseOffset: 0, extentOffset: 3), selection: const TextSelection(baseOffset: 0, extentOffset: 3),
)); ));
expect(materialTextSelectionControls.canSelectAll(key.currentState), false); expect(materialTextSelectionControls.canSelectAll(key.currentState!), false);
}); });
}); });
......
...@@ -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/rendering.dart'; import 'package:flutter/rendering.dart';
...@@ -74,7 +72,7 @@ void main() { ...@@ -74,7 +72,7 @@ void main() {
final EditableTextState editableTextState = tester.firstState(find.byType(EditableText)); final EditableTextState editableTextState = tester.firstState(find.byType(EditableText));
final RenderEditable renderEditable = editableTextState.renderEditable; final RenderEditable renderEditable = editableTextState.renderEditable;
expect(renderEditable.cursorColor, defaultCursorColor); expect(renderEditable.cursorColor, defaultCursorColor);
expect(Color(renderEditable.selectionColor.value), defaultSelectionColor); expect(Color(renderEditable.selectionColor!.value), defaultSelectionColor);
// Test the selection handle color. // Test the selection handle color.
await tester.pumpWidget( await tester.pumpWidget(
...@@ -117,7 +115,7 @@ void main() { ...@@ -117,7 +115,7 @@ void main() {
await tester.pumpAndSettle(); await tester.pumpAndSettle();
final EditableTextState editableTextState = tester.firstState(find.byType(EditableText)); final EditableTextState editableTextState = tester.firstState(find.byType(EditableText));
final RenderEditable renderEditable = editableTextState.renderEditable; final RenderEditable renderEditable = editableTextState.renderEditable;
expect(renderEditable.cursorColor, textSelectionTheme.cursorColor.withAlpha(0)); expect(renderEditable.cursorColor, textSelectionTheme.cursorColor!.withAlpha(0));
expect(renderEditable.selectionColor, textSelectionTheme.selectionColor); expect(renderEditable.selectionColor, textSelectionTheme.selectionColor);
// Test the selection handle color. // Test the selection handle color.
...@@ -170,7 +168,7 @@ void main() { ...@@ -170,7 +168,7 @@ void main() {
await tester.pumpAndSettle(); await tester.pumpAndSettle();
final EditableTextState editableTextState = tester.firstState(find.byType(EditableText)); final EditableTextState editableTextState = tester.firstState(find.byType(EditableText));
final RenderEditable renderEditable = editableTextState.renderEditable; final RenderEditable renderEditable = editableTextState.renderEditable;
expect(renderEditable.cursorColor, widgetTextSelectionTheme.cursorColor.withAlpha(0)); expect(renderEditable.cursorColor, widgetTextSelectionTheme.cursorColor!.withAlpha(0));
expect(renderEditable.selectionColor, widgetTextSelectionTheme.selectionColor); expect(renderEditable.selectionColor, widgetTextSelectionTheme.selectionColor);
// Test the selection handle color. // Test the selection handle color.
......
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