11import 'package:app_flowy/plugins/grid/application/field/field_editor_bloc.dart' ;
22import 'package:app_flowy/plugins/grid/application/field/type_option/type_option_context.dart' ;
33import 'package:appflowy_popover/appflowy_popover.dart' ;
4+ import 'package:dartz/dartz.dart' show none;
45import 'package:easy_localization/easy_localization.dart' ;
5- import 'package:app_flowy/workspace/presentation/widgets/dialogs.dart' ;
66import 'package:flowy_infra/theme.dart' ;
7- import 'package:flowy_infra_ui/flowy_infra_ui.dart' ;
87import 'package:flowy_infra_ui/style_widget/button.dart' ;
98import 'package:flowy_infra_ui/style_widget/text.dart' ;
109import 'package:flowy_infra_ui/widget/rounded_input_field.dart' ;
@@ -59,38 +58,38 @@ class _FieldEditorState extends State<FieldEditor> {
5958 isGroupField: widget.isGroupField,
6059 loader: widget.typeOptionLoader,
6160 )..add (const FieldEditorEvent .initial ()),
62- child: BlocBuilder <FieldEditorBloc , FieldEditorState >(
63- builder: (context, state) {
64- return ListView (
65- shrinkWrap: true ,
66- children: [
67- FlowyText .medium (
68- LocaleKeys .grid_field_editProperty.tr (),
69- fontSize: 12 ,
70- ),
71- const VSpace (10 ),
72- _FieldNameTextField (popoverMutex: popoverMutex),
73- const VSpace (10 ),
74- ..._addDeleteFieldButton (state),
75- _FieldTypeOptionCell (popoverMutex: popoverMutex),
76- ],
77- );
78- },
61+ child: ListView (
62+ shrinkWrap: true ,
63+ children: [
64+ FlowyText .medium (
65+ LocaleKeys .grid_field_editProperty.tr (),
66+ fontSize: 12 ,
67+ ),
68+ const VSpace (10 ),
69+ _FieldNameTextField (popoverMutex: popoverMutex),
70+ const VSpace (10 ),
71+ ..._addDeleteFieldButton (),
72+ _FieldTypeOptionCell (popoverMutex: popoverMutex),
73+ ],
7974 ),
8075 );
8176 }
8277
83- List <Widget > _addDeleteFieldButton (FieldEditorState state ) {
78+ List <Widget > _addDeleteFieldButton () {
8479 if (widget.onDeleted == null ) {
8580 return [];
8681 }
8782 return [
88- _DeleteFieldButton (
89- popoverMutex: popoverMutex,
90- onDeleted: () {
91- state.field.fold (
92- () => Log .error ('Can not delete the field' ),
93- (field) => widget.onDeleted? .call (field.id),
83+ BlocBuilder <FieldEditorBloc , FieldEditorState >(
84+ builder: (context, state) {
85+ return _DeleteFieldButton (
86+ popoverMutex: popoverMutex,
87+ onDeleted: () {
88+ state.field.fold (
89+ () => Log .error ('Can not delete the field' ),
90+ (field) => widget.onDeleted? .call (field.id),
91+ );
92+ },
9493 );
9594 },
9695 ),
@@ -139,13 +138,13 @@ class _FieldNameTextField extends StatefulWidget {
139138}
140139
141140class _FieldNameTextFieldState extends State <_FieldNameTextField > {
142- late String name;
143141 FocusNode focusNode = FocusNode ();
144142 VoidCallback ? _popoverCallback;
145- TextEditingController controller = TextEditingController () ;
143+ late TextEditingController controller;
146144
147145 @override
148146 void initState () {
147+ controller = TextEditingController ();
149148 focusNode.addListener (() {
150149 if (focusNode.hasFocus) {
151150 widget.popoverMutex.close ();
@@ -158,20 +157,29 @@ class _FieldNameTextFieldState extends State<_FieldNameTextField> {
158157 @override
159158 Widget build (BuildContext context) {
160159 final theme = context.watch <AppTheme >();
161-
162- controller.text = context.read <FieldEditorBloc >().state.name;
163- return BlocListener <FieldEditorBloc , FieldEditorState >(
164- listenWhen: (previous, current) => previous.name != current.name,
165- listener: (context, state) {
166- controller.text = state.name;
167- },
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+ ],
168175 child: BlocBuilder <FieldEditorBloc , FieldEditorState >(
176+ buildWhen: (previous, current) =>
177+ previous.errorText != current.errorText,
169178 builder: (context, state) {
170179 listenOnPopoverChanged (context);
171180
172181 return RoundedInputField (
173182 height: 36 ,
174- autoFocus: true ,
175183 focusNode: focusNode,
176184 style: const TextStyle (fontSize: 13 , fontWeight: FontWeight .w500),
177185 controller: controller,
@@ -202,14 +210,6 @@ class _FieldNameTextFieldState extends State<_FieldNameTextField> {
202210 }
203211 });
204212 }
205-
206- @override
207- void didUpdateWidget (covariant _FieldNameTextField oldWidget) {
208- controller.selection = TextSelection .fromPosition (
209- TextPosition (offset: controller.text.length));
210-
211- super .didUpdateWidget (oldWidget);
212- }
213213}
214214
215215class _DeleteFieldButton extends StatelessWidget {
@@ -235,29 +235,11 @@ class _DeleteFieldButton extends StatelessWidget {
235235 fontSize: 12 ,
236236 color: enable ? null : theme.shader4,
237237 ),
238+ onTap: () => onDeleted? .call (),
238239 );
239- if (enable) button = _wrapPopover ( button) ;
240+ // if (enable) button = button;
240241 return button;
241242 },
242243 );
243244 }
244-
245- Widget _wrapPopover (Widget widget) {
246- return AppFlowyPopover (
247- triggerActions: PopoverTriggerFlags .click,
248- constraints: BoxConstraints .loose (const Size (400 , 240 )),
249- mutex: popoverMutex,
250- direction: PopoverDirection .center,
251- popupBuilder: (popupContext) {
252- return PopoverAlertView (
253- title: LocaleKeys .grid_field_deleteFieldPromptMessage.tr (),
254- cancel: () {},
255- confirm: () {
256- onDeleted? .call ();
257- },
258- );
259- },
260- child: widget,
261- );
262- }
263245}
0 commit comments