fix: view action not working (#5325)

This commit is contained in:
Mathias Mogensen 2024-05-13 15:45:27 +02:00 committed by GitHub
parent 027ab2c1ef
commit 12ff548b09
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 25 deletions

View File

@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart'; import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.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/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/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/common_view_action.dart';
import 'package:appflowy/workspace/presentation/widgets/more_view_actions/widgets/font_size_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<MoreViewActions> { class _MoreViewActionsState extends State<MoreViewActions> {
late final List<Widget> viewActions;
final popoverMutex = PopoverMutex(); final popoverMutex = PopoverMutex();
@override
void initState() {
super.initState();
viewActions = ViewActionType.values
.map(
(type) => ViewAction(
type: type,
view: widget.view,
mutex: popoverMutex,
),
)
.toList();
}
@override @override
void dispose() { void dispose() {
popoverMutex.dispose(); popoverMutex.dispose();
@ -74,7 +60,13 @@ class _MoreViewActionsState extends State<MoreViewActions> {
const FontSizeAction(), const FontSizeAction(),
const Divider(height: 4), const Divider(height: 4),
], ],
...viewActions, ...ViewActionType.values.map(
(type) => ViewAction(
type: type,
view: widget.view,
mutex: popoverMutex,
),
),
if (state.documentCounters != null || if (state.documentCounters != null ||
state.createdAt != null) ...[ state.createdAt != null) ...[
const Divider(height: 4), const Divider(height: 4),
@ -87,13 +79,17 @@ class _MoreViewActionsState extends State<MoreViewActions> {
], ],
]; ];
return ListView.separated( return BlocProvider(
shrinkWrap: true, create: (_) =>
padding: EdgeInsets.zero, ViewBloc(view: widget.view)..add(const ViewEvent.initial()),
itemCount: actions.length, child: ListView.separated(
separatorBuilder: (_, __) => const VSpace(4), shrinkWrap: true,
physics: StyledScrollPhysics(), padding: EdgeInsets.zero,
itemBuilder: (_, index) => actions[index], itemCount: actions.length,
separatorBuilder: (_, __) => const VSpace(4),
physics: StyledScrollPhysics(),
itemBuilder: (_, index) => actions[index],
),
); );
}, },
child: FlowyTooltip( child: FlowyTooltip(

View File

@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart'; import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.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/workspace/application/view/view_bloc.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart'; import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
import 'package:appflowy_popover/appflowy_popover.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/theme_extension.dart';
import 'package:flowy_infra_ui/style_widget/button.dart'; import 'package:flowy_infra_ui/style_widget/button.dart';
import 'package:flowy_infra_ui/style_widget/text.dart'; import 'package:flowy_infra_ui/style_widget/text.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
enum ViewActionType { enum ViewActionType {
delete, delete,
@ -47,7 +47,7 @@ class ViewAction extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return FlowyButton( return FlowyButton(
onTap: () { onTap: () {
getIt<ViewBloc>(param1: view).add(type.actionEvent); context.read<ViewBloc>().add(type.actionEvent);
mutex?.close(); mutex?.close();
}, },
text: FlowyText.regular( text: FlowyText.regular(