YSWallet.dart 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014
  1. import 'dart:async';
  2. import 'dart:ui';
  3. import 'package:flutter/cupertino.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:flutter_wallet/tools/YSAlertView.dart';
  6. import 'package:flutter_wallet/tools/YSColors.dart';
  7. import 'package:flutter_wallet/tools/YSSqflite.dart';
  8. import 'package:flutter_wallet/tools/YSTools.dart';
  9. import 'package:flutter_wallet/wallet/YSMessage.dart';
  10. import 'package:flutter_wallet/wallet/YSWalletCollection.dart';
  11. import 'package:flutter_wallet/wallet/YSWalletManager.dart';
  12. import 'package:flutter_wallet/wallet/YSWalletTokenChoose.dart';
  13. import 'package:flutter_wallet/wallet/YSWalletTransfer.dart';
  14. import 'package:flutter_wallet/wallet/view/YSWalletListItemView.dart';
  15. import 'package:provider/provider.dart';
  16. import 'package:skeletons/skeletons.dart';
  17. import '../base/YSTabBar.dart';
  18. import '../generated/l10n.dart';
  19. import '../login/YSWalletSetting.dart';
  20. import '../login/view/YSHelpView.dart';
  21. import '../tools/YSBip.dart';
  22. import '../tools/YSNetWork.dart';
  23. import 'YSWalletDetail.dart';
  24. class YSWallet extends StatefulWidget {
  25. const YSWallet({Key? key}) : super(key: key);
  26. @override
  27. YSWalletState createState() => YSWalletState();
  28. }
  29. class YSWalletState extends State<YSWallet> with SingleTickerProviderStateMixin,AutomaticKeepAliveClientMixin{
  30. final List _titles = [
  31. {'title':'资产','type':0},
  32. {'title':'藏品','type':1},
  33. ];
  34. bool _isShow = true;
  35. late TabController _tabController;
  36. // int _refeshIndex = 0;
  37. Map _wallet = {};
  38. Timer? _timer;
  39. @override
  40. void initState() {
  41. _tabController = TabController(
  42. vsync: this,
  43. length: _titles.length,
  44. );
  45. _getWalletData();
  46. _startTime();
  47. checkAddress();
  48. super.initState();
  49. }
  50. _startTime() {
  51. // _timer = Timer.periodic(const Duration(seconds: 1), (timer) async{
  52. // _refreshData();
  53. // });
  54. }
  55. _getPriceData() {
  56. YSNetWork.ysRequestHttp(context, type: RequestType.get, api: 'tokens', parameter: {'chain_id':YSData().typeId,'page':1,'count':100}, successSetter: (dict) async{
  57. YSData().allTokenArray = dict['data']['list']??[];
  58. addToken(context);
  59. getMindToken(context);
  60. });
  61. }
  62. _getSymbolData() {
  63. List array = YSData().typeArray.where((element) => element['id']==YSData().typeId).toList();
  64. if(array.isNotEmpty){
  65. Map map = array.first;
  66. YSNetWork.ysRequestHttp(context, type: RequestType.get, api: 'prices', parameter: {'symbol':map['token_name'],'page':1,'count':5}, successSetter: (dict) async{
  67. YSData().priceArray = dict['data']['list']??[];
  68. });
  69. }
  70. }
  71. _refreshData() async{
  72. List array = YSData().typeArray.where((element) => element['id']==YSData().typeId).toList();
  73. if(array.isNotEmpty){
  74. Map map = array.first;
  75. YSNetWork.ysRequestHttp(context, type: RequestType.get, api: 'prices', parameter: {'symbol':map['token_name'],'page':1,'count':5}, successSetter: (dict) async{
  76. YSData().priceArray = dict['data']['list']??[];
  77. YSNetWork.ysRequestHttp(context, type: RequestType.get, api: 'tokens', parameter: {'chain_id':YSData().typeId,'page':1,'count':100}, successSetter: (dict) async{
  78. YSData().allTokenArray = dict['data']['list']??[];
  79. _getTokenArray();
  80. });
  81. });
  82. }
  83. }
  84. _getWalletData() async{
  85. YSSqflite sqflite = YSSqflite().init();
  86. List walletArray = await sqflite.rawQuery();
  87. if(!mounted)return;
  88. YSSqflite.notifier(context, walletArray);
  89. if(walletArray.isNotEmpty){
  90. YSData().wallet = walletArray.first;
  91. _getPriceData();
  92. }
  93. }
  94. @override
  95. void dispose() {
  96. if(_timer!=null){
  97. _timer?.cancel();
  98. }
  99. super.dispose();
  100. }
  101. @override
  102. Widget build(BuildContext context) {
  103. super.build(context);
  104. List _menuArray = [
  105. {'title':S.current.ZHUANZHANG,'type':1},
  106. {'title':S.current.SHOUKUAN,'type':2},
  107. {'title':S.current.SHANDUI,'type':3}
  108. ];
  109. YSData().context = context;
  110. return Scaffold(
  111. body: SingleChildScrollView(
  112. child: Consumer2(
  113. builder: (context,YSWalletNotifier value,YSTokenNotifier value2,child) {
  114. _getSymbolData();
  115. if(value.walletArray.isNotEmpty){
  116. _wallet = value.walletArray.firstWhere((element) => element['chooseType']==1,orElse: ()=>{});
  117. if(_wallet.isEmpty)_wallet = value.walletArray.first;
  118. }else{
  119. _wallet.clear();
  120. }
  121. YSData().wallet = _wallet;
  122. YSData().tokenArray = value2.value;
  123. // _getTokenArray();
  124. return Skeleton(
  125. isLoading: YSData().isLoad==false,
  126. skeleton: Stack(
  127. children: [
  128. Column(
  129. children: [
  130. SkeletonAvatar(
  131. style: SkeletonAvatarStyle(
  132. width: double.infinity,
  133. height: hsp(250)
  134. ),
  135. ),
  136. SizedBox(
  137. height: hsp(50),
  138. child: Row(
  139. children: [
  140. Expanded(child: Center(
  141. child: SkeletonLine(
  142. style: SkeletonLineStyle(
  143. height: 15,
  144. width: 50,
  145. borderRadius: BorderRadius.circular(8),
  146. alignment: AlignmentDirectional.center
  147. ),
  148. ),
  149. )),
  150. Expanded(child: Center(
  151. child: SkeletonLine(
  152. style: SkeletonLineStyle(
  153. height: 15,
  154. width: 50,
  155. borderRadius: BorderRadius.circular(8),
  156. alignment: AlignmentDirectional.center
  157. ),
  158. ),
  159. )),
  160. ],
  161. ),
  162. ),
  163. Container(
  164. width: ysWidth(context),
  165. padding: EdgeInsets.only(left: hsp(15)),
  166. child: ListView.separated(
  167. itemBuilder: (context,index){
  168. return Row(
  169. crossAxisAlignment: CrossAxisAlignment.start,
  170. children: [
  171. const SkeletonAvatar(
  172. style: SkeletonAvatarStyle(
  173. shape: BoxShape.circle, width: 50, height: 50),
  174. ),
  175. const SizedBox(width: 8),
  176. Expanded(
  177. child: SkeletonParagraph(
  178. style: SkeletonParagraphStyle(
  179. lines: 2,
  180. spacing: 10,
  181. lineStyle: SkeletonLineStyle(
  182. randomLength: true,
  183. height: 10,
  184. borderRadius: BorderRadius.circular(8),
  185. minLength: MediaQuery.of(context).size.width / 6,
  186. maxLength: MediaQuery.of(context).size.width / 3,
  187. )
  188. ),
  189. ),
  190. ),
  191. Expanded(
  192. child: SkeletonParagraph(
  193. style: SkeletonParagraphStyle(
  194. lines: 1,
  195. lineStyle: SkeletonLineStyle(
  196. alignment: AlignmentDirectional.centerEnd,
  197. randomLength: true,
  198. height: 10,
  199. borderRadius: BorderRadius.circular(8),
  200. minLength: MediaQuery.of(context).size.width / 6,
  201. maxLength: MediaQuery.of(context).size.width / 3,
  202. )
  203. ),
  204. ),
  205. )
  206. ],
  207. );
  208. },
  209. separatorBuilder: (context,index){
  210. return Container(height: hsp(20),);
  211. },
  212. itemCount: 3,
  213. shrinkWrap: true,
  214. padding: const EdgeInsets.all(0),
  215. physics: const NeverScrollableScrollPhysics(),
  216. ),
  217. ),
  218. ],
  219. )
  220. ],
  221. ),
  222. child: LayoutBuilder(
  223. builder: (context,conSize) {
  224. return Stack(
  225. children: [
  226. const YSHeadView(),
  227. Padding(
  228. padding: EdgeInsets.only(top: ysTOP(context)+hsp(10)),
  229. child: Column(
  230. children: [
  231. Container(
  232. height: hsp(50),
  233. padding: EdgeInsets.only(left: hsp(10),right: hsp(10)),
  234. child: Row(
  235. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  236. children: [
  237. GestureDetector(
  238. onTap: () async{
  239. // ysShowCenterAlertView(context, YSLoadView2(funAction: () async{
  240. // return await YSBipManager.setMnemonic('habit benefit gallery egg movie moon crumble topple side found aim cement');
  241. // },valueSetter: (isDone) async{
  242. // if(isDone&&mounted){
  243. // if(YSData().isManager){
  244. // List array = await YSSqflite().rawQuery();
  245. // if(!mounted)return;
  246. // YSSqflite.notifier(context, array);
  247. // Navigator.popUntil(context, ModalRoute.withName("YSWalletManager"));
  248. // }else{
  249. // Navigator.of(context).pushAndRemoveUntil(CupertinoPageRoute(builder: (context){
  250. // return const YSTabBar();
  251. // }), (route) => false);
  252. // }
  253. // }
  254. // },));
  255. // return;
  256. // YSFileWriteRead().readContent();
  257. // YSFileWriteRead().writeContent('content');
  258. // return;
  259. Navigator.of(context).push(
  260. CupertinoPageRoute(builder: (context){
  261. return const YSMessage();
  262. })
  263. );
  264. // Navigator.of(context).push(
  265. // CupertinoPageRoute(builder: (context){
  266. // return const YSWalletSetting();
  267. // })
  268. // );
  269. },
  270. child: Stack(
  271. children: [
  272. Image.asset(YSColors.imageStyle(context, '编组 4'),height: hsp(30),width: hsp(20),),
  273. // Container(
  274. // height: hsp(5),
  275. // width: hsp(5),
  276. // decoration: const BoxDecoration(
  277. // color: Colors.red,
  278. // borderRadius: BorderRadius.all(Radius.circular(50))
  279. // ),
  280. // margin: EdgeInsets.only(left: hsp(15),top: hsp(5)),
  281. // )
  282. ],
  283. )
  284. ),
  285. const YSChangeNetView(),
  286. const YSScanView(size: 20,)
  287. ],
  288. ),
  289. ),
  290. if(_wallet.isNotEmpty)Padding(
  291. padding: EdgeInsets.only(top: hsp(20),bottom: hsp(10),left: hsp(15),right: hsp(15)),
  292. child: ClipRRect(
  293. borderRadius: const BorderRadius.all(Radius.circular(10)),
  294. child: GestureDetector(
  295. onTap: (){
  296. if(_wallet.isEmpty)return;
  297. Navigator.of(context).push(
  298. CupertinoPageRoute(builder: (context){
  299. return YSWalletDetail(wallet: _wallet,);
  300. },)
  301. );
  302. },
  303. behavior: HitTestBehavior.opaque,
  304. child: SizedBox(
  305. height: hsp(160),
  306. width: ysWidth(context),
  307. child: Column(
  308. crossAxisAlignment: CrossAxisAlignment.start,
  309. children: [
  310. GestureDetector(
  311. onTap: (){
  312. Navigator.of(context).push(
  313. CupertinoPageRoute(builder: (context){
  314. return const YSWalletManager();
  315. },settings: const RouteSettings(name: 'YSWalletManager'),)
  316. ).then((value) {
  317. // _refeshIndex++;
  318. // _getTokenArray();
  319. // getMindToken(context);
  320. });
  321. },
  322. behavior: HitTestBehavior.opaque,
  323. child: SizedBox(
  324. height: hsp(20),
  325. child: RichText(text: TextSpan(
  326. style: YSColors.subStyle(context),
  327. children: [
  328. TextSpan(text: '${_wallet['name']??''} '),
  329. WidgetSpan(child: Image.asset(YSColors.imageStyle(context, '路径'),height: hsp(5),width: hsp(5),),alignment: PlaceholderAlignment.middle),
  330. WidgetSpan(child: YSTagView(wallet: YSData().wallet,key: Key(YSData().wallet['public']),))
  331. ]
  332. )),
  333. ),
  334. ),
  335. SizedBox(
  336. height: hsp(40),
  337. child: Row(
  338. mainAxisSize: MainAxisSize.min,
  339. children: [
  340. // Image.asset(YSColors.imageStyle(context, '编组 11'),height: hsp(25),width: hsp(25),),
  341. Text(YSUserRecord().unit=='RMB'?'¥':'\$',style: TextStyle(fontSize: zsp(25),color: Colors.white),),
  342. if(_wallet.isNotEmpty)Padding(
  343. padding: EdgeInsets.only(left: hsp(5),right: hsp(10)),
  344. child: Container(
  345. constraints: BoxConstraints(
  346. maxWidth: ysWidth(context)/2
  347. ),
  348. child: _isShow==false?Container(
  349. padding: EdgeInsets.only(top: hsp(10)),
  350. child: Text(
  351. '*****',
  352. style: TextStyle(fontSize: zsp(25),color: (YSColors.content2Style(context)).color),
  353. ),
  354. ):YSBalanceTotalData(style: TextStyle(fontSize: zsp(25),color: (YSColors.content2Style(context)).color),
  355. key: Key('${YSData().typeId}${_wallet['id']}${YSData().chooseIndex}'),),
  356. )
  357. ),
  358. GestureDetector(
  359. onTap: (){
  360. _isShow = !_isShow;
  361. setState(() {});
  362. },
  363. behavior: HitTestBehavior.opaque,
  364. child: Container(
  365. height: hsp(20),
  366. alignment: Alignment.topCenter,
  367. child: Image.asset(YSColors.imageStyle(context, _isShow?'眼睛备份':'yanjing_yincang'),height: hsp(15),width: hsp(15),color: (YSColors.content2Style(context)).color,),
  368. )
  369. ),
  370. ],
  371. )
  372. ),
  373. SizedBox(
  374. height: hsp(100),
  375. width: ysWidth(context),
  376. child: false?Row(//'${_wallet['private']}'.isEmpty
  377. children: [
  378. GestureDetector(
  379. onTap: (){
  380. Navigator.of(context).push(
  381. CupertinoPageRoute(builder: (context){
  382. return YSWalletCollection(wallet: _wallet,);
  383. })
  384. );
  385. },
  386. child: Container(
  387. // width: (conSize.maxWidth-hsp(30))/_menuArray.length,
  388. width: hsp(100),
  389. alignment: Alignment.center,
  390. child: Column(
  391. mainAxisSize: MainAxisSize.min,
  392. children: [
  393. Image.asset(YSColors.imageStyle(context, '收款_1'),height: hsp(50),width: hsp(50),),
  394. Container(
  395. constraints: BoxConstraints(maxWidth: (conSize.maxWidth/_menuArray.length)-hsp(30)),
  396. child: Text(' ${S.current.SHOUKUAN}',style: YSColors.content3Style(context),maxLines: 1,)
  397. )
  398. ],
  399. ),
  400. ),
  401. ),
  402. ],
  403. ):ListView.builder(
  404. itemBuilder: (context,index){
  405. Map item = _menuArray[index];
  406. return GestureDetector(
  407. onTap: (){
  408. if(index==2){
  409. CustomerNotification().dispatch(context);
  410. return;
  411. }
  412. // LogUtil.d(_wallet);
  413. // LogUtil.d(YSData().tokenArray);
  414. // return;
  415. if(index==0){
  416. YSData().contAddress = _wallet['public'];
  417. YSData().contName = _wallet['name'];
  418. }
  419. Navigator.of(context).push(
  420. CupertinoPageRoute(builder: (context){
  421. return index==0?const YSWalletTransfer():index==1?YSWalletCollection(wallet: _wallet,):const YSWalletTransfer();
  422. })
  423. );
  424. },
  425. behavior: HitTestBehavior.opaque,
  426. child: Container(
  427. // width: (conSize.maxWidth-hsp(30))/_menuArray.length,
  428. width: hsp(100),
  429. alignment: Alignment.center,
  430. child: Column(
  431. mainAxisSize: MainAxisSize.min,
  432. children: [
  433. Image.asset(YSColors.imageStyle(context, item['type']==1?'转账 (1)':item['type']==2?'收款_1':'交易_闪兑'),height: hsp(50),width: hsp(50),),
  434. Container(
  435. constraints: BoxConstraints(maxWidth: (conSize.maxWidth/_menuArray.length)-hsp(30)),
  436. child: Text(' ${item['title']}',style: YSColors.content3Style(context),maxLines: 1,)
  437. )
  438. ],
  439. ),
  440. ),
  441. );
  442. },
  443. itemCount: _menuArray.length,
  444. padding: const EdgeInsets.all(0),
  445. physics: const NeverScrollableScrollPhysics(),
  446. scrollDirection: Axis.horizontal,
  447. ),
  448. )
  449. ],
  450. ),
  451. ),
  452. ),
  453. ),
  454. ),
  455. if(_wallet.isNotEmpty)DefaultTabController(
  456. length: _titles.length,
  457. child: ClipRRect(
  458. borderRadius: const BorderRadius.only(topRight: Radius.circular(10),topLeft: Radius.circular(10)),
  459. child: Container(
  460. height: ysHeight(context)-ysTOP(context)-ystabBarHeight-hsp(250),
  461. width: ysWidth(context),
  462. color: YSColors.containColor(context),
  463. child: Column(
  464. children: [
  465. Container(
  466. margin: EdgeInsets.only(left: hsp(15),right: hsp(15)),
  467. height: hsp(50),
  468. child: Row(
  469. children: [
  470. SizedBox(
  471. width: ysWidth(context)-hsp(90),
  472. child: Stack(
  473. children: [
  474. Container(
  475. height: hsp(46),
  476. decoration: BoxDecoration(
  477. border: Border(bottom: BorderSide(color: YSColors.lineColor(context),width: hsp(1))),
  478. ),
  479. ),
  480. TabBar(
  481. controller: _tabController,
  482. indicatorColor: YSColors.selectedColor(context),
  483. indicatorWeight: hsp(1),
  484. tabs: _titles.map((f) {//text: '· ${f['title']}'
  485. return Tab(
  486. child: Text(f['title']=='资产'?S.current.ZICHAN:f['title'],style: YSColors.contentStyle(context),),
  487. );
  488. }).toList(),
  489. ),
  490. ],
  491. ),
  492. ),
  493. Container(
  494. width: hsp(60),
  495. height: hsp(46),
  496. decoration: BoxDecoration(
  497. border: Border(bottom: BorderSide(color: YSColors.lineColor(context),width: hsp(1))),
  498. ),
  499. alignment: Alignment.center,
  500. child: Row(
  501. mainAxisSize: MainAxisSize.min,
  502. children: [
  503. Padding(
  504. padding: EdgeInsets.only(left: hsp(15),right: hsp(15)),
  505. child: Image.asset(YSColors.imageStyle(context, '编组 10'),height: hsp(15),width: hsp(15),),
  506. ),
  507. GestureDetector(
  508. onTap: (){
  509. Navigator.of(context).push(
  510. CupertinoPageRoute(builder: (context){
  511. return const YSWalletTokenChoose();
  512. })
  513. );
  514. },
  515. child: Image.asset(YSColors.imageStyle(context, '添加'),height: hsp(15),width: hsp(15),),
  516. )
  517. ],
  518. ),
  519. )
  520. ],
  521. ),
  522. ),
  523. Container(
  524. color: YSColors.containColor(context),
  525. height: ysHeight(context)-ysTOP(context)-ystabBarHeight-hsp(300),
  526. child: TabBarView(
  527. controller: _tabController,
  528. children: _titles.map((f) {
  529. return f['type']==0?RefreshIndicator(
  530. onRefresh: _getTokenArray,
  531. child: ListView.builder(
  532. itemBuilder: (context, index) {
  533. Map item = YSData().tokenArray [index];
  534. return YSData().allTokenArray.isEmpty?Container():YSWalletListItemView(
  535. item: item,
  536. key: Key('${YSData().typeId}${YSData().wallet['id']}${item['name']}${YSData().dataRefresh}'),
  537. );
  538. },
  539. itemCount: YSData().tokenArray.length,
  540. padding: const EdgeInsets.all(0),
  541. ),
  542. ):Container();
  543. }).toList(),
  544. ),
  545. )
  546. ],
  547. ),
  548. ),
  549. ),
  550. )
  551. ],
  552. ),
  553. ),
  554. if(_wallet.isEmpty)Container(
  555. margin: EdgeInsets.only(top: ysTOP(context)+hsp(60)),
  556. height: ysHeight(context)-ysTOP(context)-hsp(130),
  557. width: ysWidth(context),
  558. child: GestureDetector(
  559. onTap: (){},
  560. behavior: HitTestBehavior.opaque,
  561. child: ClipRRect(
  562. child: BackdropFilter(
  563. filter: ImageFilter.blur(sigmaX: 5.0,sigmaY: 5.0),
  564. child: Padding(
  565. padding: EdgeInsets.only(top: ysHeight(context)-ysTOP(context)-hsp(430)),
  566. child: const YSChooseWalletType(isHome: true,),
  567. ),
  568. ),
  569. ),
  570. ),
  571. )
  572. ],
  573. );
  574. }
  575. ),
  576. );
  577. }
  578. ),
  579. ),
  580. );
  581. }
  582. Future<void> _getTokenArray() async{
  583. // YSSqflite2 sqflite2 = YSSqflite2().init();
  584. // List array = await sqflite2.rawQuery();
  585. // if(!mounted)return;
  586. YSData().dataRefresh++;
  587. // YSSqflite2.notifier(context, array);
  588. addToken(context);
  589. }
  590. @override
  591. bool get wantKeepAlive => false;
  592. }
  593. class YSWalletOld extends StatefulWidget {
  594. const YSWalletOld({Key? key}) : super(key: key);
  595. @override
  596. YSWalletOldState createState() => YSWalletOldState();
  597. }
  598. class YSWalletOldState extends State<YSWalletOld> with SingleTickerProviderStateMixin,AutomaticKeepAliveClientMixin{
  599. final List _titles = [
  600. {'title':'资产','type':0},
  601. {'title':'DeFi','type':1},
  602. {'title':'NFT','type':2},
  603. ];
  604. bool _isShow = true;
  605. late TabController _tabController;
  606. int _refeshIndex = 0;
  607. Map _wallet = {};
  608. Timer? _timer;
  609. @override
  610. void initState() {
  611. _tabController = TabController(
  612. vsync: this,
  613. length: _titles.length,
  614. );
  615. _getWalletData();
  616. _startTime();
  617. super.initState();
  618. }
  619. _startTime() {
  620. _timer = Timer.periodic(const Duration(seconds: 3), (timer){
  621. _getTokenArray();
  622. });
  623. }
  624. _getPriceData() {
  625. YSNetWork.ysRequestHttp(context, type: RequestType.get, api: 'tokens', parameter: {'chain_id':YSData().typeId,'page':1,'count':100}, successSetter: (dict) async{
  626. YSData().allTokenArray = dict['data']['list']??[];
  627. addToken(context);
  628. getMindToken(context);
  629. });
  630. }
  631. _getWalletData() async{
  632. YSSqflite sqflite = YSSqflite().init();
  633. List walletArray = await sqflite.rawQuery();
  634. if(!mounted)return;
  635. YSSqflite.notifier(context, walletArray);
  636. if(walletArray.isNotEmpty){
  637. YSData().wallet = walletArray.first;
  638. _getPriceData();
  639. }
  640. }
  641. @override
  642. void dispose() {
  643. if(_timer!=null){
  644. _timer?.cancel();
  645. }
  646. super.dispose();
  647. }
  648. @override
  649. Widget build(BuildContext context) {
  650. super.build(context);
  651. List _menuArray = [
  652. {'title':S.current.ZHUANZHANG,'type':1},
  653. {'title':S.current.SHOUKUAN,'type':2},
  654. // {'title':S.current.SHANDUI,'type':3}
  655. ];
  656. return Scaffold(
  657. body: SingleChildScrollView(
  658. child: Consumer2(
  659. builder: (context,YSWalletNotifier value,YSTokenNotifier value2,child) {
  660. if(value.walletArray.isNotEmpty){
  661. _wallet = value.walletArray.firstWhere((element) => element['chooseType']==1,orElse: ()=>{});
  662. if(_wallet.isEmpty)_wallet = value.walletArray.first;
  663. }else{
  664. _wallet.clear();
  665. }
  666. YSData().wallet = _wallet;
  667. YSData().tokenArray = value2.value;
  668. // _refeshIndex++;
  669. return YSData().isLoad==false?Container():LayoutBuilder(
  670. builder: (context,conSize) {
  671. return Stack(
  672. children: [
  673. const YSHeadView(),
  674. Padding(
  675. padding: EdgeInsets.only(top: ysTOP(context)+hsp(10),left: hsp(15),right: hsp(15)),
  676. child: Column(
  677. children: [
  678. SizedBox(
  679. height: hsp(50),
  680. child: Row(
  681. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  682. children: [
  683. GestureDetector(
  684. onTap: () async{
  685. // YSSqflite2 sqflite2 = YSSqflite2().init();
  686. // int count = await sqflite2.delete();
  687. // LogUtil.d(count);
  688. },
  689. child: Image.asset(YSColors.imageStyle(context, '编组 4'),height: hsp(30),width: hsp(20),),
  690. ),
  691. const YSChangeNetView(),
  692. const YSScanView(size: 20,)
  693. ],
  694. ),
  695. ),
  696. Padding(
  697. padding: EdgeInsets.only(top: hsp(20),bottom: hsp(10)),
  698. child: ClipRRect(
  699. borderRadius: const BorderRadius.all(Radius.circular(10)),
  700. child: Container(
  701. height: hsp(160),
  702. color: YSColors.containColor(context),
  703. child: Column(
  704. children: [
  705. GestureDetector(
  706. onTap: (){
  707. if(_wallet.isEmpty)return;
  708. Navigator.of(context).push(
  709. CupertinoPageRoute(builder: (context){
  710. return YSWalletDetail(wallet: _wallet,);
  711. },)
  712. );
  713. },
  714. behavior: HitTestBehavior.opaque,
  715. child: Container(
  716. width: ysWidth(context)-hsp(30),
  717. height: hsp(110),
  718. padding: EdgeInsets.all(hsp(15)),
  719. decoration: BoxDecoration(
  720. // image: DecorationImage(image: AssetImage(YSColors.imageStyle(context, '编组备份')),fit: BoxFit.fill),
  721. borderRadius: const BorderRadius.all(Radius.circular(10)),
  722. color: YSColors.iconColor(context)
  723. ),
  724. child: Stack(
  725. children: [
  726. Positioned(
  727. top: 0,
  728. right: 0,
  729. child: GestureDetector(
  730. onTap: (){
  731. _isShow = !_isShow;
  732. setState(() {});
  733. },
  734. child: Image.asset(YSColors.imageStyle(context, _isShow?'眼睛备份':'yanjing_yincang'),height: hsp(20),width: hsp(20),color: YSColors.containColor(context),),
  735. )
  736. ),
  737. Positioned(
  738. top: hsp(15),
  739. right: hsp(30),
  740. left: hsp(30),
  741. child: SizedBox(
  742. height: hsp(80),
  743. child: Column(
  744. children: [
  745. SizedBox(
  746. height: hsp(40),
  747. child: Row(
  748. mainAxisSize: MainAxisSize.min,
  749. children: [
  750. // Image.asset(YSColors.imageStyle(context, '编组 11'),height: hsp(25),width: hsp(25),),
  751. Text('\$',style: TextStyle(fontSize: zsp(30),color: Colors.white),),
  752. if(_wallet.isNotEmpty)Padding(
  753. padding: EdgeInsets.only(left: hsp(5)),
  754. child: Container(
  755. constraints: BoxConstraints(
  756. maxWidth: ysWidth(context)/2
  757. ),
  758. child: _isShow==false?Container(
  759. padding: EdgeInsets.only(top: hsp(10)),
  760. child: Text(
  761. '*****',
  762. style: TextStyle(fontSize: zsp(25),color: YSColors.containColor(context)),
  763. ),
  764. ):YSBalanceTotalData(style: YSColors.title2Style(context),
  765. key: Key('${YSData().typeId}${_wallet['id']}7'),),
  766. )
  767. )
  768. ],
  769. )
  770. ),
  771. GestureDetector(
  772. onTap: (){
  773. Navigator.of(context).push(
  774. CupertinoPageRoute(builder: (context){
  775. return const YSWalletManager();
  776. },settings: const RouteSettings(name: 'YSWalletManager'),)
  777. ).then((value) {
  778. _refeshIndex++;
  779. _getTokenArray();
  780. getMindToken(context);
  781. });
  782. },
  783. behavior: HitTestBehavior.opaque,
  784. child: SizedBox(
  785. height: hsp(40),
  786. child: RichText(text: TextSpan(
  787. style: YSColors.sub2Style(context),
  788. children: [
  789. TextSpan(text: '${_wallet['name']??''} '),
  790. WidgetSpan(child: Image.asset(YSColors.imageStyle(context, '路径'),height: hsp(5),width: hsp(5),),alignment: PlaceholderAlignment.middle),
  791. ]
  792. )),
  793. ),
  794. )
  795. ],
  796. ),
  797. )
  798. )
  799. ],
  800. ),
  801. ),
  802. ),
  803. SizedBox(
  804. height: hsp(50),
  805. child: ListView.builder(
  806. itemBuilder: (context,index){
  807. Map item = _menuArray[index];
  808. return GestureDetector(
  809. onTap: (){
  810. if(index==2)return;
  811. if(index==0){
  812. YSData().contAddress = _wallet['public'];
  813. YSData().contName = _wallet['name'];
  814. }
  815. Navigator.of(context).push(
  816. CupertinoPageRoute(builder: (context){
  817. return index==0?const YSWalletTransfer():index==1?YSWalletCollection(wallet: _wallet,):const YSWalletTransfer();
  818. })
  819. );
  820. },
  821. behavior: HitTestBehavior.opaque,
  822. child: Container(
  823. width: (conSize.maxWidth-hsp(30))/_menuArray.length,
  824. alignment: Alignment.center,
  825. child: Row(
  826. mainAxisSize: MainAxisSize.min,
  827. children: [
  828. Image.asset(YSColors.imageStyle(context, item['type']==1?'转账 (1)':item['type']==2?'收款_1':'交易_闪兑'),height: hsp(30),width: hsp(30),),
  829. Container(
  830. constraints: BoxConstraints(maxWidth: (conSize.maxWidth/_menuArray.length)-hsp(30)),
  831. child: Text(' ${item['title']}',style: YSColors.contentStyle(context),maxLines: 1,)
  832. )
  833. ],
  834. ),
  835. ),
  836. );
  837. },
  838. itemCount: _menuArray.length,
  839. padding: const EdgeInsets.all(0),
  840. physics: const NeverScrollableScrollPhysics(),
  841. scrollDirection: Axis.horizontal,
  842. ),
  843. )
  844. ],
  845. ),
  846. ),
  847. ),
  848. ),
  849. if(_wallet.isNotEmpty)DefaultTabController(
  850. length: _titles.length,
  851. child: Container(
  852. height: ysHeight(context)-ysTOP(context)-ystabBarHeight-hsp(270),
  853. width: ysWidth(context),
  854. color: YSColors.containColor(context),
  855. child: Column(
  856. children: [
  857. Container(
  858. margin: EdgeInsets.only(left: hsp(15),right: hsp(15)),
  859. height: hsp(50),
  860. child: Row(
  861. children: [
  862. SizedBox(
  863. width: ysWidth(context)-hsp(120),
  864. child: Stack(
  865. children: [
  866. Container(
  867. height: hsp(46),
  868. decoration: BoxDecoration(
  869. border: Border(bottom: BorderSide(color: YSColors.lineColor(context),width: hsp(1))),
  870. ),
  871. ),
  872. TabBar(
  873. controller: _tabController,
  874. indicatorColor: YSColors.selectedColor(context),
  875. isScrollable: true,
  876. indicatorWeight: hsp(1),
  877. tabs: _titles.map((f) {//text: '· ${f['title']}'
  878. return Tab(
  879. child: Text(f['title']=='资产'?S.current.ZICHAN:f['title']=='藏品'?S.current.CANGPIN:f['title'],
  880. style: YSColors.contentStyle(context),),
  881. );
  882. }).toList(),
  883. ),
  884. ],
  885. ),
  886. ),
  887. Container(
  888. width: hsp(60),
  889. height: hsp(46),
  890. decoration: BoxDecoration(
  891. border: Border(bottom: BorderSide(color: YSColors.lineColor(context),width: hsp(1))),
  892. ),
  893. alignment: Alignment.center,
  894. child: Row(
  895. mainAxisSize: MainAxisSize.min,
  896. children: [
  897. Padding(
  898. padding: EdgeInsets.only(left: hsp(15),right: hsp(15)),
  899. child: Image.asset(YSColors.imageStyle(context, '编组 10'),height: hsp(15),width: hsp(15),),
  900. ),
  901. GestureDetector(
  902. onTap: (){
  903. Navigator.of(context).push(
  904. CupertinoPageRoute(builder: (context){
  905. return const YSWalletTokenChoose();
  906. })
  907. );
  908. },
  909. child: Image.asset(YSColors.imageStyle(context, '添加'),height: hsp(15),width: hsp(15),),
  910. )
  911. ],
  912. ),
  913. )
  914. ],
  915. ),
  916. ),
  917. Container(
  918. color: YSColors.containColor(context),
  919. height: ysHeight(context)-ysTOP(context)-ystabBarHeight-hsp(330),
  920. child: TabBarView(
  921. controller: _tabController,
  922. children: _titles.map((f) {
  923. return f['type']==0?RefreshIndicator(
  924. onRefresh: _getTokenArray,
  925. child: ListView.builder(
  926. itemBuilder: (context, index) {
  927. Map item = YSData().tokenArray [index];
  928. return YSData().allTokenArray.isEmpty?Container():YSWalletListItemView(
  929. item: item,
  930. key: Key('${YSData().typeId}${YSData().wallet['id']}${item['name']}$_refeshIndex'),
  931. );
  932. },
  933. itemCount: YSData().tokenArray.length,
  934. padding: const EdgeInsets.all(0),
  935. ),
  936. ):Container();
  937. }).toList(),
  938. ),
  939. )
  940. ],
  941. ),
  942. ),
  943. )
  944. ],
  945. ),
  946. ),
  947. if(_wallet.isEmpty)Container(
  948. margin: EdgeInsets.only(top: ysTOP(context)+hsp(60)),
  949. height: ysHeight(context)-ysTOP(context)-hsp(130),
  950. width: ysWidth(context),
  951. child: GestureDetector(
  952. onTap: (){},
  953. behavior: HitTestBehavior.opaque,
  954. child: ClipRRect(
  955. child: BackdropFilter(
  956. filter: ImageFilter.blur(sigmaX: 5.0,sigmaY: 5.0),
  957. child: Padding(
  958. padding: EdgeInsets.only(top: ysHeight(context)-ysTOP(context)-hsp(430)),
  959. child: const YSChooseWalletType(isHome: true,),
  960. ),
  961. ),
  962. ),
  963. ),
  964. )
  965. ],
  966. );
  967. }
  968. );
  969. }
  970. ),
  971. ),
  972. );
  973. }
  974. Future<void> _getTokenArray() async{
  975. YSSqflite2 sqflite2 = YSSqflite2().init();
  976. List array = await sqflite2.rawQuery();
  977. if(!mounted)return;
  978. _refeshIndex++;
  979. YSSqflite2.notifier(context, array);
  980. }
  981. @override
  982. bool get wantKeepAlive => false;
  983. }