Skip to content

Commit 721781f

Browse files
authored
chore: refresh the grid rows after typing text in the text filter (#1533)
Co-authored-by: nathan <[email protected]>
1 parent 0d879a6 commit 721781f

File tree

2 files changed

+33
-9
lines changed
  • frontend/app_flowy

2 files changed

+33
-9
lines changed

frontend/app_flowy/lib/plugins/grid/presentation/widgets/filter/choicechip/text.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,9 @@ class _TextFilterEditorState extends State<TextFilterEditor> {
152152
return FlowyTextField(
153153
text: state.filter.content,
154154
hintText: LocaleKeys.grid_settings_typeAValue.tr(),
155+
debounceDuration: const Duration(milliseconds: 300),
155156
autoFocus: false,
156-
onSubmitted: (text) {
157+
onChanged: (text) {
157158
context
158159
.read<TextFilterEditorBloc>()
159160
.add(TextFilterEditorEvent.updateContent(text));

frontend/app_flowy/packages/flowy_infra_ui/lib/style_widget/text_field.dart

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'dart:async';
2+
13
import 'package:flowy_infra/size.dart';
24
import 'package:flutter/material.dart';
35
import 'package:flutter/services.dart';
@@ -13,6 +15,7 @@ class FlowyTextField extends StatefulWidget {
1315
final int? maxLength;
1416
final TextEditingController? controller;
1517
final bool autoClearWhenDone;
18+
final Duration? debounceDuration;
1619

1720
const FlowyTextField({
1821
this.hintText = "",
@@ -24,6 +27,7 @@ class FlowyTextField extends StatefulWidget {
2427
this.maxLength,
2528
this.controller,
2629
this.autoClearWhenDone = false,
30+
this.debounceDuration,
2731
Key? key,
2832
}) : super(key: key);
2933

@@ -34,6 +38,7 @@ class FlowyTextField extends StatefulWidget {
3438
class FlowyTextFieldState extends State<FlowyTextField> {
3539
late FocusNode focusNode;
3640
late TextEditingController controller;
41+
Timer? _debounceOnChanged;
3742

3843
@override
3944
void initState() {
@@ -54,22 +59,40 @@ class FlowyTextFieldState extends State<FlowyTextField> {
5459
super.initState();
5560
}
5661

62+
void _debounceOnChangedText(Duration duration, String text) {
63+
_debounceOnChanged?.cancel();
64+
_debounceOnChanged = Timer(duration, () async {
65+
if (mounted) {
66+
_onChanged(text);
67+
}
68+
});
69+
}
70+
71+
void _onChanged(String text) {
72+
widget.onChanged?.call(text);
73+
setState(() {});
74+
}
75+
76+
void _onSubmitted(String text) {
77+
widget.onSubmitted?.call(text);
78+
if (widget.autoClearWhenDone) {
79+
controller.text = "";
80+
}
81+
}
82+
5783
@override
5884
Widget build(BuildContext context) {
5985
return TextField(
6086
controller: controller,
6187
focusNode: focusNode,
6288
onChanged: (text) {
63-
widget.onChanged?.call(text);
64-
setState(() {});
65-
},
66-
onSubmitted: (text) {
67-
widget.onSubmitted?.call(text);
68-
69-
if (widget.autoClearWhenDone) {
70-
controller.text = "";
89+
if (widget.debounceDuration != null) {
90+
_debounceOnChangedText(widget.debounceDuration!, text);
91+
} else {
92+
_onChanged(text);
7193
}
7294
},
95+
onSubmitted: (text) => _onSubmitted(text),
7396
maxLines: 1,
7497
maxLength: widget.maxLength,
7598
maxLengthEnforcement: MaxLengthEnforcement.truncateAfterCompositionEnds,

0 commit comments

Comments
 (0)