Skip to content

Commit

Permalink
fixup! fixup! fixup! TW-1787: Update context menu for pinned screen
Browse files Browse the repository at this point in the history
  • Loading branch information
hieutbui committed Jun 4, 2024
1 parent 56d41ca commit 9c7e2d3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 101 deletions.
30 changes: 21 additions & 9 deletions lib/widgets/context_menu/context_menu_action.dart
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -18,4 +19,15 @@ class ContextMenuAction {
this.styleName,
this.padding,
});

@override
List<Object?> get props => [
name,
icon,
imagePath,
colorIcon,
iconSize,
styleName,
padding,
];
}
92 changes: 0 additions & 92 deletions lib/widgets/mixins/twake_context_menu_mixin.dart
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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),
),
),
],
),
),
);
}
}

0 comments on commit 9c7e2d3

Please sign in to comment.