|
| 1 | +import 'package:flutter/cupertino.dart'; |
| 2 | +import 'package:flutter/material.dart'; |
| 3 | +import 'package:flutter_mobx/flutter_mobx.dart'; |
| 4 | +import 'package:polkawallet_plugin_statemine/pages/transferPage.dart'; |
| 5 | +import 'package:polkawallet_plugin_statemine/polkawallet_plugin_statemine.dart'; |
| 6 | +import 'package:polkawallet_plugin_statemine/utils/i18n/index.dart'; |
| 7 | +import 'package:polkawallet_sdk/plugin/store/balances.dart'; |
| 8 | +import 'package:polkawallet_sdk/storage/keyring.dart'; |
| 9 | +import 'package:polkawallet_sdk/utils/i18n.dart'; |
| 10 | +import 'package:polkawallet_ui/components/roundedButton.dart'; |
| 11 | +import 'package:polkawallet_ui/pages/accountQrCodePage.dart'; |
| 12 | +import 'package:polkawallet_ui/utils/format.dart'; |
| 13 | + |
| 14 | +class AssetBalancePage extends StatefulWidget { |
| 15 | + AssetBalancePage(this.plugin, this.keyring); |
| 16 | + final PluginStatemine plugin; |
| 17 | + final Keyring keyring; |
| 18 | + |
| 19 | + static final String route = '/asset/balance/detail'; |
| 20 | + |
| 21 | + @override |
| 22 | + _AssetBalancePageSate createState() => _AssetBalancePageSate(); |
| 23 | +} |
| 24 | + |
| 25 | +class _AssetBalancePageSate extends State<AssetBalancePage> { |
| 26 | + final GlobalKey<RefreshIndicatorState> _refreshKey = |
| 27 | + new GlobalKey<RefreshIndicatorState>(); |
| 28 | + |
| 29 | + final colorIn = Color(0xFF62CFE4); |
| 30 | + final colorOut = Color(0xFF3394FF); |
| 31 | + |
| 32 | + Future<void> _updateData() async { |
| 33 | + widget.plugin.updateBalances(widget.keyring.current); |
| 34 | + } |
| 35 | + |
| 36 | + @override |
| 37 | + void initState() { |
| 38 | + super.initState(); |
| 39 | + |
| 40 | + WidgetsBinding.instance.addPostFrameCallback((_) { |
| 41 | + _updateData(); |
| 42 | + |
| 43 | + final TokenBalanceData asset = ModalRoute.of(context).settings.arguments; |
| 44 | + if (widget.plugin.store.assets.assetsDetails[asset.id] == null) { |
| 45 | + widget.plugin.service.assets.getAssetsDetail(asset.id); |
| 46 | + } |
| 47 | + }); |
| 48 | + } |
| 49 | + |
| 50 | + @override |
| 51 | + Widget build(BuildContext context) { |
| 52 | + final dic = I18n.of(context).getDic(i18n_full_dic_statemine, 'common'); |
| 53 | + |
| 54 | + final TokenBalanceData token = ModalRoute.of(context).settings.arguments; |
| 55 | + |
| 56 | + final primaryColor = Theme.of(context).primaryColor; |
| 57 | + final titleColor = Theme.of(context).cardColor; |
| 58 | + |
| 59 | + return Scaffold( |
| 60 | + appBar: AppBar( |
| 61 | + title: Text(token.symbol), |
| 62 | + centerTitle: true, |
| 63 | + elevation: 0.0, |
| 64 | + ), |
| 65 | + body: SafeArea( |
| 66 | + child: Observer( |
| 67 | + builder: (_) { |
| 68 | + final balance = |
| 69 | + widget.plugin.store.assets.tokenBalanceMap[token.id]; |
| 70 | + final free = Fmt.balanceInt(balance?.amount ?? '0'); |
| 71 | + return RefreshIndicator( |
| 72 | + key: _refreshKey, |
| 73 | + onRefresh: _updateData, |
| 74 | + child: Column( |
| 75 | + children: <Widget>[ |
| 76 | + Stack( |
| 77 | + alignment: AlignmentDirectional.bottomCenter, |
| 78 | + children: [ |
| 79 | + Container( |
| 80 | + width: MediaQuery.of(context).size.width, |
| 81 | + alignment: Alignment.center, |
| 82 | + color: primaryColor, |
| 83 | + padding: EdgeInsets.only(bottom: 24), |
| 84 | + margin: EdgeInsets.only(bottom: 24), |
| 85 | + child: Padding( |
| 86 | + padding: EdgeInsets.only(top: 16, bottom: 40), |
| 87 | + child: Column( |
| 88 | + children: [ |
| 89 | + Container( |
| 90 | + margin: EdgeInsets.only(bottom: 24), |
| 91 | + child: Text( |
| 92 | + Fmt.token(free, token.decimals, length: 8), |
| 93 | + style: TextStyle( |
| 94 | + color: titleColor, |
| 95 | + fontSize: 28, |
| 96 | + fontWeight: FontWeight.bold, |
| 97 | + ), |
| 98 | + ), |
| 99 | + ), |
| 100 | + ], |
| 101 | + ), |
| 102 | + ), |
| 103 | + ), |
| 104 | + Container( |
| 105 | + height: 48, |
| 106 | + width: MediaQuery.of(context).size.width, |
| 107 | + decoration: BoxDecoration( |
| 108 | + color: titleColor, |
| 109 | + borderRadius: |
| 110 | + const BorderRadius.all(const Radius.circular(16)), |
| 111 | + ), |
| 112 | + ), |
| 113 | + ], |
| 114 | + ), |
| 115 | + Container( |
| 116 | + color: titleColor, |
| 117 | + child: Row( |
| 118 | + children: <Widget>[ |
| 119 | + Expanded( |
| 120 | + child: Container( |
| 121 | + padding: EdgeInsets.fromLTRB(16, 8, 8, 8), |
| 122 | + child: RoundedButton( |
| 123 | + icon: Icon(Icons.qr_code, |
| 124 | + color: titleColor, size: 24), |
| 125 | + text: dic['receive'], |
| 126 | + color: colorIn, |
| 127 | + onPressed: () { |
| 128 | + Navigator.pushNamed( |
| 129 | + context, AccountQrCodePage.route); |
| 130 | + }, |
| 131 | + ), |
| 132 | + ), |
| 133 | + ), |
| 134 | + Expanded( |
| 135 | + child: Container( |
| 136 | + padding: EdgeInsets.fromLTRB(8, 8, 16, 8), |
| 137 | + child: RoundedButton( |
| 138 | + icon: SizedBox( |
| 139 | + height: 20, |
| 140 | + child: Image.asset( |
| 141 | + 'packages/polkawallet_plugin_acala/assets/images/assets_send.png'), |
| 142 | + ), |
| 143 | + text: dic['transfer'], |
| 144 | + color: colorOut, |
| 145 | + onPressed: () async { |
| 146 | + final res = await Navigator.pushNamed( |
| 147 | + context, |
| 148 | + TransferPage.route, |
| 149 | + arguments: token, |
| 150 | + ); |
| 151 | + if (res != null) { |
| 152 | + _refreshKey.currentState.show(); |
| 153 | + } |
| 154 | + }, |
| 155 | + ), |
| 156 | + ), |
| 157 | + ), |
| 158 | + ], |
| 159 | + ), |
| 160 | + ), |
| 161 | + ], |
| 162 | + ), |
| 163 | + ); |
| 164 | + }, |
| 165 | + ), |
| 166 | + ), |
| 167 | + ); |
| 168 | + } |
| 169 | +} |
0 commit comments