From 9c7e2d3b98a910207ee93772a05eb99cfe54661e Mon Sep 17 00:00:00 2001 From: hieubt Date: Tue, 4 Jun 2024 11:08:41 +0700 Subject: [PATCH] fixup! fixup! fixup! TW-1787: Update context menu for pinned screen --- .../context_menu/context_menu_action.dart | 30 ++++-- .../mixins/twake_context_menu_mixin.dart | 92 ------------------- 2 files changed, 21 insertions(+), 101 deletions(-) diff --git a/lib/widgets/context_menu/context_menu_action.dart b/lib/widgets/context_menu/context_menu_action.dart index cbde6a7f81..7d02be5594 100644 --- a/lib/widgets/context_menu/context_menu_action.dart +++ b/lib/widgets/context_menu/context_menu_action.dart @@ -1,15 +1,16 @@ +import 'package:equatable/equatable.dart'; import 'package:flutter/material.dart'; -class ContextMenuAction { - String name; - IconData? icon; - String? imagePath; - Color? colorIcon; - double? iconSize; - TextStyle? styleName; - EdgeInsets? padding; +class ContextMenuAction extends Equatable { + final String name; + final IconData? icon; + final String? imagePath; + final Color? colorIcon; + final double? iconSize; + final TextStyle? styleName; + final EdgeInsets? padding; - ContextMenuAction({ + const ContextMenuAction({ required this.name, this.icon, this.imagePath, @@ -18,4 +19,15 @@ class ContextMenuAction { this.styleName, this.padding, }); + + @override + List get props => [ + name, + icon, + imagePath, + colorIcon, + iconSize, + styleName, + padding, + ]; } diff --git a/lib/widgets/mixins/twake_context_menu_mixin.dart b/lib/widgets/mixins/twake_context_menu_mixin.dart index 9c4d860f80..a7d1ff0b2d 100644 --- a/lib/widgets/mixins/twake_context_menu_mixin.dart +++ b/lib/widgets/mixins/twake_context_menu_mixin.dart @@ -1,9 +1,6 @@ import 'package:fluffychat/widgets/context_menu/context_menu_action.dart'; import 'package:fluffychat/widgets/context_menu/twake_context_menu.dart'; -import 'package:fluffychat/widgets/mixins/twake_context_menu_style.dart'; -import 'package:fluffychat/widgets/twake_app.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_svg/svg.dart'; /// Show a [TwakeContextMenu] on the given [BuildContext]. For other parameters, see [TwakeContextMenu]. mixin TwakeContextMenuMixin { @@ -31,93 +28,4 @@ mixin TwakeContextMenuMixin { }); return result; } - - Widget contextMenuItem( - BuildContext context, - String nameAction, { - IconData? iconAction, - String? imagePath, - Color? colorIcon, - double? iconSize, - TextStyle? styleName, - EdgeInsets? padding, - void Function()? onCallbackAction, - bool isClearCurrentPage = true, - }) { - return InkWell( - onTap: () { - if (isClearCurrentPage) { - TwakeApp.router.routerDelegate.pop(); - } - onCallbackAction!.call(); - }, - child: _itemBuilder( - context, - nameAction, - iconAction: iconAction, - imagePath: imagePath, - colorIcon: colorIcon, - iconSize: iconSize, - styleName: styleName, - padding: padding, - ), - ); - } - - Widget _itemBuilder( - BuildContext context, - String nameAction, { - IconData? iconAction, - String? imagePath, - Color? colorIcon, - double? iconSize, - TextStyle? styleName, - EdgeInsets? padding, - }) { - Widget buildIcon() { - // We try to get the SVG first and then the IconData - if (imagePath != null) { - return SvgPicture.asset( - imagePath, - width: iconSize ?? TwakeContextMenuStyle.defaultItemIconSize, - height: iconSize ?? TwakeContextMenuStyle.defaultItemIconSize, - fit: BoxFit.fill, - colorFilter: ColorFilter.mode( - colorIcon ?? TwakeContextMenuStyle.defaultItemColorIcon(context)!, - BlendMode.srcIn, - ), - ); - } - - if (iconAction != null) { - return Icon( - iconAction, - size: iconSize ?? TwakeContextMenuStyle.defaultItemIconSize, - color: - colorIcon ?? TwakeContextMenuStyle.defaultItemColorIcon(context), - ); - } - - return const SizedBox.shrink(); - } - - return Padding( - padding: padding ?? TwakeContextMenuStyle.defaultItemPadding, - child: SizedBox( - child: Row( - children: [ - buildIcon(), - const SizedBox(width: TwakeContextMenuStyle.defaultItemElementsGap), - Expanded( - child: Text( - nameAction, - style: styleName ?? - TwakeContextMenuStyle.defaultItemTextStyle(context), - ), - ), - ], - ), - ), - ); - } }