mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Modify CupertinoSearchTextField's prefix icon. (#81100)
This commit is contained in:
parent
b7dd9acbed
commit
aa81ac6008
@ -116,6 +116,9 @@ class CupertinoSearchTextField extends StatefulWidget {
|
||||
/// default fields were determined using the comparison tool in
|
||||
/// https://github.com/flutter/platform_tests/.
|
||||
///
|
||||
/// To customize the prefix icon, pass a [Widget] to [prefixIcon]. This
|
||||
/// defaults to the search icon.
|
||||
///
|
||||
/// To customize the suffix icon, pass an [Icon] to [suffixIcon]. This
|
||||
/// defaults to the X-Mark.
|
||||
///
|
||||
@ -141,6 +144,7 @@ class CupertinoSearchTextField extends StatefulWidget {
|
||||
this.itemColor = CupertinoColors.secondaryLabel,
|
||||
this.itemSize = 20.0,
|
||||
this.prefixInsets = const EdgeInsetsDirectional.fromSTEB(6, 0, 0, 4),
|
||||
this.prefixIcon = const Icon(CupertinoIcons.search),
|
||||
this.suffixInsets = const EdgeInsetsDirectional.fromSTEB(0, 0, 5, 2),
|
||||
this.suffixIcon = const Icon(CupertinoIcons.xmark_circle_fill),
|
||||
this.suffixMode = OverlayVisibilityMode.editing,
|
||||
@ -246,6 +250,11 @@ class CupertinoSearchTextField extends StatefulWidget {
|
||||
/// the comparison tool in https://github.com/flutter/platform_tests/.
|
||||
final EdgeInsetsGeometry prefixInsets;
|
||||
|
||||
/// Sets a prefix widget.
|
||||
///
|
||||
/// Cannot be null. Defaults to an [Icon] widget with the [CupertinoIcons.search] icon.
|
||||
final Widget prefixIcon;
|
||||
|
||||
/// Sets the padding insets for the prefix.
|
||||
///
|
||||
/// Cannot be null. Defaults to padding that replicates the
|
||||
@ -287,7 +296,7 @@ class CupertinoSearchTextField extends StatefulWidget {
|
||||
/// Disables the text field when false.
|
||||
///
|
||||
/// Text fields in disabled states have a light grey background and don't
|
||||
/// respond to touch events including the [suffixIcon] and the search button.
|
||||
/// respond to touch events including the [prefixIcon] and [suffixIcon] button.
|
||||
final bool? enabled;
|
||||
|
||||
@override
|
||||
@ -387,7 +396,7 @@ class _CupertinoSearchTextFieldState extends State<CupertinoSearchTextField>
|
||||
final Widget prefix = Padding(
|
||||
child: IconTheme(
|
||||
data: iconThemeData,
|
||||
child: const Icon(CupertinoIcons.search),
|
||||
child: widget.prefixIcon,
|
||||
),
|
||||
padding: widget.prefixInsets,
|
||||
);
|
||||
|
||||
@ -257,6 +257,35 @@ void main() {
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('prefix widget visibility', (WidgetTester tester) async {
|
||||
const Key prefixIcon = Key('prefix');
|
||||
|
||||
await tester.pumpWidget(
|
||||
const CupertinoApp(
|
||||
home: Center(
|
||||
child: CupertinoSearchTextField(
|
||||
prefixIcon: SizedBox(
|
||||
key: prefixIcon,
|
||||
width: 50,
|
||||
height: 50,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byIcon(CupertinoIcons.search), findsNothing);
|
||||
expect(find.byKey(prefixIcon), findsOneWidget);
|
||||
|
||||
await tester.enterText(
|
||||
find.byType(CupertinoSearchTextField), 'text input');
|
||||
await tester.pump();
|
||||
|
||||
expect(find.text('text input'), findsOneWidget);
|
||||
expect(find.byIcon(CupertinoIcons.search), findsNothing);
|
||||
expect(find.byKey(prefixIcon), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'suffix widget respects visibility mode',
|
||||
(WidgetTester tester) async {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user