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:
@ -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/field_editor_bloc.dart';
|
||||||
import 'package:appflowy/plugins/database_view/application/field/type_option/type_option_context.dart';
|
import 'package:appflowy/plugins/database_view/application/field/type_option/type_option_context.dart';
|
||||||
import 'package:appflowy_popover/appflowy_popover.dart';
|
import 'package:appflowy_popover/appflowy_popover.dart';
|
||||||
import 'package:dartz/dartz.dart' show none;
|
|
||||||
import 'package:easy_localization/easy_localization.dart';
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
|
|
||||||
import 'package:flowy_infra_ui/style_widget/button.dart';
|
import 'package:flowy_infra_ui/style_widget/button.dart';
|
||||||
@ -164,6 +163,8 @@ class _FieldNameTextFieldState extends State<FieldNameTextField> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
|
||||||
focusNode.addListener(() {
|
focusNode.addListener(() {
|
||||||
if (focusNode.hasFocus) {
|
if (focusNode.hasFocus) {
|
||||||
widget.popoverMutex.close();
|
widget.popoverMutex.close();
|
||||||
@ -175,39 +176,28 @@ class _FieldNameTextFieldState extends State<FieldNameTextField> {
|
|||||||
focusNode.unfocus();
|
focusNode.unfocus();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
super.initState();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocListener<FieldEditorBloc, FieldEditorState>(
|
return BlocBuilder<FieldEditorBloc, FieldEditorState>(
|
||||||
listenWhen: (p, c) => p.field == none(),
|
builder: (context, state) {
|
||||||
listener: (context, state) {
|
return Padding(
|
||||||
textController.text = state.name;
|
padding: const EdgeInsets.symmetric(horizontal: 12.0),
|
||||||
focusNode.requestFocus();
|
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 = widget.focusNode ?? FocusNode();
|
||||||
focusNode.addListener(notifyDidEndEditing);
|
focusNode.addListener(notifyDidEndEditing);
|
||||||
|
|
||||||
if (widget.controller != null) {
|
controller = widget.controller ?? TextEditingController();
|
||||||
controller = widget.controller!;
|
controller.text = widget.text;
|
||||||
} else {
|
|
||||||
controller = TextEditingController();
|
|
||||||
controller.text = widget.text;
|
|
||||||
}
|
|
||||||
if (widget.autoFocus) {
|
if (widget.autoFocus) {
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
focusNode.requestFocus();
|
focusNode.requestFocus();
|
||||||
|
controller.selection = TextSelection.fromPosition(
|
||||||
|
TextPosition(offset: controller.text.length));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
super.initState();
|
super.initState();
|
||||||
|
Reference in New Issue
Block a user