|
| 1 | +import 'package:decimal/decimal.dart'; |
| 2 | +import 'package:flutter/material.dart'; |
| 3 | +import 'package:flutter_riverpod/flutter_riverpod.dart'; |
| 4 | +import 'package:stackwallet/providers/providers.dart'; |
| 5 | +import 'package:stackwallet/providers/wallet/public_private_balance_state_provider.dart'; |
| 6 | +import 'package:stackwallet/services/coins/firo/firo_wallet.dart'; |
| 7 | +import 'package:stackwallet/utilities/cfcolors.dart'; |
| 8 | +import 'package:stackwallet/utilities/constants.dart'; |
| 9 | +import 'package:stackwallet/utilities/enums/coin_enum.dart'; |
| 10 | +import 'package:stackwallet/utilities/text_styles.dart'; |
| 11 | +import 'package:stackwallet/widgets/animated_text.dart'; |
| 12 | + |
| 13 | +class FiroBalanceSelectionSheet extends ConsumerStatefulWidget { |
| 14 | + const FiroBalanceSelectionSheet({ |
| 15 | + Key? key, |
| 16 | + required this.walletId, |
| 17 | + }) : super(key: key); |
| 18 | + |
| 19 | + final String walletId; |
| 20 | + |
| 21 | + @override |
| 22 | + ConsumerState<FiroBalanceSelectionSheet> createState() => |
| 23 | + _FiroBalanceSelectionSheetState(); |
| 24 | +} |
| 25 | + |
| 26 | +class _FiroBalanceSelectionSheetState |
| 27 | + extends ConsumerState<FiroBalanceSelectionSheet> { |
| 28 | + late final String walletId; |
| 29 | + |
| 30 | + final stringsToLoopThrough = [ |
| 31 | + "Loading balance", |
| 32 | + "Loading balance.", |
| 33 | + "Loading balance..", |
| 34 | + "Loading balance...", |
| 35 | + ]; |
| 36 | + |
| 37 | + @override |
| 38 | + void initState() { |
| 39 | + walletId = widget.walletId; |
| 40 | + super.initState(); |
| 41 | + } |
| 42 | + |
| 43 | + @override |
| 44 | + Widget build(BuildContext context) { |
| 45 | + debugPrint("BUILD: $runtimeType"); |
| 46 | + |
| 47 | + final manager = ref.watch(walletsChangeNotifierProvider |
| 48 | + .select((value) => value.getManager(walletId))); |
| 49 | + final firoWallet = manager.wallet as FiroWallet; |
| 50 | + |
| 51 | + return Container( |
| 52 | + decoration: const BoxDecoration( |
| 53 | + color: CFColors.white, |
| 54 | + borderRadius: BorderRadius.vertical( |
| 55 | + top: Radius.circular(20), |
| 56 | + ), |
| 57 | + ), |
| 58 | + child: Padding( |
| 59 | + padding: const EdgeInsets.only( |
| 60 | + left: 24, |
| 61 | + right: 24, |
| 62 | + top: 10, |
| 63 | + bottom: 0, |
| 64 | + ), |
| 65 | + child: Column( |
| 66 | + mainAxisSize: MainAxisSize.min, |
| 67 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 68 | + children: [ |
| 69 | + Center( |
| 70 | + child: Container( |
| 71 | + decoration: BoxDecoration( |
| 72 | + color: CFColors.fieldGray, |
| 73 | + borderRadius: BorderRadius.circular( |
| 74 | + Constants.size.circularBorderRadius, |
| 75 | + ), |
| 76 | + ), |
| 77 | + width: 60, |
| 78 | + height: 4, |
| 79 | + ), |
| 80 | + ), |
| 81 | + const SizedBox( |
| 82 | + height: 36, |
| 83 | + ), |
| 84 | + Column( |
| 85 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 86 | + children: [ |
| 87 | + Text( |
| 88 | + "Select balance", |
| 89 | + style: STextStyles.pageTitleH2, |
| 90 | + textAlign: TextAlign.left, |
| 91 | + ), |
| 92 | + const SizedBox( |
| 93 | + height: 16, |
| 94 | + ), |
| 95 | + GestureDetector( |
| 96 | + onTap: () { |
| 97 | + final state = |
| 98 | + ref.read(publicPrivateBalanceStateProvider.state).state; |
| 99 | + if (state != "Private") { |
| 100 | + ref.read(publicPrivateBalanceStateProvider.state).state = |
| 101 | + "Private"; |
| 102 | + } |
| 103 | + Navigator.of(context).pop(); |
| 104 | + }, |
| 105 | + child: Container( |
| 106 | + color: Colors.transparent, |
| 107 | + child: Row( |
| 108 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 109 | + children: [ |
| 110 | + Column( |
| 111 | + mainAxisAlignment: MainAxisAlignment.start, |
| 112 | + children: [ |
| 113 | + SizedBox( |
| 114 | + width: 20, |
| 115 | + height: 20, |
| 116 | + child: Radio( |
| 117 | + activeColor: CFColors.link2, |
| 118 | + value: "Private", |
| 119 | + groupValue: ref |
| 120 | + .watch( |
| 121 | + publicPrivateBalanceStateProvider.state) |
| 122 | + .state, |
| 123 | + onChanged: (x) { |
| 124 | + ref |
| 125 | + .read(publicPrivateBalanceStateProvider |
| 126 | + .state) |
| 127 | + .state = "Private"; |
| 128 | + |
| 129 | + Navigator.of(context).pop(); |
| 130 | + }, |
| 131 | + ), |
| 132 | + ), |
| 133 | + ], |
| 134 | + ), |
| 135 | + const SizedBox( |
| 136 | + width: 12, |
| 137 | + ), |
| 138 | + Flexible( |
| 139 | + child: Column( |
| 140 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 141 | + children: [ |
| 142 | + // Row( |
| 143 | + // children: [ |
| 144 | + Text( |
| 145 | + "Private balance", |
| 146 | + style: STextStyles.titleBold12.copyWith( |
| 147 | + color: const Color(0xFF44464E), |
| 148 | + ), |
| 149 | + textAlign: TextAlign.left, |
| 150 | + ), |
| 151 | + const SizedBox( |
| 152 | + width: 2, |
| 153 | + ), |
| 154 | + FutureBuilder( |
| 155 | + future: firoWallet.availablePrivateBalance(), |
| 156 | + builder: |
| 157 | + (context, AsyncSnapshot<Decimal> snapshot) { |
| 158 | + if (snapshot.connectionState == |
| 159 | + ConnectionState.done && |
| 160 | + snapshot.hasData) { |
| 161 | + return Text( |
| 162 | + "${snapshot.data!} ${manager.coin.ticker}", |
| 163 | + style: STextStyles.itemSubtitle, |
| 164 | + textAlign: TextAlign.left, |
| 165 | + ); |
| 166 | + } else { |
| 167 | + return AnimatedText( |
| 168 | + stringsToLoopThrough: |
| 169 | + stringsToLoopThrough, |
| 170 | + style: STextStyles.itemSubtitle, |
| 171 | + ); |
| 172 | + } |
| 173 | + }, |
| 174 | + ) |
| 175 | + ], |
| 176 | + ), |
| 177 | + // ], |
| 178 | + // ), |
| 179 | + ) |
| 180 | + ], |
| 181 | + ), |
| 182 | + ), |
| 183 | + ), |
| 184 | + const SizedBox( |
| 185 | + height: 16, |
| 186 | + ), |
| 187 | + GestureDetector( |
| 188 | + onTap: () { |
| 189 | + final state = |
| 190 | + ref.read(publicPrivateBalanceStateProvider.state).state; |
| 191 | + if (state != "Public") { |
| 192 | + ref.read(publicPrivateBalanceStateProvider.state).state = |
| 193 | + "Public"; |
| 194 | + } |
| 195 | + Navigator.of(context).pop(); |
| 196 | + }, |
| 197 | + child: Container( |
| 198 | + color: Colors.transparent, |
| 199 | + child: Row( |
| 200 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 201 | + children: [ |
| 202 | + Column( |
| 203 | + children: [ |
| 204 | + SizedBox( |
| 205 | + width: 20, |
| 206 | + height: 20, |
| 207 | + child: Radio( |
| 208 | + activeColor: CFColors.link2, |
| 209 | + value: "Public", |
| 210 | + groupValue: ref |
| 211 | + .watch( |
| 212 | + publicPrivateBalanceStateProvider.state) |
| 213 | + .state, |
| 214 | + onChanged: (x) { |
| 215 | + ref |
| 216 | + .read(publicPrivateBalanceStateProvider |
| 217 | + .state) |
| 218 | + .state = "Public"; |
| 219 | + Navigator.of(context).pop(); |
| 220 | + }, |
| 221 | + ), |
| 222 | + ), |
| 223 | + ], |
| 224 | + ), |
| 225 | + const SizedBox( |
| 226 | + width: 12, |
| 227 | + ), |
| 228 | + Flexible( |
| 229 | + child: Column( |
| 230 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 231 | + children: [ |
| 232 | + // Row( |
| 233 | + // children: [ |
| 234 | + Text( |
| 235 | + "Public balance", |
| 236 | + style: STextStyles.titleBold12.copyWith( |
| 237 | + color: const Color(0xFF44464E), |
| 238 | + ), |
| 239 | + textAlign: TextAlign.left, |
| 240 | + ), |
| 241 | + const SizedBox( |
| 242 | + width: 2, |
| 243 | + ), |
| 244 | + FutureBuilder( |
| 245 | + future: firoWallet.availablePublicBalance(), |
| 246 | + builder: |
| 247 | + (context, AsyncSnapshot<Decimal> snapshot) { |
| 248 | + if (snapshot.connectionState == |
| 249 | + ConnectionState.done && |
| 250 | + snapshot.hasData) { |
| 251 | + return Text( |
| 252 | + "${snapshot.data!} ${manager.coin.ticker}", |
| 253 | + style: STextStyles.itemSubtitle, |
| 254 | + textAlign: TextAlign.left, |
| 255 | + ); |
| 256 | + } else { |
| 257 | + return AnimatedText( |
| 258 | + stringsToLoopThrough: |
| 259 | + stringsToLoopThrough, |
| 260 | + style: STextStyles.itemSubtitle, |
| 261 | + ); |
| 262 | + } |
| 263 | + }, |
| 264 | + ) |
| 265 | + // ], |
| 266 | + // ), |
| 267 | + ], |
| 268 | + ), |
| 269 | + ), |
| 270 | + ], |
| 271 | + ), |
| 272 | + ), |
| 273 | + ), |
| 274 | + const SizedBox( |
| 275 | + height: 16, |
| 276 | + ), |
| 277 | + const SizedBox( |
| 278 | + height: 24, |
| 279 | + ), |
| 280 | + ], |
| 281 | + ), |
| 282 | + ], |
| 283 | + ), |
| 284 | + ), |
| 285 | + ); |
| 286 | + } |
| 287 | +} |
0 commit comments