YSTansDetail.dart 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_wallet/base/YSBase.dart';
  3. import 'package:flutter_wallet/generated/l10n.dart';
  4. import 'package:flutter_wallet/tools/YSNetWork.dart';
  5. import 'package:flutter_wallet/tools/YSTools.dart';
  6. import '../tools/YSColors.dart';
  7. class YSTansDetail extends StatefulWidget {
  8. final Map item;
  9. final String tokenAddress;
  10. const YSTansDetail({Key? key, required this.item, required this.tokenAddress}) : super(key: key);
  11. @override
  12. YSTansDetailState createState() => YSTansDetailState();
  13. }
  14. class YSTansDetailState extends State<YSTansDetail> {
  15. final List _array1 = [];
  16. final List _array2 = [];
  17. String _hash = '';
  18. String _status = '2';
  19. @override
  20. void initState() {
  21. _getArrayData(widget.item);
  22. super.initState();
  23. }
  24. _getArrayData(Map item) async{
  25. _array1.clear();
  26. _array2.clear();
  27. _status = '${item['status']}';
  28. _array1.addAll([
  29. {'title':S.current.FASONGFANG,'value':item['from_addr'],'isCopy':true},
  30. {'title':S.current.JIESHOUFANG,'value':item['to_addr'],'isCopy':true},
  31. if(item['gas_price']!=null){'title':S.current.WANGLUOFEI,'value':toDecimalFlex(double.parse('${item['gas_price']}'),decimal: 18,range: 10),'isCopy':false},
  32. ]);
  33. _array2.addAll([
  34. {'title':S.current.JIAOYIHAXI,'value':item['hash'],'isCopy':true},
  35. if(item['block_number']!=null){'title':S.current.QUKUAIGAODU,'value':'${item['block_number']??''}','isCopy':true},
  36. if(item['timestamp']!=null){'title':S.current.JIAOYISHIJIAN,'value':toDateFlex(item['timestamp']),'isCopy':false},
  37. ]);
  38. _hash = widget.item['hash'];
  39. setState(() {});
  40. }
  41. Future<void> _refresh() async{
  42. Map request = {'chain_id':YSData().typeId,'address':YSData().wallet['public'],'type':0,'page':1,'count':100};
  43. if(YSData().wallet['public']!=widget.tokenAddress){
  44. request['contract_address'] = widget.tokenAddress;
  45. }
  46. YSNetWork.ysRequestHttp(context, type: RequestType.get, api: 'transactions', parameter: request, successSetter: (dict){
  47. List list = dict['data']['list']??[];
  48. List array = list.where((element) => element['hash']==widget.item['hash']).toList();
  49. if(array.isNotEmpty){
  50. Map item = array.first;
  51. _getArrayData(item);
  52. }
  53. });
  54. }
  55. @override
  56. Widget build(BuildContext context) {
  57. return YSBase(
  58. ysTitle: S.current.JIAOYIXIANGQING,
  59. ysChild: Container(
  60. width: ysWidth(context),
  61. height: ysHeight(context)-ysTOP(context)-60,
  62. margin: EdgeInsets.only(left: hsp(20),right: hsp(20)),
  63. padding: EdgeInsets.only(top: hsp(10)),
  64. child: RefreshIndicator(
  65. onRefresh: _refresh,
  66. child: SingleChildScrollView(
  67. physics: const AlwaysScrollableScrollPhysics(),
  68. child: Column(
  69. children: [
  70. //${'${item['status']}'=='1'?'交易成功':'${item['status']}'=='0'?'交易失败':'交易中'}
  71. _status=='1'?Icon(Icons.check_circle,size: hsp(60),color: Colors.green,):
  72. _status=='0'?Icon(Icons.error,size: hsp(60),color: Colors.red,):Icon(Icons.watch_later_rounded,size: hsp(60),color: Colors.grey,),
  73. Padding(
  74. padding: EdgeInsets.only(top: hsp(5),bottom: hsp(5)),
  75. child: Text(_status=='1'?S.current.JIAOYICHENGGONG:_status=='0'?S.current.JIAOYISHIBAI:S.current.JIAOYIZHONG,style: TextStyle(fontSize: zsp(14),color: _status=='1'?Colors.green:_status=='0'?Colors.red:Colors.grey),)
  76. ),
  77. Text('${widget.item['type']==2?'-':widget.item['type']==1?'+':''}${toDecimalFlex((widget.item['value']??
  78. double.parse(widget.item['amount'])??0),decimal: widget.item['decimal']??0,range: 5)}${widget.item['symbol']??''}',
  79. style: TextStyle(fontSize: zsp(16),color: widget.item['type']==1?const Color(0xFF68AF64):const Color(0xFFDE5656)),),
  80. Container(
  81. margin: EdgeInsets.only(top: hsp(20)),
  82. decoration: BoxDecoration(
  83. borderRadius: const BorderRadius.all(Radius.circular(10)),
  84. color: YSColors.containColor(context),
  85. boxShadow: [
  86. BoxShadow(color: YSColors.lineColor(context),blurRadius: 3)
  87. ],
  88. ),
  89. padding: EdgeInsets.all(hsp(20)),
  90. child: ListView.builder(
  91. itemBuilder: (context,index){
  92. Map item = _array1[index];
  93. return Padding(
  94. padding: EdgeInsets.only(top: hsp(10)),
  95. child: Column(
  96. mainAxisSize: MainAxisSize.min,
  97. crossAxisAlignment: CrossAxisAlignment.start,
  98. children: [
  99. Text(item['title'],style: YSColors.subStyle(context),),
  100. Row(
  101. children: [
  102. Text(ysTextCut(item['value'],number: 8),style: YSColors.contentStyle(context),),
  103. if(item['isCopy']==true)Padding(
  104. padding: EdgeInsets.only(left: hsp(5)),
  105. child: GestureDetector(
  106. onTap: (){
  107. YSCopyPaste.copy(item['value']);
  108. },
  109. behavior: HitTestBehavior.opaque,
  110. child: Image.asset(YSColors.imageStyle(context, '复制'),height: hsp(15),width: hsp(15),),
  111. ),
  112. )
  113. ],
  114. )
  115. ],
  116. ),
  117. );
  118. },
  119. padding: const EdgeInsets.all(0),
  120. physics: const NeverScrollableScrollPhysics(),
  121. shrinkWrap: true,
  122. itemCount: _array1.length,
  123. ),
  124. ),
  125. Container(
  126. margin: EdgeInsets.only(top: hsp(20)),
  127. decoration: BoxDecoration(
  128. borderRadius: const BorderRadius.all(Radius.circular(10)),
  129. color: YSColors.containColor(context),
  130. boxShadow: [
  131. BoxShadow(color: YSColors.lineColor(context),blurRadius: 3)
  132. ],
  133. ),
  134. padding: EdgeInsets.all(hsp(20)),
  135. child: Row(
  136. children: [
  137. Expanded(child: ListView.builder(
  138. itemBuilder: (context,index){
  139. Map item = _array2[index];
  140. return Padding(
  141. padding: EdgeInsets.only(top: hsp(10)),
  142. child: Column(
  143. mainAxisSize: MainAxisSize.min,
  144. crossAxisAlignment: CrossAxisAlignment.start,
  145. children: [
  146. Text(item['title'],style: YSColors.subStyle(context),),
  147. Row(
  148. children: [
  149. Text(ysTextCut(item['value'],number: 8),style: YSColors.contentStyle(context),),
  150. if(item['isCopy']==true)Padding(
  151. padding: EdgeInsets.only(left: hsp(5)),
  152. child: GestureDetector(
  153. onTap: (){
  154. YSCopyPaste.copy(item['value']);
  155. },
  156. behavior: HitTestBehavior.opaque,
  157. child: Image.asset(YSColors.imageStyle(context, '复制'),height: hsp(15),width: hsp(15),),
  158. ),
  159. )
  160. ],
  161. )
  162. ],
  163. ),
  164. );
  165. },
  166. padding: const EdgeInsets.all(0),
  167. physics: const NeverScrollableScrollPhysics(),
  168. shrinkWrap: true,
  169. itemCount: _array2.length,
  170. )),
  171. SizedBox(
  172. height: hsp(100),
  173. width: hsp(100),
  174. child: YSCodeImage.codeImage(_hash),
  175. )
  176. ],
  177. ),
  178. )
  179. ],
  180. ),
  181. ),
  182. ),
  183. ),
  184. );
  185. }
  186. }
  187. class YSTansDetail2 extends StatefulWidget {
  188. final Map item;
  189. const YSTansDetail2({Key? key, required this.item}) : super(key: key);
  190. @override
  191. YSTansDetail2State createState() => YSTansDetail2State();
  192. }
  193. class YSTansDetail2State extends State<YSTansDetail2> {
  194. final List _array1 = [];
  195. final List _array2 = [];
  196. String _hash = '';
  197. int _status = 2;
  198. _getArrayData(Map item) async{
  199. _array1.clear();
  200. _array2.clear();
  201. _status = item['TxStatus'];
  202. _array1.addAll([
  203. {'title':S.current.FASONGFANG,'value':item['FromAddress'],'isCopy':true},
  204. {'title':S.current.JIESHOUFANG,'value':item['ToAddress'],'isCopy':true},
  205. if(item['gas_price']!=null){'title':S.current.WANGLUOFEI,'value':toDecimalFlex(item['gas_price'],decimal: item['Decimal'],range: 6),'isCopy':false},
  206. ]);
  207. _array2.addAll([
  208. {'title':S.current.JIAOYIHAXI,'value':item['Hash'],'isCopy':true},
  209. if(item['BlockNum']!=null){'title':S.current.QUKUAIGAODU,'value':'${item['BlockNum']??''}','isCopy':true},
  210. if(item['CreateTime']!=null){'title':S.current.JIAOYISHIJIAN,'value':item['CreateTime'],'isCopy':false},
  211. ]);
  212. _hash = widget.item['Hash'];
  213. setState(() {});
  214. }
  215. @override
  216. void initState() {
  217. _getArrayData(widget.item);
  218. _postRead();
  219. super.initState();
  220. }
  221. _postRead() async{
  222. Map request = {};
  223. request['ids'] = widget.item['ID'];
  224. request['address'] = YSData().wallet['public'];
  225. request['chain_id'] = YSData().typeId;
  226. Map dict = await YSNetWork.ysRequestHttpNOSet(context, type: RequestType.get, api: 'settransnotice', parameter: request);
  227. if(dict.isNotEmpty){
  228. }
  229. }
  230. @override
  231. Widget build(BuildContext context) {
  232. LogUtil.d(widget.item);
  233. return YSBase(
  234. ysTitle: S.current.JIAOYIXIANGQING,
  235. ysChild: Container(
  236. width: ysWidth(context),
  237. height: ysHeight(context)-ysTOP(context)-60,
  238. margin: EdgeInsets.only(left: hsp(20),right: hsp(20)),
  239. padding: EdgeInsets.only(top: hsp(10)),
  240. child: SingleChildScrollView(
  241. physics: const AlwaysScrollableScrollPhysics(),
  242. child: Column(
  243. children: [
  244. //${'${item['status']}'=='1'?'交易成功':'${item['status']}'=='0'?'交易失败':'交易中'}
  245. _status==1?Icon(Icons.check_circle,size: hsp(60),color: Colors.green,):Icon(Icons.error,size: hsp(60),color: Colors.red,),
  246. Padding(
  247. padding: EdgeInsets.only(top: hsp(5),bottom: hsp(5)),
  248. child: Text(_status==1?S.current.JIAOYICHENGGONG:_status==0?S.current.JIAOYISHIBAI:'',style: TextStyle(fontSize: zsp(14),color: _status==1?Colors.green:Colors.red),)
  249. ),
  250. Text('${widget.item['type']==2?'-':widget.item['type']==1?'+':''}${toDecimalFlex(widget.item['Amount'],decimal: widget.item['Decimal']??0,range: 6)}${widget.item['Symbol']??''}',
  251. style: TextStyle(fontSize: zsp(16),color: widget.item['type']==1?const Color(0xFF68AF64):const Color(0xFFDE5656)),),
  252. Container(
  253. margin: EdgeInsets.only(top: hsp(20)),
  254. decoration: BoxDecoration(
  255. borderRadius: const BorderRadius.all(Radius.circular(10)),
  256. color: YSColors.containColor(context),
  257. boxShadow: [
  258. BoxShadow(color: YSColors.lineColor(context),blurRadius: 3)
  259. ],
  260. ),
  261. padding: EdgeInsets.all(hsp(20)),
  262. child: ListView.builder(
  263. itemBuilder: (context,index){
  264. Map item = _array1[index];
  265. return Padding(
  266. padding: EdgeInsets.only(top: hsp(10)),
  267. child: Column(
  268. mainAxisSize: MainAxisSize.min,
  269. crossAxisAlignment: CrossAxisAlignment.start,
  270. children: [
  271. Text(item['title'],style: YSColors.subStyle(context),),
  272. Row(
  273. children: [
  274. Text(ysTextCut(item['value'],number: 8),style: YSColors.contentStyle(context),),
  275. if(item['isCopy']==true)Padding(
  276. padding: EdgeInsets.only(left: hsp(5)),
  277. child: GestureDetector(
  278. onTap: (){
  279. YSCopyPaste.copy(item['value']);
  280. },
  281. behavior: HitTestBehavior.opaque,
  282. child: Image.asset(YSColors.imageStyle(context, '复制'),height: hsp(15),width: hsp(15),),
  283. ),
  284. )
  285. ],
  286. )
  287. ],
  288. ),
  289. );
  290. },
  291. padding: const EdgeInsets.all(0),
  292. physics: const NeverScrollableScrollPhysics(),
  293. shrinkWrap: true,
  294. itemCount: _array1.length,
  295. ),
  296. ),
  297. Container(
  298. margin: EdgeInsets.only(top: hsp(20)),
  299. decoration: BoxDecoration(
  300. borderRadius: const BorderRadius.all(Radius.circular(10)),
  301. color: YSColors.containColor(context),
  302. boxShadow: [
  303. BoxShadow(color: YSColors.lineColor(context),blurRadius: 3)
  304. ],
  305. ),
  306. padding: EdgeInsets.all(hsp(20)),
  307. child: Row(
  308. children: [
  309. Expanded(child: ListView.builder(
  310. itemBuilder: (context,index){
  311. Map item = _array2[index];
  312. return Padding(
  313. padding: EdgeInsets.only(top: hsp(10)),
  314. child: Column(
  315. mainAxisSize: MainAxisSize.min,
  316. crossAxisAlignment: CrossAxisAlignment.start,
  317. children: [
  318. Text(item['title'],style: YSColors.subStyle(context),),
  319. Row(
  320. children: [
  321. Text(ysTextCut(item['value'],number: 8),style: YSColors.contentStyle(context),),
  322. if(item['isCopy']==true)Padding(
  323. padding: EdgeInsets.only(left: hsp(5)),
  324. child: GestureDetector(
  325. onTap: (){
  326. YSCopyPaste.copy(item['value']);
  327. },
  328. behavior: HitTestBehavior.opaque,
  329. child: Image.asset(YSColors.imageStyle(context, '复制'),height: hsp(15),width: hsp(15),),
  330. ),
  331. )
  332. ],
  333. )
  334. ],
  335. ),
  336. );
  337. },
  338. padding: const EdgeInsets.all(0),
  339. physics: const NeverScrollableScrollPhysics(),
  340. shrinkWrap: true,
  341. itemCount: _array2.length,
  342. )),
  343. SizedBox(
  344. height: hsp(100),
  345. width: hsp(100),
  346. child: YSCodeImage.codeImage(_hash),
  347. )
  348. ],
  349. ),
  350. )
  351. ],
  352. ),
  353. ),
  354. ),
  355. );
  356. }
  357. }