YSWalletListItemDetail.dart 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter_wallet/base/YSBase.dart';
  4. import 'package:flutter_wallet/generated/l10n.dart';
  5. import 'package:flutter_wallet/login/view/YSHelpView.dart';
  6. import 'package:flutter_wallet/tools/YSColors.dart';
  7. import 'package:flutter_wallet/tools/YSNetWork.dart';
  8. import 'package:flutter_wallet/tools/YSRefrehLoad.dart';
  9. import 'package:flutter_wallet/tools/YSSqflite.dart';
  10. import 'package:flutter_wallet/tools/YSTools.dart';
  11. import 'package:flutter_wallet/wallet/YSTansDetail.dart';
  12. import 'YSWalletCollection.dart';
  13. import 'YSWalletTransfer.dart';
  14. class YSWalletListItemDetail extends StatefulWidget {
  15. final Map item;
  16. const YSWalletListItemDetail({Key? key, required this.item}) : super(key: key);
  17. @override
  18. YSWalletListItemDetailState createState() => YSWalletListItemDetailState();
  19. }
  20. class YSWalletListItemDetailState extends State<YSWalletListItemDetail> {
  21. List _dataArray = [];
  22. Map _token = {};
  23. @override
  24. void initState() {
  25. networkDelay((){
  26. _getToken();
  27. });
  28. super.initState();
  29. }
  30. _getToken() {
  31. List list = YSData().allTokenArray.where((element) => element['address']==widget.item['address']).toList();
  32. if(list.isNotEmpty){
  33. _token = list.first;
  34. }else{
  35. _token = widget.item;
  36. }
  37. setState(() {});
  38. }
  39. @override
  40. Widget build(BuildContext context) {
  41. return YSBase2(
  42. isScroll: false,
  43. ysTitle: _token['name']??'',
  44. // ysRightWidget: GestureDetector(
  45. // onTap: (){},
  46. // child: Text(S.current.DAIBIXIANGQING,style: YSColors.content2Style(context),),
  47. // ),
  48. ysChild: _token.isEmpty?Container():Padding(
  49. padding: EdgeInsets.only(left: hsp(20),right: hsp(20)),
  50. child: Column(
  51. children: [
  52. Container(
  53. margin: EdgeInsets.only(top: hsp(20)),
  54. height: hsp(60),
  55. width: hsp(60),
  56. decoration: BoxDecoration(
  57. color: Colors.grey,
  58. borderRadius: const BorderRadius.all(Radius.circular(50)),
  59. border: Border.all(color: YSColors.containColor(context),width: hsp(2)),
  60. image: DecorationImage(image: NetworkImage(_token['icon_url']))
  61. ),
  62. ),
  63. Padding(
  64. padding: EdgeInsets.only(top: hsp(10)),
  65. child: Text('${_token['name']} ',style: YSColors.title2Style(context),),
  66. ),
  67. YSBalanceView(public: _token['address'],style: YSColors.sub2Style(context),walletAddress: YSData().wallet['public'],type: 1,),
  68. // Text('\$ 82.878',style: YSColors.sub2Style(context),),
  69. Container(
  70. height: hsp(45),
  71. decoration: BoxDecoration(
  72. color: YSColors.containColor(context),
  73. borderRadius: const BorderRadius.all(Radius.circular(10))
  74. ),
  75. margin: EdgeInsets.only(top: hsp(15)),
  76. padding: EdgeInsets.only(left: hsp(15),right: hsp(15)),
  77. child: Row(
  78. children: [
  79. Text(S.current.JIAGE,style: YSColors.contentStyle(context),),
  80. if(_token['price_usd']!=null)Expanded(
  81. child: Column(
  82. crossAxisAlignment: CrossAxisAlignment.end,
  83. mainAxisSize: MainAxisSize.min,
  84. children: [
  85. Text(toDecimalFlex(_token['price_usd'],range: 4),style: YSColors.subStyle(context),),
  86. Text('\$ ${toDecimalFlex(_token['price_usd'],range: 4)}',style: YSColors.sub3Style(context),),
  87. ],
  88. )
  89. )
  90. ],
  91. ),
  92. ),
  93. Container(
  94. margin: EdgeInsets.only(top: hsp(40)),
  95. height: hsp(20),
  96. child: Row(
  97. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  98. children: [
  99. Text(S.current.JIAOYIJILU,style: YSColors.contentStyle(context),),
  100. PopupMenuButton(
  101. itemBuilder: (BuildContext context) {
  102. return [
  103. PopupMenuItem(value: "0",child: Text("全部",style: YSColors.contentStyle(context),),),
  104. PopupMenuItem(value: "1",child: Text("转入",style: YSColors.contentStyle(context),),),
  105. PopupMenuItem(value: "2",child: Text("转出",style: YSColors.contentStyle(context),),),
  106. ];
  107. },
  108. child: Image.asset(YSColors.imageStyle(context, '更多 (5)'),height: hsp(15),width: hsp(15),),
  109. onSelected: (value){
  110. Map request = YSData().wallet['public']!=_token['address']?{
  111. 'chain_id':YSData().typeId,'contract_address':_token['address'],'address':YSData().wallet['public'],'type':0
  112. }:{
  113. 'chain_id':YSData().typeId,'address':YSData().wallet['public'],'type':0
  114. };
  115. request['type'] = value;
  116. refreshKey.currentState?.refresh(request: request);
  117. },
  118. )
  119. ],
  120. ),
  121. ),
  122. Expanded(
  123. child: Container(
  124. margin: EdgeInsets.only(top: hsp(10),bottom: hsp(15)),
  125. decoration: BoxDecoration(
  126. color: YSColors.containColor(context),
  127. borderRadius: const BorderRadius.all(Radius.circular(10))
  128. ),
  129. padding: EdgeInsets.all(hsp(15)),
  130. child: LayoutBuilder(
  131. builder: (context,conSize) {
  132. return Column(
  133. children: [
  134. // Container(
  135. // height: hsp(40),
  136. // decoration: const BoxDecoration(
  137. // color: Color(0xFFEFF1F9),
  138. // borderRadius: BorderRadius.all(Radius.circular(10))
  139. // ),
  140. // padding: EdgeInsets.only(left: hsp(15),right: hsp(15)),
  141. // child: Row(
  142. // children: [
  143. // SizedBox(
  144. // width: conSize.maxWidth-hsp(50),
  145. // child: Text(S.current.NINYIKAIQIYINCANGXIAOEJIAOYI,style: TextStyle(fontSize: zsp(11),color: const Color(0xFF3D5AFF)),),
  146. // ),
  147. // Icon(Icons.chevron_right,size: hsp(20),color: const Color(0xFF3D5AFF),)
  148. // ],
  149. // ),
  150. // ),
  151. SizedBox(
  152. height: conSize.maxHeight-hsp(0),
  153. child: YSRefreshLoad(
  154. key: refreshKey,
  155. url: 'transactions',
  156. request: YSData().wallet['public']!=_token['address']?{
  157. 'chain_id':YSData().typeId,'contract_address':_token['address'],'address':YSData().wallet['public'],'type':0
  158. }:{
  159. 'chain_id':YSData().typeId,'address':YSData().wallet['public'],'type':0
  160. },
  161. postData: (value) async{
  162. _dataArray = value;
  163. YSTansTable table = YSTansTable().init();
  164. List array = await table.rawQuery();
  165. List temp = [];
  166. for (var element in _dataArray) {
  167. for (var element2 in array) {
  168. if(element2['hash']==element['hash']){
  169. temp.add(element2);
  170. table.rawDelete('${element2['id']}');
  171. }
  172. }
  173. }
  174. for (var element in temp) {
  175. array.remove(element);
  176. }
  177. _dataArray.insertAll(0,array);
  178. setState(() {});
  179. },
  180. child: SingleChildScrollView(
  181. child: ListView.builder(
  182. itemBuilder: (context,index){
  183. Map item = _dataArray[index];
  184. return GestureDetector(
  185. onTap: (){
  186. LogUtil.d(item);
  187. Navigator.of(context).push(
  188. CupertinoPageRoute(builder: (context){
  189. return YSTansDetail(item: item,tokenAddress: _token['address'],);
  190. })
  191. );
  192. },
  193. behavior: HitTestBehavior.opaque,
  194. child: Container(
  195. padding: EdgeInsets.only(top: hsp(10),bottom: hsp(10)),
  196. decoration: BoxDecoration(
  197. border: Border(top: BorderSide(color: YSColors.lineColor(context),width: hsp(1)))
  198. ),
  199. child: Row(
  200. children: [
  201. Image.asset(YSColors.imageStyle(context, '编组 ${item['type']==1?'64':'54'}'),height: hsp(30),width: hsp(30),),
  202. Expanded(
  203. child: Padding(
  204. padding: EdgeInsets.only(left: hsp(10),right: hsp(10)),
  205. child: Column(
  206. crossAxisAlignment: CrossAxisAlignment.start,
  207. children: [
  208. Row(
  209. children: [
  210. Container(
  211. constraints: BoxConstraints(
  212. maxWidth: conSize.maxWidth-hsp(190),
  213. ),
  214. child: Text(ysTextCut(item['to_addr']),style: YSColors.contentStyle(context),maxLines: 1,),
  215. ),
  216. Padding(
  217. padding: const EdgeInsets.only(left: 5),
  218. child: GestureDetector(
  219. onTap: (){
  220. YSCopyPaste.copy(item['to_addr']);
  221. },
  222. child: Image.asset(YSColors.imageStyle(context, '复制备份'),height: hsp(10),width: hsp(10),),
  223. ),
  224. )
  225. ],
  226. ),
  227. if(item['timestamp']!=null)Text('${toDateFlex(item['timestamp'])}',style: YSColors.subStyle(context),maxLines: 1,),
  228. ],
  229. ),
  230. )
  231. ),
  232. Container(
  233. width: hsp(100),
  234. alignment: Alignment.centerRight,
  235. child: Column(
  236. crossAxisAlignment: CrossAxisAlignment.end,
  237. children: [
  238. Text(('${item['status']}'=='1'?S.current.JIAOYICHENGGONG:'${item['status']}'=='0'?S.current.JIAOYISHIBAI:S.current.JIAOYIZHONG).fixAutoLines(),
  239. style: TextStyle(fontSize: zsp(10),color: '${item['status']}'=='1'?const Color(0xFF68AF64):const Color(0xFFDE5656)),maxLines: 1,),
  240. if(item['symbol']!=null)Padding(
  241. padding: EdgeInsets.only(top: hsp(5)),
  242. child: Text(''
  243. '${item['type']==2?'-':item['type']==1?'+':''}${toDecimalFlex((item['value']??double.parse(item['amount']??'0')),decimal: item['decimal']??0,range: 5)}${item['symbol']??''}',
  244. style: TextStyle(fontSize: zsp(12),color: item['type']==1?const Color(0xFF68AF64):const Color(0xFFDE5656)),maxLines: 1,),
  245. )
  246. ],
  247. ),
  248. )
  249. ],
  250. ),
  251. ),
  252. );
  253. },
  254. itemCount: _dataArray.length,
  255. padding: EdgeInsets.only(top: hsp(15)),
  256. shrinkWrap: true,
  257. physics: const NeverScrollableScrollPhysics(),
  258. ),
  259. ),
  260. ),
  261. )
  262. ],
  263. );
  264. }
  265. ),
  266. )
  267. ),
  268. Container(
  269. margin: EdgeInsets.only(bottom: hsp(15)),
  270. height: hsp(45),
  271. child: Row(
  272. children: [
  273. Expanded(
  274. child: GestureDetector(
  275. onTap: (){
  276. Navigator.of(context).push(
  277. CupertinoPageRoute(builder: (context){
  278. return const YSWalletTransfer();
  279. })
  280. ).then((value) {
  281. Map request = YSData().wallet['public']!=_token['address']?{
  282. 'chain_id':YSData().typeId,'contract_address':_token['address'],'address':YSData().wallet['public'],'type':0
  283. }:{
  284. 'chain_id':YSData().typeId,'address':YSData().wallet['public'],'type':0
  285. };
  286. refreshKey.currentState?.refresh(request: request);
  287. });
  288. },
  289. behavior: HitTestBehavior.opaque,
  290. child: Container(
  291. decoration: const BoxDecoration(
  292. color: Color(0xFF68AF64),
  293. borderRadius: BorderRadius.all(Radius.circular(10))
  294. ),
  295. alignment: Alignment.center,
  296. child: SingleChildScrollView(
  297. physics: const NeverScrollableScrollPhysics(),
  298. scrollDirection: Axis.horizontal,
  299. child: Row(
  300. mainAxisSize: MainAxisSize.min,
  301. children: [
  302. Image.asset(YSColors.imageStyle(context, '形状3'),height: hsp(15),width: hsp(15),),
  303. Text(' ${S.current.ZHUANZHANG}',style: YSColors.buttonStyle(context),)
  304. ],
  305. ),
  306. ),
  307. ),
  308. )
  309. ),
  310. SizedBox(width: hsp(15),),
  311. Expanded(
  312. child: GestureDetector(
  313. onTap: (){
  314. Navigator.of(context).push(
  315. CupertinoPageRoute(builder: (context){
  316. return YSWalletCollection(wallet: YSData().wallet,);
  317. })
  318. );
  319. },
  320. behavior: HitTestBehavior.opaque,
  321. child: Container(
  322. decoration: const BoxDecoration(
  323. color: Color(0xFF3D5AFF),
  324. borderRadius: BorderRadius.all(Radius.circular(10))
  325. ),
  326. alignment: Alignment.center,
  327. child: Row(
  328. mainAxisSize: MainAxisSize.min,
  329. children: [
  330. Image.asset(YSColors.imageStyle(context, '形状 2'),height: hsp(15),width: hsp(15),),
  331. Text(' ${S.current.SHOUKUAN}',style: YSColors.buttonStyle(context),)
  332. ],
  333. ),
  334. ),
  335. )
  336. )
  337. ],
  338. ),
  339. )
  340. ],
  341. ),
  342. ),
  343. );
  344. }
  345. }