mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
fix: arrow keys on field name text field (#3162)
This commit is contained in:
parent
72363921b0
commit
e9f31ea0f8
@ -2,7 +2,6 @@ import 'package:appflowy/generated/flowy_svgs.g.dart';
|
||||
import 'package:appflowy/plugins/database_view/application/field/field_editor_bloc.dart';
|
||||
import 'package:appflowy/plugins/database_view/application/field/type_option/type_option_context.dart';
|
||||
import 'package:appflowy_popover/appflowy_popover.dart';
|
||||
import 'package:dartz/dartz.dart' show none;
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
|
||||
import 'package:flowy_infra_ui/style_widget/button.dart';
|
||||
@ -164,6 +163,8 @@ class _FieldNameTextFieldState extends State<FieldNameTextField> {
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
focusNode.addListener(() {
|
||||
if (focusNode.hasFocus) {
|
||||
widget.popoverMutex.close();
|
||||
@ -175,39 +176,28 @@ class _FieldNameTextFieldState extends State<FieldNameTextField> {
|
||||
focusNode.unfocus();
|
||||
}
|
||||
});
|
||||
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocListener<FieldEditorBloc, FieldEditorState>(
|
||||
listenWhen: (p, c) => p.field == none(),
|
||||
listener: (context, state) {
|
||||
textController.text = state.name;
|
||||
focusNode.requestFocus();
|
||||
return BlocBuilder<FieldEditorBloc, FieldEditorState>(
|
||||
builder: (context, state) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12.0),
|
||||
child: FlowyTextField(
|
||||
focusNode: focusNode,
|
||||
controller: textController,
|
||||
onSubmitted: (String _) => PopoverContainer.of(context).close(),
|
||||
text: state.name,
|
||||
errorText: state.errorText.isEmpty ? null : state.errorText,
|
||||
onChanged: (newName) {
|
||||
context
|
||||
.read<FieldEditorBloc>()
|
||||
.add(FieldEditorEvent.updateName(newName));
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
child: BlocBuilder<FieldEditorBloc, FieldEditorState>(
|
||||
buildWhen: (previous, current) =>
|
||||
previous.errorText != current.errorText,
|
||||
builder: (context, state) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12.0),
|
||||
child: FlowyTextField(
|
||||
focusNode: focusNode,
|
||||
controller: textController,
|
||||
onSubmitted: (String _) => PopoverContainer.of(context).close(),
|
||||
text: state.name,
|
||||
errorText: state.errorText.isEmpty ? null : state.errorText,
|
||||
onChanged: (newName) {
|
||||
context
|
||||
.read<FieldEditorBloc>()
|
||||
.add(FieldEditorEvent.updateName(newName));
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -54,15 +54,13 @@ class FlowyTextFieldState extends State<FlowyTextField> {
|
||||
focusNode = widget.focusNode ?? FocusNode();
|
||||
focusNode.addListener(notifyDidEndEditing);
|
||||
|
||||
if (widget.controller != null) {
|
||||
controller = widget.controller!;
|
||||
} else {
|
||||
controller = TextEditingController();
|
||||
controller.text = widget.text;
|
||||
}
|
||||
controller = widget.controller ?? TextEditingController();
|
||||
controller.text = widget.text;
|
||||
if (widget.autoFocus) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
focusNode.requestFocus();
|
||||
controller.selection = TextSelection.fromPosition(
|
||||
TextPosition(offset: controller.text.length));
|
||||
});
|
||||
}
|
||||
super.initState();
|
||||
|
Loading…
Reference in New Issue
Block a user