Add onTap and autocorrect into CupertinoSearchTextField (#79966)
This commit is contained in:
parent
f0c9710493
commit
a4411b5565
@ -147,6 +147,9 @@ class CupertinoSearchTextField extends StatefulWidget {
|
|||||||
this.onSuffixTap,
|
this.onSuffixTap,
|
||||||
this.restorationId,
|
this.restorationId,
|
||||||
this.focusNode,
|
this.focusNode,
|
||||||
|
this.onTap,
|
||||||
|
this.autocorrect = true,
|
||||||
|
this.enabled,
|
||||||
}) : assert(padding != null),
|
}) : assert(padding != null),
|
||||||
assert(itemColor != null),
|
assert(itemColor != null),
|
||||||
assert(itemSize != null),
|
assert(itemSize != null),
|
||||||
@ -275,6 +278,18 @@ class CupertinoSearchTextField extends StatefulWidget {
|
|||||||
/// {@macro flutter.widgets.Focus.focusNode}
|
/// {@macro flutter.widgets.Focus.focusNode}
|
||||||
final FocusNode? focusNode;
|
final FocusNode? focusNode;
|
||||||
|
|
||||||
|
/// {@macro flutter.material.textfield.onTap}
|
||||||
|
final VoidCallback? onTap;
|
||||||
|
|
||||||
|
/// {@macro flutter.widgets.editableText.autocorrect}
|
||||||
|
final bool autocorrect;
|
||||||
|
|
||||||
|
/// 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.
|
||||||
|
final bool? enabled;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<StatefulWidget> createState() => _CupertinoSearchTextFieldState();
|
State<StatefulWidget> createState() => _CupertinoSearchTextFieldState();
|
||||||
}
|
}
|
||||||
@ -393,6 +408,8 @@ class _CupertinoSearchTextFieldState extends State<CupertinoSearchTextField>
|
|||||||
style: widget.style,
|
style: widget.style,
|
||||||
prefix: prefix,
|
prefix: prefix,
|
||||||
suffix: suffix,
|
suffix: suffix,
|
||||||
|
onTap: widget.onTap,
|
||||||
|
enabled: widget.enabled,
|
||||||
suffixMode: widget.suffixMode,
|
suffixMode: widget.suffixMode,
|
||||||
placeholder: placeholder,
|
placeholder: placeholder,
|
||||||
placeholderStyle: placeholderStyle,
|
placeholderStyle: placeholderStyle,
|
||||||
@ -400,6 +417,7 @@ class _CupertinoSearchTextFieldState extends State<CupertinoSearchTextField>
|
|||||||
onChanged: widget.onChanged,
|
onChanged: widget.onChanged,
|
||||||
onSubmitted: widget.onSubmitted,
|
onSubmitted: widget.onSubmitted,
|
||||||
focusNode: widget.focusNode,
|
focusNode: widget.focusNode,
|
||||||
|
autocorrect: widget.autocorrect,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -465,4 +465,69 @@ void main() {
|
|||||||
expect(find.text('Text'), findsOneWidget);
|
expect(find.text('Text'), findsOneWidget);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
testWidgets('onTap is properly forwarded to the inner text field',
|
||||||
|
(WidgetTester tester) async {
|
||||||
|
int onTapCallCount = 0;
|
||||||
|
|
||||||
|
// onTap can be null.
|
||||||
|
await tester.pumpWidget(
|
||||||
|
const CupertinoApp(
|
||||||
|
home: Center(
|
||||||
|
child: CupertinoSearchTextField(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
// onTap callback is called if not null.
|
||||||
|
await tester.pumpWidget(
|
||||||
|
CupertinoApp(
|
||||||
|
home: Center(
|
||||||
|
child: CupertinoSearchTextField(
|
||||||
|
onTap: () {
|
||||||
|
onTapCallCount++;
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(onTapCallCount, 0);
|
||||||
|
await tester.tap(find.byType(CupertinoTextField));
|
||||||
|
expect(onTapCallCount, 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('autocorrect is properly forwarded to the inner text field',
|
||||||
|
(WidgetTester tester) async {
|
||||||
|
|
||||||
|
await tester.pumpWidget(
|
||||||
|
const CupertinoApp(
|
||||||
|
home: Center(
|
||||||
|
child: CupertinoSearchTextField(
|
||||||
|
autocorrect: false,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
final CupertinoTextField textField = tester.widget(find.byType(CupertinoTextField));
|
||||||
|
expect(textField.autocorrect, false);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('enabled is properly forwarded to the inner text field',
|
||||||
|
(WidgetTester tester) async {
|
||||||
|
|
||||||
|
await tester.pumpWidget(
|
||||||
|
const CupertinoApp(
|
||||||
|
home: Center(
|
||||||
|
child: CupertinoSearchTextField(
|
||||||
|
enabled: false,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
final CupertinoTextField textField = tester.widget(find.byType(CupertinoTextField));
|
||||||
|
expect(textField.enabled, false);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user