fix:: trigger onTapOutside only if has focus (#136291)
Adds new feat and fix to https://github.com/flutter/flutter/issues/134341
This commit is contained in:
parent
1c90ed8b64
commit
de4e3d67a0
@ -4770,7 +4770,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
|
||||
compositeCallback: _compositeCallback,
|
||||
enabled: _hasInputConnection,
|
||||
child: TextFieldTapRegion(
|
||||
onTapOutside: widget.onTapOutside ?? _defaultOnTapOutside,
|
||||
onTapOutside: _hasFocus ? widget.onTapOutside ?? _defaultOnTapOutside : null,
|
||||
debugLabel: kReleaseMode ? null : 'EditableText',
|
||||
child: MouseRegion(
|
||||
cursor: widget.mouseCursor ?? SystemMouseCursors.text,
|
||||
|
@ -773,6 +773,7 @@ void main() {
|
||||
children: <Widget>[
|
||||
const Text('Outside'),
|
||||
TextFormField(
|
||||
autofocus: true,
|
||||
onTapOutside: (PointerEvent event) {
|
||||
tapOutsideCount += 1;
|
||||
},
|
||||
@ -793,6 +794,37 @@ void main() {
|
||||
expect(tapOutsideCount, 3);
|
||||
});
|
||||
|
||||
// Regression test for https://github.com/flutter/flutter/issues/134341.
|
||||
testWidgetsWithLeakTracking('onTapOutside is not called upon tap outside when field is not focused', (WidgetTester tester) async {
|
||||
int tapOutsideCount = 0;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Material(
|
||||
child: Center(
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
const Text('Outside'),
|
||||
TextFormField(
|
||||
onTapOutside: (PointerEvent event) {
|
||||
tapOutsideCount += 1;
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
|
||||
expect(tapOutsideCount, 0);
|
||||
await tester.tap(find.byType(TextFormField));
|
||||
await tester.tap(find.text('Outside'));
|
||||
await tester.tap(find.text('Outside'));
|
||||
await tester.tap(find.text('Outside'));
|
||||
expect(tapOutsideCount, 0);
|
||||
});
|
||||
|
||||
// Regression test for https://github.com/flutter/flutter/issues/54472.
|
||||
testWidgetsWithLeakTracking('reset resets the text fields value to the initialValue', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
|
Loading…
x
Reference in New Issue
Block a user