Skip to content

Commit c916613

Browse files
authored
feat: on enter exit editing property field #1295 (#1747)
* feat: on enter exit editing property field #1295 * chore: use FlowyTextField instead of RoundedInputField * fix: make all text field border radius 10, added errorBorder * fix: put cursor position at end of text field See the related discussion here: #1747 (comment) * chore: make errorText optional on FlowyTextField
1 parent d505314 commit c916613

File tree

3 files changed

+32
-24
lines changed

3 files changed

+32
-24
lines changed

frontend/app_flowy/lib/plugins/grid/presentation/widgets/header/field_editor.dart

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import 'package:dartz/dartz.dart' show none;
66
import 'package:easy_localization/easy_localization.dart';
77
import 'package:flowy_infra_ui/style_widget/button.dart';
88
import 'package:flowy_infra_ui/style_widget/text.dart';
9-
import 'package:flowy_infra_ui/widget/rounded_input_field.dart';
9+
import 'package:flowy_infra_ui/style_widget/text_field.dart';
1010
import 'package:flowy_infra_ui/widget/spacing.dart';
1111
import 'package:appflowy_backend/log.dart';
1212
import 'package:flutter/material.dart';
@@ -135,11 +135,9 @@ class _FieldNameTextField extends StatefulWidget {
135135

136136
class _FieldNameTextFieldState extends State<_FieldNameTextField> {
137137
FocusNode focusNode = FocusNode();
138-
late TextEditingController controller;
139138

140139
@override
141140
void initState() {
142-
controller = TextEditingController();
143141
focusNode.addListener(() {
144142
if (focusNode.hasFocus) {
145143
widget.popoverMutex.close();
@@ -157,33 +155,23 @@ class _FieldNameTextFieldState extends State<_FieldNameTextField> {
157155

158156
@override
159157
Widget build(BuildContext context) {
160-
return MultiBlocListener(
161-
listeners: [
162-
BlocListener<FieldEditorBloc, FieldEditorState>(
163-
listenWhen: (p, c) => p.field == none(),
164-
listener: (context, state) {
165-
focusNode.requestFocus();
166-
},
167-
),
168-
BlocListener<FieldEditorBloc, FieldEditorState>(
169-
listenWhen: (p, c) => controller.text != c.name,
170-
listener: (context, state) {
171-
controller.text = state.name;
172-
},
173-
),
174-
],
158+
return BlocListener<FieldEditorBloc, FieldEditorState>(
159+
listenWhen: (p, c) => p.field == none(),
160+
listener: (context, state) {
161+
focusNode.requestFocus();
162+
},
175163
child: BlocBuilder<FieldEditorBloc, FieldEditorState>(
176164
buildWhen: (previous, current) =>
177165
previous.errorText != current.errorText,
178166
builder: (context, state) {
179167
return Padding(
180168
padding: const EdgeInsets.symmetric(horizontal: 12.0),
181-
child: RoundedInputField(
182-
height: 36,
169+
child: FlowyTextField(
183170
focusNode: focusNode,
184-
style: Theme.of(context).textTheme.bodyMedium,
185-
controller: controller,
186-
errorText: context.read<FieldEditorBloc>().state.errorText,
171+
onSubmitted: (String _) => PopoverContainer.of(context).close(),
172+
text: context.read<FieldEditorBloc>().state.name,
173+
errorText: context.read<FieldEditorBloc>().state.errorText.isEmpty ?
174+
null : context.read<FieldEditorBloc>().state.errorText,
187175
onChanged: (newName) {
188176
context
189177
.read<FieldEditorBloc>()

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class FlowyTextField extends StatefulWidget {
1919
final bool autoClearWhenDone;
2020
final bool submitOnLeave;
2121
final Duration? debounceDuration;
22+
final String? errorText;
2223

2324
const FlowyTextField({
2425
this.hintText = "",
@@ -34,6 +35,7 @@ class FlowyTextField extends StatefulWidget {
3435
this.autoClearWhenDone = false,
3536
this.submitOnLeave = false,
3637
this.debounceDuration,
38+
this.errorText,
3739
Key? key,
3840
}) : super(key: key);
3941

@@ -117,6 +119,7 @@ class FlowyTextFieldState extends State<FlowyTextField> {
117119
),
118120
isDense: true,
119121
hintText: widget.hintText,
122+
errorText: widget.errorText,
120123
hintStyle: Theme.of(context)
121124
.textTheme
122125
.bodySmall!
@@ -128,7 +131,21 @@ class FlowyTextFieldState extends State<FlowyTextField> {
128131
color: Theme.of(context).colorScheme.primary,
129132
width: 1.0,
130133
),
131-
borderRadius: Corners.s8Border,
134+
borderRadius: Corners.s10Border,
135+
),
136+
errorBorder: OutlineInputBorder(
137+
borderSide: BorderSide(
138+
color: Theme.of(context).colorScheme.error,
139+
width: 1.0,
140+
),
141+
borderRadius: Corners.s10Border,
142+
),
143+
focusedErrorBorder: OutlineInputBorder(
144+
borderSide: BorderSide(
145+
color: Theme.of(context).colorScheme.error,
146+
width: 1.0,
147+
),
148+
borderRadius: Corners.s10Border,
132149
),
133150
),
134151
);

frontend/app_flowy/packages/flowy_infra_ui/lib/widget/rounded_input_field.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class RoundedInputField extends StatefulWidget {
2727
final TextEditingController? controller;
2828
final bool autoFocus;
2929
final int? maxLength;
30+
final Function(String)? onFieldSubmitted;
3031

3132
const RoundedInputField({
3233
Key? key,
@@ -51,6 +52,7 @@ class RoundedInputField extends StatefulWidget {
5152
this.controller,
5253
this.autoFocus = false,
5354
this.maxLength,
55+
this.onFieldSubmitted,
5456
}) : super(key: key);
5557

5658
@override
@@ -106,6 +108,7 @@ class _RoundedInputFieldState extends State<RoundedInputField> {
106108
maxLength: widget.maxLength,
107109
maxLengthEnforcement:
108110
MaxLengthEnforcement.truncateAfterCompositionEnds,
111+
onFieldSubmitted: widget.onFieldSubmitted,
109112
onChanged: (value) {
110113
inputText = value;
111114
if (widget.onChanged != null) {

0 commit comments

Comments
 (0)