@@ -2,6 +2,7 @@ import 'package:app_flowy/plugins/grid/application/cell/cell_service/cell_servic
22import 'package:app_flowy/plugins/grid/application/field/type_option/type_option_context.dart' ;
33import 'package:app_flowy/plugins/grid/application/row/row_data_controller.dart' ;
44import 'package:app_flowy/plugins/grid/application/row/row_detail_bloc.dart' ;
5+ import 'package:app_flowy/workspace/presentation/widgets/dialogs.dart' ;
56import 'package:flowy_infra/image.dart' ;
67import 'package:flowy_infra/theme.dart' ;
78import 'package:flowy_infra_ui/flowy_infra_ui.dart' ;
@@ -112,67 +113,61 @@ class _PropertyList extends StatelessWidget {
112113 builder: (context, state) {
113114 return Column (
114115 children: [
115- Expanded (
116- child: ScrollbarListStack (
117- axis: Axis .vertical,
118- controller: _scrollController,
119- barSize: GridSize .scrollBarSize,
120- autoHideScrollbar: false ,
121- child: ListView .separated (
122- controller: _scrollController,
123- itemCount: state.gridCells.length,
124- itemBuilder: (BuildContext context, int index) {
125- return _RowDetailCell (
126- cellId: state.gridCells[index],
127- cellBuilder: cellBuilder,
128- );
129- },
130- separatorBuilder: (BuildContext context, int index) {
131- return const VSpace (2 );
132- },
133- ),
134- ),
135- ),
116+ Expanded (child: _wrapScrollbar (buildList (state))),
136117 const VSpace (10 ),
137118 _CreateFieldButton (
138119 viewId: viewId,
139- onClosed: () {
140- WidgetsBinding .instance.addPostFrameCallback ((_) {
141- _scrollController.animateTo (
142- _scrollController.position.maxScrollExtent,
143- duration: const Duration (milliseconds: 250 ),
144- curve: Curves .ease,
145- );
146- });
147- },
148- onOpened: (controller) {
149- return FieldEditor (
150- gridId: viewId,
151- typeOptionLoader: NewFieldTypeOptionLoader (gridId: viewId),
152- onDeleted: (fieldId) {
153- controller.close ();
154- context
155- .read <RowDetailBloc >()
156- .add (RowDetailEvent .deleteField (fieldId));
157- },
158- );
159- },
120+ onClosed: _handleDidCreateField,
160121 ),
161122 ],
162123 );
163124 },
164125 );
165126 }
127+
128+ Widget buildList (RowDetailState state) {
129+ return ListView .separated (
130+ controller: _scrollController,
131+ itemCount: state.gridCells.length,
132+ itemBuilder: (BuildContext context, int index) {
133+ return _RowDetailCell (
134+ cellId: state.gridCells[index],
135+ cellBuilder: cellBuilder,
136+ );
137+ },
138+ separatorBuilder: (BuildContext context, int index) {
139+ return const VSpace (2 );
140+ },
141+ );
142+ }
143+
144+ Widget _wrapScrollbar (Widget child) {
145+ return ScrollbarListStack (
146+ axis: Axis .vertical,
147+ controller: _scrollController,
148+ barSize: GridSize .scrollBarSize,
149+ autoHideScrollbar: false ,
150+ child: child,
151+ );
152+ }
153+
154+ void _handleDidCreateField () {
155+ WidgetsBinding .instance.addPostFrameCallback ((_) {
156+ _scrollController.animateTo (
157+ _scrollController.position.maxScrollExtent,
158+ duration: const Duration (milliseconds: 250 ),
159+ curve: Curves .ease,
160+ );
161+ });
162+ }
166163}
167164
168165class _CreateFieldButton extends StatefulWidget {
169166 final String viewId;
170- final Widget Function (PopoverController ) onOpened;
171167 final VoidCallback onClosed;
172168
173169 const _CreateFieldButton ({
174170 required this .viewId,
175- required this .onOpened,
176171 required this .onClosed,
177172 Key ? key,
178173 }) : super (key: key);
@@ -213,8 +208,24 @@ class _CreateFieldButtonState extends State<_CreateFieldButton> {
213208 leftIcon: svgWidget ("home/add" ),
214209 ),
215210 ),
216- popupBuilder: (BuildContext context) =>
217- widget.onOpened (popoverController),
211+ popupBuilder: (BuildContext popOverContext) {
212+ return FieldEditor (
213+ gridId: widget.viewId,
214+ typeOptionLoader: NewFieldTypeOptionLoader (gridId: widget.viewId),
215+ onDeleted: (fieldId) {
216+ popoverController.close ();
217+
218+ NavigatorAlertDialog (
219+ title: LocaleKeys .grid_field_deleteFieldPromptMessage.tr (),
220+ confirm: () {
221+ context
222+ .read <RowDetailBloc >()
223+ .add (RowDetailEvent .deleteField (fieldId));
224+ },
225+ ).show (context);
226+ },
227+ );
228+ },
218229 );
219230 }
220231
@@ -260,41 +271,24 @@ class _RowDetailCellState extends State<_RowDetailCell> {
260271 ),
261272 );
262273
263- return ConstrainedBox (
264- constraints : const BoxConstraints (minHeight : 40 ),
265- child : IntrinsicHeight (
274+ return IntrinsicHeight (
275+ child : ConstrainedBox (
276+ constraints : const BoxConstraints (minHeight : 40 ),
266277 child: Row (
267278 crossAxisAlignment: CrossAxisAlignment .stretch,
268279 mainAxisAlignment: MainAxisAlignment .center,
269280 children: [
270- SizedBox (
271- width: 150 ,
272- child: Popover (
273- controller: popover,
274- offset: const Offset (20 , 0 ),
275- popupBuilder: (popoverContext) {
276- return OverlayContainer (
277- constraints: BoxConstraints .loose (const Size (240 , 600 )),
278- child: FieldEditor (
279- gridId: widget.cellId.gridId,
280- fieldName: widget.cellId.fieldContext.field.name,
281- isGroupField: widget.cellId.fieldContext.isGroupField,
282- typeOptionLoader: FieldTypeOptionLoader (
283- gridId: widget.cellId.gridId,
284- field: widget.cellId.fieldContext.field,
285- ),
286- onDeleted: (fieldId) {
287- popover.close ();
288- context
289- .read <RowDetailBloc >()
290- .add (RowDetailEvent .deleteField (fieldId));
291- },
292- ),
293- );
294- },
281+ AppFlowyPopover (
282+ controller: popover,
283+ constraints: BoxConstraints .loose (const Size (240 , 600 )),
284+ popupBuilder: (popoverContext) => buildFieldEditor (),
285+ child: SizedBox (
286+ width: 150 ,
295287 child: FieldCellButton (
296288 field: widget.cellId.fieldContext.field,
297- onTap: () => popover.show (),
289+ onTap: () {
290+ popover.show ();
291+ },
298292 ),
299293 ),
300294 ),
@@ -305,6 +299,30 @@ class _RowDetailCellState extends State<_RowDetailCell> {
305299 ),
306300 );
307301 }
302+
303+ Widget buildFieldEditor () {
304+ return FieldEditor (
305+ gridId: widget.cellId.gridId,
306+ fieldName: widget.cellId.fieldContext.field.name,
307+ isGroupField: widget.cellId.fieldContext.isGroupField,
308+ typeOptionLoader: FieldTypeOptionLoader (
309+ gridId: widget.cellId.gridId,
310+ field: widget.cellId.fieldContext.field,
311+ ),
312+ onDeleted: (fieldId) {
313+ popover.close ();
314+
315+ NavigatorAlertDialog (
316+ title: LocaleKeys .grid_field_deleteFieldPromptMessage.tr (),
317+ confirm: () {
318+ context
319+ .read <RowDetailBloc >()
320+ .add (RowDetailEvent .deleteField (fieldId));
321+ },
322+ ).show (context);
323+ },
324+ );
325+ }
308326}
309327
310328GridCellStyle ? _customCellStyle (AppTheme theme, FieldType fieldType) {
0 commit comments