| 1 | import 'dart:ui'; |
| 2 | |
| 3 | import 'package:cake_wallet/src/widgets/cake_image_widget.dart'; |
| 4 | import 'package:flutter/material.dart'; |
| 5 | import 'package:flutter_svg/svg.dart'; |
| 6 | |
| 7 | class LongPressMenuItem { |
| 8 | final String label; |
| 9 | final String iconPath; |
| 10 | final VoidCallback onSelected; |
| 11 | final Color? color; |
| 12 | |
| 13 | LongPressMenuItem( |
| 14 | {required this.label, required this.iconPath, required this.onSelected, this.color}); |
| 15 | } |
| 16 | |
| 17 | class LongPressMenu extends StatefulWidget { |
| 18 | const LongPressMenu({super.key, required this.items}); |
| 19 | |
| 20 | final List<LongPressMenuItem> items; |
| 21 | |
| 22 | @override |
| 23 | State<LongPressMenu> createState() => _LongPressMenuState(); |
| 24 | } |
| 25 | |
| 26 | class _LongPressMenuState extends State<LongPressMenu> { |
| 27 | bool _isVisible = false; |
| 28 | |
| 29 | @override |
| 30 | void initState() { |
| 31 | super.initState(); |
| 32 | WidgetsBinding.instance.addPostFrameCallback((_) { |
| 33 | setState(() { |
| 34 | _isVisible = true; |
| 35 | }); |
| 36 | }); |
| 37 | } |
| 38 | |
| 39 | @override |
| 40 | Widget build(BuildContext context) { |
| 41 | return AnimatedSize( |
| 42 | duration: Duration(milliseconds: 300), |
| 43 | curve: Curves.easeOutCubic, |
| 44 | alignment: Alignment.topCenter, |
| 45 | child: SizedBox( |
| 46 | height: _isVisible ? null : 0, |
| 47 | child: ClipRRect( |
| 48 | borderRadius: BorderRadius.circular(20), |
| 49 | child: BackdropFilter( |
| 50 | filter: ImageFilter.blur(sigmaX: 10.0, sigmaY: 10.0), |
| 51 | child: Container( |
| 52 | decoration: BoxDecoration( |
| 53 | borderRadius: BorderRadius.circular(20), |
| 54 | color: Theme.of(context).colorScheme.primary.withAlpha(60), |
| 55 | ), |
| 56 | child: Column( |
| 57 | mainAxisSize: MainAxisSize.min, |
| 58 | crossAxisAlignment: CrossAxisAlignment.start, |
| 59 | children: widget.items.map((item) { |
| 60 | final color = item.color ?? Theme.of(context).colorScheme.onSurface; |
| 61 | return Material( |
| 62 | color: Colors.transparent, |
| 63 | child: MergeSemantics( |
| 64 | child: Semantics( |
| 65 | button: true, |
| 66 | child: InkWell( |
| 67 | onTap: item.onSelected, |
| 68 | child: Padding( |
| 69 | padding: EdgeInsets.only( |
| 70 | left: 16, |
| 71 | right: 16, |
| 72 | top: 12, |
| 73 | bottom: 12, |
| 74 | ), |
| 75 | child: Container( |
| 76 | child: Row( |
| 77 | crossAxisAlignment: CrossAxisAlignment.center, |
| 78 | mainAxisAlignment: MainAxisAlignment.start, |
| 79 | spacing: 8, |
| 80 | children: [ |
| 81 | ExcludeSemantics( |
| 82 | child: CakeImageWidget( |
| 83 | imageUrl: item.iconPath, |
| 84 | height: 20, |
| 85 | width: 20, |
| 86 | colorFilter: ColorFilter.mode(color, BlendMode.srcIn), |
| 87 | ), |
| 88 | ), |
| 89 | Text(item.label, |
| 90 | style: TextStyle( |
| 91 | color: color, fontSize: 14, fontWeight: FontWeight.w500)), |
| 92 | ], |
| 93 | ), |
| 94 | ), |
| 95 | ), |
| 96 | ), |
| 97 | ), |
| 98 | ), |
| 99 | ); |
| 100 | }).toList(), |
| 101 | ), |
| 102 | ), |
| 103 | ), |
| 104 | ), |
| 105 | ), |
| 106 | ); |
| 107 | } |
| 108 | } |