From 12ff548b09da7028943bb04ac3aa94d80ce6f927 Mon Sep 17 00:00:00 2001 From: Mathias Mogensen <42929161+Xazin@users.noreply.github.com> Date: Mon, 13 May 2024 15:45:27 +0200 Subject: [PATCH] fix: view action not working (#5325) --- .../more_view_actions/more_view_actions.dart | 42 +++++++++---------- .../widgets/common_view_action.dart | 4 +- 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/widgets/more_view_actions/more_view_actions.dart b/frontend/appflowy_flutter/lib/workspace/presentation/widgets/more_view_actions/more_view_actions.dart index 529807c4f4..3d0416f589 100644 --- a/frontend/appflowy_flutter/lib/workspace/presentation/widgets/more_view_actions/more_view_actions.dart +++ b/frontend/appflowy_flutter/lib/workspace/presentation/widgets/more_view_actions/more_view_actions.dart @@ -3,6 +3,7 @@ import 'package:flutter/material.dart'; import 'package:appflowy/generated/flowy_svgs.g.dart'; import 'package:appflowy/generated/locale_keys.g.dart'; import 'package:appflowy/workspace/application/settings/appearance/appearance_cubit.dart'; +import 'package:appflowy/workspace/application/view/view_bloc.dart'; import 'package:appflowy/workspace/application/view_info/view_info_bloc.dart'; import 'package:appflowy/workspace/presentation/widgets/more_view_actions/widgets/common_view_action.dart'; import 'package:appflowy/workspace/presentation/widgets/more_view_actions/widgets/font_size_action.dart'; @@ -33,23 +34,8 @@ class MoreViewActions extends StatefulWidget { } class _MoreViewActionsState extends State { - late final List viewActions; final popoverMutex = PopoverMutex(); - @override - void initState() { - super.initState(); - viewActions = ViewActionType.values - .map( - (type) => ViewAction( - type: type, - view: widget.view, - mutex: popoverMutex, - ), - ) - .toList(); - } - @override void dispose() { popoverMutex.dispose(); @@ -74,7 +60,13 @@ class _MoreViewActionsState extends State { const FontSizeAction(), const Divider(height: 4), ], - ...viewActions, + ...ViewActionType.values.map( + (type) => ViewAction( + type: type, + view: widget.view, + mutex: popoverMutex, + ), + ), if (state.documentCounters != null || state.createdAt != null) ...[ const Divider(height: 4), @@ -87,13 +79,17 @@ class _MoreViewActionsState extends State { ], ]; - return ListView.separated( - shrinkWrap: true, - padding: EdgeInsets.zero, - itemCount: actions.length, - separatorBuilder: (_, __) => const VSpace(4), - physics: StyledScrollPhysics(), - itemBuilder: (_, index) => actions[index], + return BlocProvider( + create: (_) => + ViewBloc(view: widget.view)..add(const ViewEvent.initial()), + child: ListView.separated( + shrinkWrap: true, + padding: EdgeInsets.zero, + itemCount: actions.length, + separatorBuilder: (_, __) => const VSpace(4), + physics: StyledScrollPhysics(), + itemBuilder: (_, index) => actions[index], + ), ); }, child: FlowyTooltip( diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/widgets/more_view_actions/widgets/common_view_action.dart b/frontend/appflowy_flutter/lib/workspace/presentation/widgets/more_view_actions/widgets/common_view_action.dart index 0ce56272b1..c54f6169a2 100644 --- a/frontend/appflowy_flutter/lib/workspace/presentation/widgets/more_view_actions/widgets/common_view_action.dart +++ b/frontend/appflowy_flutter/lib/workspace/presentation/widgets/more_view_actions/widgets/common_view_action.dart @@ -2,7 +2,6 @@ import 'package:flutter/material.dart'; import 'package:appflowy/generated/flowy_svgs.g.dart'; import 'package:appflowy/generated/locale_keys.g.dart'; -import 'package:appflowy/startup/startup.dart'; import 'package:appflowy/workspace/application/view/view_bloc.dart'; import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart'; import 'package:appflowy_popover/appflowy_popover.dart'; @@ -10,6 +9,7 @@ import 'package:easy_localization/easy_localization.dart'; import 'package:flowy_infra/theme_extension.dart'; import 'package:flowy_infra_ui/style_widget/button.dart'; import 'package:flowy_infra_ui/style_widget/text.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; enum ViewActionType { delete, @@ -47,7 +47,7 @@ class ViewAction extends StatelessWidget { Widget build(BuildContext context) { return FlowyButton( onTap: () { - getIt(param1: view).add(type.actionEvent); + context.read().add(type.actionEvent); mutex?.close(); }, text: FlowyText.regular(