Commit 6e50ccc8 authored by hyjfine's avatar hyjfine Committed by xster

Let CupertinoTextField's clear button also call onChanged (#29474)

parent b5700506
......@@ -660,9 +660,14 @@ class _CupertinoTextFieldState extends State<CupertinoTextField> with AutomaticK
} else if (_showClearButton(text)) {
rowChildren.add(
GestureDetector(
onTap: widget.enabled ?? true
? () => _effectiveController.clear()
: null,
onTap: widget.enabled ?? true ? () {
// Special handle onChanged for ClearButton
// Also call onChanged when the clear button is tapped.
final bool textChanged = _effectiveController.text.isNotEmpty;
_effectiveController.clear();
if (widget.onChanged != null && textChanged)
widget.onChanged(_effectiveController.text);
} : null,
child: const Padding(
padding: EdgeInsets.symmetric(horizontal: 6.0),
child: Icon(
......
......@@ -749,6 +749,36 @@ void main() {
},
);
testWidgets(
'tapping clear button also calls onChanged when text not empty',
(WidgetTester tester) async {
String value = 'text entry';
final TextEditingController controller = TextEditingController();
await tester.pumpWidget(
CupertinoApp(
home: Center(
child: CupertinoTextField(
controller: controller,
placeholder: 'placeholder',
onChanged: (String newValue) => value = newValue,
clearButtonMode: OverlayVisibilityMode.always,
),
),
),
);
controller.text = value;
await tester.pump();
await tester.tap(find.byIcon(CupertinoIcons.clear_thick_circled));
await tester.pump();
expect(controller.text, isEmpty);
expect(find.text('text entry'), findsNothing);
expect(value, isEmpty);
},
);
testWidgets(
'clear button yields precedence to suffix',
(WidgetTester tester) async {
......
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