YSAlwayAddressAdd.dart 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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/login/view/YSHelpView.dart';
  5. import 'package:flutter_wallet/tools/YSNetWork.dart';
  6. import 'package:flutter_wallet/tools/YSSqflite.dart';
  7. import 'package:flutter_wallet/tools/YSTools.dart';
  8. import '../generated/l10n.dart';
  9. import '../tools/YSColors.dart';
  10. import '../tools/YSRefrehLoad.dart';
  11. class YSAlwayAddressAdd extends StatefulWidget {
  12. const YSAlwayAddressAdd({Key? key}) : super(key: key);
  13. @override
  14. YSAlwayAddressAddState createState() => YSAlwayAddressAddState();
  15. }
  16. class YSAlwayAddressAddState extends State<YSAlwayAddressAdd> {
  17. final List _array = [
  18. {'title':'钱包地址','tips':'请输入地址','index':1,'key':'address'},
  19. {'title':'设置名称','tips':'请输入名称','index':2,'key':'name'},
  20. {'title':'设置备注','tips':'备注仅做补充信息,不参与链上交易','index':3,'key':'remark'}
  21. ];
  22. TextEditingController _addressField = TextEditingController();
  23. TextEditingController _nameField = TextEditingController();
  24. TextEditingController _remarkField = TextEditingController();
  25. List _chooseArray = [];
  26. @override
  27. void dispose() {
  28. _addressField.dispose();
  29. _nameField.dispose();
  30. _remarkField.dispose();
  31. super.dispose();
  32. }
  33. @override
  34. Widget build(BuildContext context) {
  35. return YSBase(
  36. ysTitle: S.current.XINJIANLIANXIREN,
  37. ysChild: Column(
  38. children: [
  39. Container(
  40. width: ysWidth(context),
  41. color: Colors.white,
  42. child: Column(
  43. children: [
  44. Container(
  45. height: hsp(45),
  46. color: YSColors.containColor(context),
  47. padding: EdgeInsets.only(left: hsp(15),right: hsp(15)),
  48. alignment: Alignment.centerLeft,
  49. child: Text(S.current.QUANBUWANGLUO,style: YSColors.contentStyle(context),),
  50. ),
  51. Divider(height: hsp(1),color: YSColors.lineColor(context),),
  52. GestureDetector(
  53. onTap: (){
  54. ysShowBottomAlertView(context, YSAlwayAddressAlertView(valueSetter: (value){
  55. _chooseArray.clear();
  56. _chooseArray = value;
  57. setState(() {});
  58. },),isBarr: true);
  59. },
  60. behavior: HitTestBehavior.opaque,
  61. child: Container(
  62. height: hsp(60),
  63. padding: EdgeInsets.only(left: hsp(15),right: hsp(15)),
  64. child: Row(
  65. children: [
  66. Expanded(child: SingleChildScrollView(
  67. scrollDirection: Axis.horizontal,
  68. padding: const EdgeInsets.all(0),
  69. child: Stack(
  70. children: [
  71. for(int i = 0;i<_chooseArray.length;i++)Container(
  72. height: hsp(30),
  73. width: hsp(30),
  74. margin: EdgeInsets.only(left: hsp(i*20)),
  75. decoration: BoxDecoration(
  76. borderRadius: const BorderRadius.all(Radius.circular(50)),
  77. color: Colors.white,
  78. image: DecorationImage(image: NetworkImage(_chooseArray[i]['icon'],),),
  79. boxShadow: [
  80. BoxShadow(color: YSColors.shadowColor(context),blurRadius: 3)
  81. ]
  82. ),
  83. )
  84. ],
  85. ),
  86. )),
  87. Icon(Icons.chevron_right,size: hsp(25),color: YSColors.shadowColor(context),)
  88. ],
  89. ),
  90. ),
  91. ),
  92. Divider(height: hsp(1),color: YSColors.lineColor(context),),
  93. ListView.separated(
  94. itemBuilder: (context,index){
  95. Map item = _array[index];
  96. return Container(
  97. padding: EdgeInsets.only(top: hsp(15),bottom: hsp(15),left: hsp(15),right: hsp(15)),
  98. color: Colors.white,
  99. child: Row(
  100. children: [
  101. SizedBox(
  102. width: hsp(60),
  103. child: Text(item['title'],style: YSColors.contentStyle(context),),
  104. ),
  105. Expanded(child: CupertinoTextField(
  106. placeholder: item['tips'],
  107. style: YSColors.contentStyle(context),
  108. decoration: const BoxDecoration(),
  109. controller: item['index']==1?_addressField:item['index']==2?_nameField:_remarkField,
  110. suffix: item['index']==1?GestureDetector(
  111. onTap: () async{
  112. String result = await YSCodeImage.scanCode();
  113. if(result.isNotEmpty&&mounted){
  114. _addressField.text = result;
  115. }
  116. },
  117. child: Image.asset(YSColors.imageStyle(context, '扫码 (3)'),height: hsp(20),width: hsp(20),),
  118. ):Container(),
  119. ))
  120. ],
  121. ),
  122. );
  123. },
  124. separatorBuilder: (context,index){
  125. return Divider(height: hsp(1),color: YSColors.lineColor(context),);
  126. },
  127. itemCount: _array.length,
  128. padding: const EdgeInsets.all(0),
  129. shrinkWrap: true,
  130. physics: const NeverScrollableScrollPhysics(),
  131. ),
  132. ],
  133. ),
  134. ),
  135. GestureDetector(
  136. onTap: (){
  137. FocusScope.of(context).unfocus();
  138. if(_chooseArray.isEmpty){
  139. ysFlutterToast('请选择网络');
  140. return;
  141. }
  142. if(_addressField.text.isEmpty){
  143. ysFlutterToast('请完善钱包地址');
  144. return;
  145. }
  146. if(_nameField.text.isEmpty){
  147. ysFlutterToast('请设置名称');
  148. return;
  149. }
  150. for (var element in _chooseArray) {
  151. YSAlwayAddressTable table = YSAlwayAddressTable().init();
  152. table.rawInsert(_addressField.text, _nameField.text, _remarkField.text, element['icon'], element['id']);
  153. Navigator.of(context).pop('');
  154. }
  155. },
  156. child: Container(
  157. width: ysWidth(context)-hsp(150),
  158. height: hsp(50),
  159. margin: EdgeInsets.only(top: hsp(50)),
  160. decoration: BoxDecoration(
  161. color: YSColors.buttonColor(context),
  162. borderRadius: const BorderRadius.all(Radius.circular(5))
  163. ),
  164. alignment: Alignment.center,
  165. child: Text('添加',style: YSColors.buttonStyle(context),),
  166. ),
  167. )
  168. ],
  169. ),
  170. );
  171. }
  172. }
  173. class YSAlwayAddressAlertView extends StatefulWidget {
  174. final ValueSetter valueSetter;
  175. const YSAlwayAddressAlertView({Key? key, required this.valueSetter}) : super(key: key);
  176. @override
  177. YSAlwayAddressAlertViewState createState() => YSAlwayAddressAlertViewState();
  178. }
  179. class YSAlwayAddressAlertViewState extends State<YSAlwayAddressAlertView> {
  180. final List _chooseArray = [];
  181. @override
  182. Widget build(BuildContext context) {
  183. return Container(
  184. height: hsp(400),
  185. decoration: BoxDecoration(
  186. color: YSColors.containColor(context),
  187. borderRadius: const BorderRadius.only(topRight: Radius.circular(10),topLeft: Radius.circular(10))
  188. ),
  189. child: Column(
  190. children: [
  191. Container(
  192. height: hsp(49),
  193. alignment: Alignment.center,
  194. padding: EdgeInsets.only(left: hsp(15),right: hsp(15)),
  195. child: Row(
  196. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  197. children: [
  198. SizedBox(
  199. width: hsp(50),
  200. ),
  201. Text(S.current.XUANZEWANGLUO,style: YSColors.titleStyle(context),),
  202. GestureDetector(
  203. onTap: (){
  204. if(_chooseArray.isEmpty)return;
  205. widget.valueSetter(_chooseArray);
  206. Navigator.pop(context);
  207. },
  208. child: Container(
  209. width: hsp(50),
  210. alignment: Alignment.centerRight,
  211. child: Text('选择',style: YSColors.contentStyle(context),),
  212. ),
  213. )
  214. ],
  215. )
  216. ),
  217. Divider(height: hsp(1),color: YSColors.lineColor(context),),
  218. SizedBox(
  219. height: hsp(350),
  220. child: YSRefreshLoad(
  221. url: 'chains',
  222. request: const {},
  223. postData: (value) {
  224. YSData().typeArray = value;
  225. setState(() {});
  226. },
  227. child: ListView.separated(
  228. itemBuilder: (context,index){
  229. Map item = YSData().typeArray[index];
  230. bool isChoose = _chooseArray.contains(item);
  231. return GestureDetector(
  232. onTap: () async{
  233. if(isChoose){
  234. _chooseArray.remove(item);
  235. }else{
  236. _chooseArray.add(item);
  237. }
  238. setState(() {});
  239. // if(!mounted)return;
  240. // Navigator.pop(context);
  241. },
  242. behavior: HitTestBehavior.opaque,
  243. child: Container(
  244. height: hsp(49),
  245. padding: EdgeInsets.only(left: hsp(15),right: hsp(15)),
  246. child: Row(
  247. children: [
  248. SizedBox(
  249. height: hsp(40),
  250. width: hsp(40),
  251. child: YSImage.network(item['icon'],),
  252. ),
  253. Expanded(
  254. child: Text(' ${item['name']}',style: YSColors.contentStyle(context),)
  255. ),
  256. if(isChoose)Image.asset(YSColors.imageStyle(context, '矩形2'),height: hsp(15),width: hsp(15),),
  257. ],
  258. ),
  259. ),
  260. );
  261. },
  262. separatorBuilder: (context,index){
  263. return Divider(height: hsp(1),color: YSColors.lineColor(context),);
  264. },
  265. itemCount: YSData().typeArray.length
  266. ),
  267. ),
  268. )
  269. ],
  270. ),
  271. );
  272. }
  273. }