Unverified Commit 20da4014 authored by Callum Moffat's avatar Callum Moffat Committed by GitHub

Expose smart punctuation options on CupertinoSearchTextField (#97980)

parent e182a1c9
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
// 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.
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'button.dart'; import 'button.dart';
...@@ -10,6 +11,8 @@ import 'icons.dart'; ...@@ -10,6 +11,8 @@ import 'icons.dart';
import 'localizations.dart'; import 'localizations.dart';
import 'text_field.dart'; import 'text_field.dart';
export 'package:flutter/services.dart' show SmartQuotesType, SmartDashesType;
/// A [CupertinoTextField] that mimics the look and behavior of UIKit's /// A [CupertinoTextField] that mimics the look and behavior of UIKit's
/// `UISearchTextField`. /// `UISearchTextField`.
/// ///
...@@ -116,6 +119,8 @@ class CupertinoSearchTextField extends StatefulWidget { ...@@ -116,6 +119,8 @@ class CupertinoSearchTextField extends StatefulWidget {
this.onSuffixTap, this.onSuffixTap,
this.restorationId, this.restorationId,
this.focusNode, this.focusNode,
this.smartQuotesType,
this.smartDashesType,
this.autofocus = false, this.autofocus = false,
this.onTap, this.onTap,
this.autocorrect = true, this.autocorrect = true,
...@@ -261,6 +266,52 @@ class CupertinoSearchTextField extends StatefulWidget { ...@@ -261,6 +266,52 @@ class CupertinoSearchTextField extends StatefulWidget {
/// {@macro flutter.widgets.editableText.autocorrect} /// {@macro flutter.widgets.editableText.autocorrect}
final bool autocorrect; final bool autocorrect;
/// Whether to allow the platform to automatically format quotes.
///
/// This flag only affects iOS, where it is equivalent to [`UITextSmartQuotesType`](https://developer.apple.com/documentation/uikit/uitextsmartquotestype?language=objc).
///
/// When set to [SmartQuotesType.enabled], it passes
/// [`UITextSmartQuotesTypeYes`](https://developer.apple.com/documentation/uikit/uitextsmartquotestype/uitextsmartquotestypeyes?language=objc),
/// and when set to [SmartQuotesType.disabled], it passes
/// [`UITextSmartQuotesTypeNo`](https://developer.apple.com/documentation/uikit/uitextsmartquotestype/uitextsmartquotestypeno?language=objc).
///
/// If set to null, [SmartQuotesType.enabled] will be used.
///
/// As an example of what this does, a standard vertical double quote
/// character will be automatically replaced by a left or right double quote
/// depending on its position in a word.
///
/// Defaults to null.
///
/// See also:
///
/// * [smartDashesType]
/// * <https://developer.apple.com/documentation/uikit/uitextinputtraits>
final SmartQuotesType? smartQuotesType;
/// Whether to allow the platform to automatically format dashes.
///
/// This flag only affects iOS versions 11 and above, where it is equivalent to [`UITextSmartDashesType`](https://developer.apple.com/documentation/uikit/uitextsmartdashestype?language=objc).
///
/// When set to [SmartDashesType.enabled], it passes
/// [`UITextSmartDashesTypeYes`](https://developer.apple.com/documentation/uikit/uitextsmartdashestype/uitextsmartdashestypeyes?language=objc),
/// and when set to [SmartDashesType.disabled], it passes
/// [`UITextSmartDashesTypeNo`](https://developer.apple.com/documentation/uikit/uitextsmartdashestype/uitextsmartdashestypeno?language=objc).
///
/// If set to null, [SmartDashesType.enabled] will be used.
///
/// As an example of what this does, two consecutive hyphen characters will be
/// automatically replaced with one en dash, and three consecutive hyphens
/// will become one em dash.
///
/// Defaults to null.
///
/// See also:
///
/// * [smartQuotesType]
/// * <https://developer.apple.com/documentation/uikit/uitextinputtraits>
final SmartDashesType? smartDashesType;
/// Disables the text field when false. /// Disables the text field when false.
/// ///
/// Text fields in disabled states have a light grey background and don't /// Text fields in disabled states have a light grey background and don't
...@@ -400,6 +451,8 @@ class _CupertinoSearchTextFieldState extends State<CupertinoSearchTextField> ...@@ -400,6 +451,8 @@ class _CupertinoSearchTextFieldState extends State<CupertinoSearchTextField>
focusNode: widget.focusNode, focusNode: widget.focusNode,
autofocus: widget.autofocus, autofocus: widget.autofocus,
autocorrect: widget.autocorrect, autocorrect: widget.autocorrect,
smartQuotesType: widget.smartQuotesType,
smartDashesType: widget.smartDashesType,
textInputAction: TextInputAction.search, textInputAction: TextInputAction.search,
); );
} }
......
...@@ -578,4 +578,34 @@ void main() { ...@@ -578,4 +578,34 @@ void main() {
expect(focusNode.hasFocus, isTrue); expect(focusNode.hasFocus, isTrue);
}); });
testWidgets('smartQuotesType is properly forwarded to the inner text field', (WidgetTester tester) async {
await tester.pumpWidget(
const CupertinoApp(
home: Center(
child: CupertinoSearchTextField(
smartQuotesType: SmartQuotesType.disabled,
),
),
),
);
final CupertinoTextField textField = tester.widget(find.byType(CupertinoTextField));
expect(textField.smartQuotesType, SmartQuotesType.disabled);
});
testWidgets('smartDashesType is properly forwarded to the inner text field', (WidgetTester tester) async {
await tester.pumpWidget(
const CupertinoApp(
home: Center(
child: CupertinoSearchTextField(
smartDashesType: SmartDashesType.disabled,
),
),
),
);
final CupertinoTextField textField = tester.widget(find.byType(CupertinoTextField));
expect(textField.smartDashesType, SmartDashesType.disabled);
});
} }
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