dev
dart 96 lines 2.98 KB
Raw
1 import 'package:flutter/material.dart';
2 import 'package:flutter_slidable/flutter_slidable.dart';
3 import 'package:cake_wallet/generated/i18n.dart';
4
5 class AccountTile extends StatelessWidget {
6 AccountTile({
7 required this.isCurrent,
8 required this.accountName,
9 this.accountBalance,
10 required this.currency,
11 required this.onTap,
12 required this.onEdit,
13 });
14
15 final bool isCurrent;
16 final String accountName;
17 final String? accountBalance;
18 final String currency;
19 final Function() onTap;
20 final Function() onEdit;
21
22 @override
23 Widget build(BuildContext context) {
24 final color = isCurrent
25 ? Theme.of(context).colorScheme.surfaceContainer
26 : Theme.of(context).colorScheme.surfaceContainerHighest;
27 final textColor = isCurrent
28 ? Theme.of(context).colorScheme.onSurface
29 : Theme.of(context).colorScheme.onSurfaceVariant;
30
31 final Widget cell = GestureDetector(
32 onTap: onTap,
33 child: Container(
34 height: 60,
35 width: double.infinity,
36 padding: EdgeInsets.only(left: 24, right: 24),
37 color: color,
38 child: Wrap(
39 direction: Axis.horizontal,
40 alignment: WrapAlignment.spaceBetween,
41 runAlignment: WrapAlignment.center,
42 crossAxisAlignment: WrapCrossAlignment.center,
43 children: [
44 Container(
45 child: Text(
46 accountName,
47 style: Theme.of(context).textTheme.titleMedium!.copyWith(
48 fontSize: 18,
49 fontWeight: FontWeight.w600,
50 color: textColor,
51 decoration: TextDecoration.none,
52 ),
53 ),
54 ),
55 if (accountBalance != null)
56 Container(
57 child: Text(
58 '${accountBalance.toString()} $currency',
59 textAlign: TextAlign.end,
60 style: Theme.of(context).textTheme.bodyMedium!.copyWith(
61 fontSize: 15,
62 fontWeight: FontWeight.w600,
63 color: isCurrent
64 ? Theme.of(context).colorScheme.onSurface
65 : Theme.of(context).colorScheme.onSurfaceVariant,
66 decoration: TextDecoration.none,
67 ),
68 ),
69 ),
70 ],
71 ),
72 ),
73 );
74
75 // return cell;
76 return Slidable(
77 key: Key(accountName),
78 child: cell,
79 endActionPane: _actionPane(context),
80 );
81 }
82
83 ActionPane _actionPane(BuildContext context) => ActionPane(
84 motion: const ScrollMotion(),
85 extentRatio: 0.3,
86 children: [
87 SlidableAction(
88 onPressed: (_) => onEdit.call(),
89 backgroundColor: Theme.of(context).colorScheme.primaryContainer,
90 foregroundColor: Theme.of(context).colorScheme.onPrimaryContainer,
91 icon: Icons.edit,
92 label: S.of(context).edit,
93 ),
94 ],
95 );
96 }