iOS TextField spell check style (#125432)
When using a Material TextField on iOS, the spell check selection style now defaults to the red iOS-style, not Android's blue.
This commit is contained in:
committed by
GitHub
parent
8cd11e91fb
commit
85ec874260
@@ -887,6 +887,27 @@ class CupertinoTextField extends StatefulWidget {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
/// Returns a new [SpellCheckConfiguration] where the given configuration has
|
||||
/// had any missing values replaced with their defaults for the iOS platform.
|
||||
static SpellCheckConfiguration inferIOSSpellCheckConfiguration(
|
||||
SpellCheckConfiguration? configuration,
|
||||
) {
|
||||
if (configuration == null
|
||||
|| configuration == const SpellCheckConfiguration.disabled()) {
|
||||
return const SpellCheckConfiguration.disabled();
|
||||
}
|
||||
|
||||
return configuration.copyWith(
|
||||
misspelledTextStyle: configuration.misspelledTextStyle
|
||||
?? CupertinoTextField.cupertinoMisspelledTextStyle,
|
||||
misspelledSelectionColor: configuration.misspelledSelectionColor
|
||||
?? CupertinoTextField.kMisspelledSelectionColor,
|
||||
spellCheckSuggestionsToolbarBuilder:
|
||||
configuration.spellCheckSuggestionsToolbarBuilder
|
||||
?? CupertinoTextField.defaultSpellCheckSuggestionsToolbarBuilder,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _CupertinoTextFieldState extends State<CupertinoTextField> with RestorationMixin, AutomaticKeepAliveClientMixin<CupertinoTextField> implements TextSelectionGestureDetectorBuilderDelegate, AutofillClient {
|
||||
@@ -1298,18 +1319,9 @@ class _CupertinoTextFieldState extends State<CupertinoTextField> with Restoratio
|
||||
// ensure that configuration uses Cupertino text style for misspelled words
|
||||
// unless a custom style is specified.
|
||||
final SpellCheckConfiguration spellCheckConfiguration =
|
||||
widget.spellCheckConfiguration != null &&
|
||||
widget.spellCheckConfiguration != const SpellCheckConfiguration.disabled()
|
||||
? widget.spellCheckConfiguration!.copyWith(
|
||||
misspelledTextStyle: widget.spellCheckConfiguration!.misspelledTextStyle
|
||||
?? CupertinoTextField.cupertinoMisspelledTextStyle,
|
||||
misspelledSelectionColor: widget.spellCheckConfiguration!.misspelledSelectionColor
|
||||
?? CupertinoTextField.kMisspelledSelectionColor,
|
||||
spellCheckSuggestionsToolbarBuilder:
|
||||
widget.spellCheckConfiguration!.spellCheckSuggestionsToolbarBuilder
|
||||
?? CupertinoTextField.defaultSpellCheckSuggestionsToolbarBuilder,
|
||||
)
|
||||
: const SpellCheckConfiguration.disabled();
|
||||
CupertinoTextField.inferIOSSpellCheckConfiguration(
|
||||
widget.spellCheckConfiguration,
|
||||
);
|
||||
|
||||
final Widget paddedEditable = Padding(
|
||||
padding: widget.padding,
|
||||
|
||||
@@ -833,6 +833,25 @@ class TextField extends StatefulWidget {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a new [SpellCheckConfiguration] where the given configuration has
|
||||
/// had any missing values replaced with their defaults for the Android
|
||||
/// platform.
|
||||
static SpellCheckConfiguration inferAndroidSpellCheckConfiguration(
|
||||
SpellCheckConfiguration? configuration,
|
||||
) {
|
||||
if (configuration == null
|
||||
|| configuration == const SpellCheckConfiguration.disabled()) {
|
||||
return const SpellCheckConfiguration.disabled();
|
||||
}
|
||||
return configuration.copyWith(
|
||||
misspelledTextStyle: configuration.misspelledTextStyle
|
||||
?? TextField.materialMisspelledTextStyle,
|
||||
spellCheckSuggestionsToolbarBuilder:
|
||||
configuration.spellCheckSuggestionsToolbarBuilder
|
||||
?? TextField.defaultSpellCheckSuggestionsToolbarBuilder,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
State<TextField> createState() => _TextFieldState();
|
||||
|
||||
@@ -1236,19 +1255,24 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements
|
||||
];
|
||||
|
||||
// Set configuration as disabled if not otherwise specified. If specified,
|
||||
// ensure that configuration uses Material text style for misspelled words
|
||||
// unless a custom style is specified.
|
||||
final SpellCheckConfiguration spellCheckConfiguration =
|
||||
widget.spellCheckConfiguration != null &&
|
||||
widget.spellCheckConfiguration != const SpellCheckConfiguration.disabled()
|
||||
? widget.spellCheckConfiguration!.copyWith(
|
||||
misspelledTextStyle: widget.spellCheckConfiguration!.misspelledTextStyle
|
||||
?? TextField.materialMisspelledTextStyle,
|
||||
spellCheckSuggestionsToolbarBuilder:
|
||||
widget.spellCheckConfiguration!.spellCheckSuggestionsToolbarBuilder
|
||||
?? TextField.defaultSpellCheckSuggestionsToolbarBuilder,
|
||||
)
|
||||
: const SpellCheckConfiguration.disabled();
|
||||
// ensure that configuration uses the correct style for misspelled words for
|
||||
// the current platform, unless a custom style is specified.
|
||||
final SpellCheckConfiguration spellCheckConfiguration;
|
||||
switch (defaultTargetPlatform) {
|
||||
case TargetPlatform.iOS:
|
||||
case TargetPlatform.macOS:
|
||||
spellCheckConfiguration =
|
||||
CupertinoTextField.inferIOSSpellCheckConfiguration(
|
||||
widget.spellCheckConfiguration,
|
||||
);
|
||||
case TargetPlatform.android:
|
||||
case TargetPlatform.fuchsia:
|
||||
case TargetPlatform.linux:
|
||||
case TargetPlatform.windows:
|
||||
spellCheckConfiguration = TextField.inferAndroidSpellCheckConfiguration(
|
||||
widget.spellCheckConfiguration,
|
||||
);
|
||||
}
|
||||
|
||||
TextSelectionControls? textSelectionControls = widget.selectionControls;
|
||||
final bool paintCursorAboveText;
|
||||
|
||||
@@ -16257,6 +16257,64 @@ void main() {
|
||||
expect(spellCheckToolbar, isA<SpellCheckSuggestionsToolbar>());
|
||||
}
|
||||
}, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.android, TargetPlatform.iOS }));
|
||||
|
||||
testWidgets('Builds the corresponding default spell check configuration by platform', (WidgetTester tester) async {
|
||||
tester.binding.platformDispatcher.nativeSpellCheckServiceDefinedTestValue =
|
||||
true;
|
||||
|
||||
final SpellCheckConfiguration expectedConfiguration;
|
||||
switch (defaultTargetPlatform) {
|
||||
case TargetPlatform.iOS:
|
||||
case TargetPlatform.macOS:
|
||||
expectedConfiguration = SpellCheckConfiguration(
|
||||
misspelledTextStyle: CupertinoTextField.cupertinoMisspelledTextStyle,
|
||||
misspelledSelectionColor: CupertinoTextField.kMisspelledSelectionColor,
|
||||
spellCheckService: DefaultSpellCheckService(),
|
||||
spellCheckSuggestionsToolbarBuilder: CupertinoTextField.defaultSpellCheckSuggestionsToolbarBuilder,
|
||||
);
|
||||
case TargetPlatform.android:
|
||||
case TargetPlatform.fuchsia:
|
||||
case TargetPlatform.linux:
|
||||
case TargetPlatform.windows:
|
||||
expectedConfiguration = SpellCheckConfiguration(
|
||||
misspelledTextStyle: TextField.materialMisspelledTextStyle,
|
||||
spellCheckService: DefaultSpellCheckService(),
|
||||
spellCheckSuggestionsToolbarBuilder: TextField.defaultSpellCheckSuggestionsToolbarBuilder,
|
||||
);
|
||||
}
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: Scaffold(
|
||||
body: Center(
|
||||
child: TextField(
|
||||
autofocus: true,
|
||||
spellCheckConfiguration: SpellCheckConfiguration(),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final EditableTextState editableTextState =
|
||||
tester.state<EditableTextState>(find.byType(EditableText));
|
||||
|
||||
expect(
|
||||
editableTextState.spellCheckConfiguration.misspelledTextStyle,
|
||||
expectedConfiguration.misspelledTextStyle,
|
||||
);
|
||||
expect(
|
||||
editableTextState.spellCheckConfiguration.misspelledSelectionColor,
|
||||
expectedConfiguration.misspelledSelectionColor,
|
||||
);
|
||||
expect(
|
||||
editableTextState.spellCheckConfiguration.spellCheckService.runtimeType,
|
||||
expectedConfiguration.spellCheckService.runtimeType,
|
||||
);
|
||||
expect(
|
||||
editableTextState.spellCheckConfiguration.spellCheckSuggestionsToolbarBuilder,
|
||||
expectedConfiguration.spellCheckSuggestionsToolbarBuilder,
|
||||
);
|
||||
}, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.android, TargetPlatform.iOS }));
|
||||
}
|
||||
|
||||
/// A Simple widget for testing the obscure text.
|
||||
|
||||
Reference in New Issue
Block a user