dev
dart 79 lines 2.38 KB
Raw
1 import 'dart:math';
2
3 import 'package:cake_wallet/themes/core/theme_extension.dart';
4 import 'package:flutter/material.dart';
5 import 'package:flutter/services.dart';
6
7 class CoinActionButton extends StatelessWidget {
8 const CoinActionButton({
9 super.key,
10 required this.icon,
11 required this.label,
12 required this.action,
13 });
14
15 final Widget icon;
16 final String label;
17 final VoidCallback action;
18
19 static const sizeFactor = 0.16;
20
21 @override
22 Widget build(BuildContext context) {
23 final size = MediaQuery.of(context).size.width * sizeFactor;
24 final double effectiveSize = min(size, 80);
25
26 // The caption below the circle is the accessible name, so it is excluded
27 // from the semantics tree to keep this a single button node.
28 return MergeSemantics(
29 child: Semantics(
30 button: true,
31 label: label,
32 child: Column(
33 children: [
34 Container(
35 width: effectiveSize,
36 height: effectiveSize,
37 decoration: BoxDecoration(
38 shape: BoxShape.circle,
39 gradient: LinearGradient(
40 colors: [
41 context.customColors.cardGradientColorPrimary,
42 context.customColors.cardGradientColorSecondary
43 ],
44 begin: Alignment.topCenter,
45 end: Alignment.bottomCenter,
46 ),
47 border: Border.all(
48 color: Theme.of(context).colorScheme.surfaceContainerHigh,
49 width: 1,
50 ),
51 ),
52 child: IconButton(
53 padding: EdgeInsets.zero,
54 constraints: const BoxConstraints(),
55 onPressed: () {
56 HapticFeedback.mediumImpact();
57 action();
58 },
59 icon: ExcludeSemantics(child: icon),
60 color: Theme.of(context).colorScheme.primary,
61 ),
62 ),
63 Padding(
64 padding: const EdgeInsets.only(top: 8.0),
65 child: ExcludeSemantics(
66 child: Text(
67 style: Theme.of(context).textTheme.bodySmall?.copyWith(
68 color: Theme.of(context).colorScheme.onSurfaceVariant,
69 ),
70 label,
71 ),
72 ),
73 ),
74 ],
75 ),
76 ),
77 );
78 }
79 }