| 1 | import 'package:cake_wallet/themes/core/custom_theme_colors.dart'; |
| 2 | import 'package:flutter/material.dart'; |
| 3 | |
| 4 | class TemplateTile extends StatefulWidget { |
| 5 | TemplateTile({ |
| 6 | Key? key, |
| 7 | required this.to, |
| 8 | required this.amount, |
| 9 | required this.from, |
| 10 | required this.onTap, |
| 11 | required this.onRemove, |
| 12 | this.hasMultipleRecipients, |
| 13 | }) : super(key: key); |
| 14 | |
| 15 | final String to; |
| 16 | final String amount; |
| 17 | final String from; |
| 18 | final VoidCallback onTap; |
| 19 | final VoidCallback onRemove; |
| 20 | final bool? hasMultipleRecipients; |
| 21 | |
| 22 | @override |
| 23 | TemplateTileState createState() => TemplateTileState(to, amount, from, onTap, onRemove); |
| 24 | } |
| 25 | |
| 26 | class TemplateTileState extends State<TemplateTile> { |
| 27 | TemplateTileState(this.to, this.amount, this.from, this.onTap, this.onRemove); |
| 28 | |
| 29 | final String to; |
| 30 | final String amount; |
| 31 | final String from; |
| 32 | final VoidCallback onTap; |
| 33 | final VoidCallback onRemove; |
| 34 | |
| 35 | bool isRemovable = false; |
| 36 | |
| 37 | @override |
| 38 | Widget build(BuildContext context) { |
| 39 | final toIcon = Image.asset( |
| 40 | 'assets/images/to_icon.png', |
| 41 | color: Theme.of(context).colorScheme.onSurface, |
| 42 | ); |
| 43 | |
| 44 | final content = Row( |
| 45 | mainAxisAlignment: MainAxisAlignment.start, |
| 46 | mainAxisSize: MainAxisSize.min, |
| 47 | children: widget.hasMultipleRecipients ?? false |
| 48 | ? [ |
| 49 | Text( |
| 50 | to, |
| 51 | style: Theme.of(context).textTheme.bodyMedium?.copyWith( |
| 52 | fontSize: 16, |
| 53 | fontWeight: FontWeight.w600, |
| 54 | color: Theme.of(context).colorScheme.onSurface, |
| 55 | ), |
| 56 | ), |
| 57 | ] |
| 58 | : [ |
| 59 | Text( |
| 60 | amount, |
| 61 | style: Theme.of(context).textTheme.bodyMedium?.copyWith( |
| 62 | fontSize: 16, |
| 63 | fontWeight: FontWeight.w600, |
| 64 | color: Theme.of(context).colorScheme.onSurface, |
| 65 | ), |
| 66 | ), |
| 67 | Padding( |
| 68 | padding: EdgeInsets.only(left: 5), |
| 69 | child: Text( |
| 70 | from, |
| 71 | style: Theme.of(context).textTheme.bodyMedium?.copyWith( |
| 72 | fontSize: 16, |
| 73 | fontWeight: FontWeight.w600, |
| 74 | color: Theme.of(context).colorScheme.onSurface, |
| 75 | ), |
| 76 | ), |
| 77 | ), |
| 78 | Padding( |
| 79 | padding: EdgeInsets.only(left: 5), |
| 80 | child: toIcon, |
| 81 | ), |
| 82 | Padding( |
| 83 | padding: EdgeInsets.only(left: 5), |
| 84 | child: Text( |
| 85 | to, |
| 86 | style: Theme.of(context).textTheme.bodyMedium?.copyWith( |
| 87 | fontSize: 16, |
| 88 | fontWeight: FontWeight.w600, |
| 89 | color: Theme.of(context).colorScheme.onSurface, |
| 90 | ), |
| 91 | ), |
| 92 | ), |
| 93 | ], |
| 94 | ); |
| 95 | |
| 96 | final tile = Container( |
| 97 | padding: EdgeInsets.only(right: 10), |
| 98 | child: ClipRRect( |
| 99 | borderRadius: BorderRadius.all(Radius.circular(12)), |
| 100 | child: GestureDetector( |
| 101 | onTap: onTap, |
| 102 | onLongPress: () { |
| 103 | setState(() { |
| 104 | isRemovable = true; |
| 105 | }); |
| 106 | }, |
| 107 | child: Container( |
| 108 | height: 40, |
| 109 | padding: EdgeInsets.only(left: 24, right: 24), |
| 110 | color: Theme.of(context).colorScheme.surfaceContainerHighest, |
| 111 | child: content, |
| 112 | ), |
| 113 | ), |
| 114 | )); |
| 115 | |
| 116 | final removableTile = Container( |
| 117 | padding: EdgeInsets.only(right: 10), |
| 118 | child: ClipRRect( |
| 119 | borderRadius: BorderRadius.all(Radius.circular(12)), |
| 120 | child: Row( |
| 121 | mainAxisSize: MainAxisSize.min, |
| 122 | children: <Widget>[ |
| 123 | GestureDetector( |
| 124 | onTap: () { |
| 125 | setState(() { |
| 126 | isRemovable = false; |
| 127 | }); |
| 128 | }, |
| 129 | child: Container( |
| 130 | height: 40, |
| 131 | padding: EdgeInsets.only(left: 24, right: 10), |
| 132 | color: CustomThemeColors.syncYellow, |
| 133 | child: content, |
| 134 | ), |
| 135 | ), |
| 136 | GestureDetector( |
| 137 | onTap: onRemove, |
| 138 | child: Container( |
| 139 | height: 40, |
| 140 | width: 44, |
| 141 | color: Theme.of(context).colorScheme.errorContainer, |
| 142 | child: Center( |
| 143 | child: Image.asset( |
| 144 | 'assets/images/trash.png', |
| 145 | height: 16, |
| 146 | width: 16, |
| 147 | color: Theme.of(context).colorScheme.onErrorContainer, |
| 148 | ), |
| 149 | ), |
| 150 | ), |
| 151 | ) |
| 152 | ], |
| 153 | ), |
| 154 | ), |
| 155 | ); |
| 156 | |
| 157 | return isRemovable ? removableTile : tile; |
| 158 | } |
| 159 | } |