From af98febcb0e993868f48ac0640075cb0426142c3 Mon Sep 17 00:00:00 2001 From: appflowy Date: Fri, 23 Sep 2022 15:10:20 +0800 Subject: [PATCH] fix: can't find context after popover disappear --- .../header/field_cell_action_sheet.dart | 34 +++++++++++-------- .../appflowy_popover/lib/src/popover.dart | 5 ++- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/frontend/app_flowy/lib/plugins/grid/presentation/widgets/header/field_cell_action_sheet.dart b/frontend/app_flowy/lib/plugins/grid/presentation/widgets/header/field_cell_action_sheet.dart index 398a2206ae..5dca885414 100644 --- a/frontend/app_flowy/lib/plugins/grid/presentation/widgets/header/field_cell_action_sheet.dart +++ b/frontend/app_flowy/lib/plugins/grid/presentation/widgets/header/field_cell_action_sheet.dart @@ -93,9 +93,9 @@ class _EditFieldButton extends StatelessWidget { } class _FieldOperationList extends StatelessWidget { - final GridFieldCellContext fieldData; + final GridFieldCellContext fieldContext; final VoidCallback onDismissed; - const _FieldOperationList(this.fieldData, this.onDismissed, {Key? key}) + const _FieldOperationList(this.fieldContext, this.onDismissed, {Key? key}) : super(key: key); @override @@ -118,14 +118,14 @@ class _FieldOperationList extends StatelessWidget { bool enable = true; switch (action) { case FieldAction.delete: - enable = !fieldData.field.isPrimary; + enable = !fieldContext.field.isPrimary; break; default: break; } return FieldActionCell( - fieldId: fieldData.field.id, + fieldContext: fieldContext, action: action, onTap: onDismissed, enable: enable, @@ -136,13 +136,13 @@ class _FieldOperationList extends StatelessWidget { } class FieldActionCell extends StatelessWidget { - final String fieldId; + final GridFieldCellContext fieldContext; final VoidCallback onTap; final FieldAction action; final bool enable; const FieldActionCell({ - required this.fieldId, + required this.fieldContext, required this.action, required this.onTap, required this.enable, @@ -161,7 +161,7 @@ class FieldActionCell extends StatelessWidget { hoverColor: theme.hover, onTap: () { if (enable) { - action.run(context); + action.run(context, fieldContext); onTap(); } }, @@ -202,7 +202,7 @@ extension _FieldActionExtension on FieldAction { } } - void run(BuildContext context) { + void run(BuildContext context, GridFieldCellContext fieldContext) { switch (this) { case FieldAction.hide: context @@ -210,18 +210,24 @@ extension _FieldActionExtension on FieldAction { .add(const FieldActionSheetEvent.hideField()); break; case FieldAction.duplicate: - context - .read() - .add(const FieldActionSheetEvent.duplicateField()); + PopoverContainer.of(context).close(); + + FieldService( + gridId: fieldContext.gridId, + fieldId: fieldContext.field.id, + ).duplicateField(); + break; case FieldAction.delete: PopoverContainer.of(context).close(); + NavigatorAlertDialog( title: LocaleKeys.grid_field_deleteFieldPromptMessage.tr(), confirm: () { - context - .read() - .add(const FieldActionSheetEvent.deleteField()); + FieldService( + gridId: fieldContext.gridId, + fieldId: fieldContext.field.id, + ).deleteField(); }, ).show(context); diff --git a/frontend/app_flowy/packages/appflowy_popover/lib/src/popover.dart b/frontend/app_flowy/packages/appflowy_popover/lib/src/popover.dart index a817572c66..6b666c278c 100644 --- a/frontend/app_flowy/packages/appflowy_popover/lib/src/popover.dart +++ b/frontend/app_flowy/packages/appflowy_popover/lib/src/popover.dart @@ -136,7 +136,6 @@ class PopoverState extends State { return Stack(children: children); }); - _rootEntry.addEntry(context, this, newEntry, widget.asBarrier); } @@ -243,7 +242,7 @@ class PopoverContainerState extends State { ); } - close() => widget.onClose(); + void close() => widget.onClose(); - closeAll() => widget.onCloseAll(); + void closeAll() => widget.onCloseAll(); }