mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Fix CupertinoTextField and TextField ToolbarOptions not changing (#40665)
This commit is contained in:
parent
0e605cc4dd
commit
b730a993c1
1
AUTHORS
1
AUTHORS
@ -42,4 +42,5 @@ Igor Katsuba <katsuba.igor@gmail.com>
|
||||
Diego Velásquez <diego.velasquez.lopez@gmail.com>
|
||||
Simon Lightfoot <simon@devangels.london>
|
||||
Sarbagya Dhaubanjar <mail@sarbagyastha.com.np>
|
||||
Rody Davis Jr <rody.davis.jr@gmail.com>
|
||||
Robin Jespersen <info@unitedpartners.de>
|
||||
|
@ -265,7 +265,7 @@ class CupertinoTextField extends StatefulWidget {
|
||||
assert(prefixMode != null),
|
||||
assert(suffixMode != null),
|
||||
keyboardType = keyboardType ?? (maxLines == 1 ? TextInputType.text : TextInputType.multiline),
|
||||
toolbarOptions = toolbarOptions ?? obscureText ?
|
||||
toolbarOptions = toolbarOptions ?? (obscureText ?
|
||||
const ToolbarOptions(
|
||||
selectAll: true,
|
||||
paste: true,
|
||||
@ -275,7 +275,7 @@ class CupertinoTextField extends StatefulWidget {
|
||||
cut: true,
|
||||
selectAll: true,
|
||||
paste: true,
|
||||
),
|
||||
)),
|
||||
super(key: key);
|
||||
|
||||
/// Controls the text being edited.
|
||||
|
@ -346,7 +346,7 @@ class TextField extends StatefulWidget {
|
||||
),
|
||||
assert(maxLength == null || maxLength == TextField.noMaxLength || maxLength > 0),
|
||||
keyboardType = keyboardType ?? (maxLines == 1 ? TextInputType.text : TextInputType.multiline),
|
||||
toolbarOptions = toolbarOptions ?? obscureText ?
|
||||
toolbarOptions = toolbarOptions ?? (obscureText ?
|
||||
const ToolbarOptions(
|
||||
selectAll: true,
|
||||
paste: true,
|
||||
@ -356,7 +356,7 @@ class TextField extends StatefulWidget {
|
||||
cut: true,
|
||||
selectAll: true,
|
||||
paste: true,
|
||||
),
|
||||
)),
|
||||
super(key: key);
|
||||
|
||||
/// Controls the text being edited.
|
||||
|
@ -1290,6 +1290,49 @@ void main() {
|
||||
expect(text.style.fontWeight, FontWeight.w400);
|
||||
});
|
||||
|
||||
|
||||
testWidgets('text field toolbar options correctly changes options', (WidgetTester tester) async {
|
||||
final TextEditingController controller = TextEditingController(
|
||||
text: 'Atwater Peel Sherbrooke Bonaventure',
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
CupertinoApp(
|
||||
home: Column(
|
||||
children: <Widget>[
|
||||
CupertinoTextField(
|
||||
controller: controller,
|
||||
toolbarOptions: const ToolbarOptions(copy: true),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Long press to put the cursor after the "w".
|
||||
const int index = 3;
|
||||
await tester.longPressAt(textOffsetToPosition(tester, index));
|
||||
await tester.pump();
|
||||
expect(
|
||||
controller.selection,
|
||||
const TextSelection.collapsed(offset: index),
|
||||
);
|
||||
|
||||
// Double tap on the same location to select the word around the cursor.
|
||||
await tester.tapAt(textOffsetToPosition(tester, index));
|
||||
await tester.pump(const Duration(milliseconds: 50));
|
||||
await tester.tapAt(textOffsetToPosition(tester, index));
|
||||
await tester.pump();
|
||||
expect(
|
||||
controller.selection,
|
||||
const TextSelection(baseOffset: 0, extentOffset: 7),
|
||||
);
|
||||
|
||||
// Selected text shows 'Copy'.
|
||||
expect(find.text('Paste'), findsNothing);
|
||||
expect(find.text('Copy'), findsOneWidget);
|
||||
expect(find.text('Cut'), findsNothing);
|
||||
expect(find.text('Select All'), findsNothing);
|
||||
});
|
||||
testWidgets('Read only text field', (WidgetTester tester) async {
|
||||
final TextEditingController controller = TextEditingController(text: 'readonly');
|
||||
|
||||
|
@ -505,6 +505,89 @@ void main() {
|
||||
);
|
||||
}, skip: isBrowser);
|
||||
|
||||
testWidgets('text field toolbar options correctly changes options (iOS)',
|
||||
(WidgetTester tester) async {
|
||||
final TextEditingController controller = TextEditingController(
|
||||
text: 'Atwater Peel Sherbrooke Bonaventure',
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeData(platform: TargetPlatform.iOS),
|
||||
home: Material(
|
||||
child: Center(
|
||||
child: TextField(
|
||||
controller: controller,
|
||||
toolbarOptions: const ToolbarOptions(copy: true),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final Offset textfieldStart = tester.getTopLeft(find.byType(TextField));
|
||||
|
||||
// This tap just puts the cursor somewhere different than where the double
|
||||
// tap will occur to test that the double tap moves the existing cursor first.
|
||||
await tester.tapAt(textfieldStart + const Offset(50.0, 5.0));
|
||||
await tester.pump(const Duration(milliseconds: 500));
|
||||
|
||||
await tester.tapAt(textfieldStart + const Offset(150.0, 5.0));
|
||||
await tester.pump(const Duration(milliseconds: 50));
|
||||
// First tap moved the cursor.
|
||||
expect(
|
||||
controller.selection,
|
||||
const TextSelection.collapsed(
|
||||
offset: 8, affinity: TextAffinity.downstream),
|
||||
);
|
||||
await tester.tapAt(textfieldStart + const Offset(150.0, 5.0));
|
||||
await tester.pump();
|
||||
|
||||
// Second tap selects the word around the cursor.
|
||||
expect(
|
||||
controller.selection,
|
||||
const TextSelection(baseOffset: 8, extentOffset: 12),
|
||||
);
|
||||
|
||||
// Selected text shows 'Copy', and not 'Paste', 'Cut', 'Select All'.
|
||||
expect(find.text('Paste'), findsNothing);
|
||||
expect(find.text('Copy'), findsOneWidget);
|
||||
expect(find.text('Cut'), findsNothing);
|
||||
expect(find.text('Select All'), findsNothing);
|
||||
}, skip: isBrowser);
|
||||
|
||||
testWidgets('text field toolbar options correctly changes options (Android)',
|
||||
(WidgetTester tester) async {
|
||||
final TextEditingController controller = TextEditingController(
|
||||
text: 'Atwater Peel Sherbrooke Bonaventure',
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Material(
|
||||
child: Center(
|
||||
child: TextField(
|
||||
controller: controller,
|
||||
toolbarOptions: const ToolbarOptions(copy: true),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final Offset textfieldStart = tester.getTopLeft(find.byType(TextField));
|
||||
|
||||
await tester.tapAt(textfieldStart + const Offset(150.0, 5.0));
|
||||
await tester.pump(const Duration(milliseconds: 50));
|
||||
|
||||
await tester.tapAt(textfieldStart + const Offset(150.0, 5.0));
|
||||
await tester.pump();
|
||||
|
||||
// Selected text shows 'COPY', and not 'PASTE', 'CUT', 'SELECT ALL'.
|
||||
expect(find.text('PASTE'), findsNothing);
|
||||
expect(find.text('COPY'), findsOneWidget);
|
||||
expect(find.text('CUT'), findsNothing);
|
||||
expect(find.text('SELECT ALL'), findsNothing);
|
||||
}, skip: isBrowser);
|
||||
|
||||
// TODO(hansmuller): restore these tests after the fix for #24876 has landed.
|
||||
/*
|
||||
testWidgets('cursor layout has correct width', (WidgetTester tester) async {
|
||||
|
Loading…
Reference in New Issue
Block a user