YSWalletManager.dart 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. import 'package:dart_ping/dart_ping.dart';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter_wallet/base/YSBase.dart';
  5. import 'package:flutter_wallet/generated/l10n.dart';
  6. import 'package:flutter_wallet/login/view/YSHelpView.dart';
  7. import 'package:flutter_wallet/tools/YSAlertView.dart';
  8. import 'package:flutter_wallet/tools/YSColors.dart';
  9. import 'package:flutter_wallet/tools/YSTools.dart';
  10. import 'package:flutter_wallet/wallet/view/YSWalletManagerListItemView.dart';
  11. import 'package:provider/provider.dart';
  12. import '../tools/YSPingView.dart';
  13. import '../tools/YSSqflite.dart';
  14. import 'YSWalletDetail.dart';
  15. import 'YSWalletRocChoose.dart';
  16. class YSWalletManager extends StatefulWidget {
  17. final bool isChoose;
  18. const YSWalletManager({Key? key, this.isChoose = false}) : super(key: key);
  19. @override
  20. YSWalletManagerState createState() => YSWalletManagerState();
  21. }
  22. class YSWalletManagerState extends State<YSWalletManager> {
  23. List _walletArray = [];
  24. bool _isDrag = false;
  25. @override
  26. void initState() {
  27. _getWalletData();
  28. super.initState();
  29. }
  30. _getWalletData() async{
  31. YSSqflite sqflite = YSSqflite().init();
  32. _walletArray = await sqflite.rawQuery();
  33. if(!mounted)return;
  34. YSSqflite.notifier(context, _walletArray);
  35. }
  36. @override
  37. Widget build(BuildContext context) {
  38. return YSBase2(
  39. titleType: 2,
  40. ysRightWidget: const YSCapsule(),
  41. ysChild: Padding(
  42. padding: EdgeInsets.only(left: hsp(20),right: hsp(20)),
  43. child: Column(
  44. children: [
  45. SizedBox(
  46. height: hsp(50),
  47. child: Row(
  48. children: [
  49. Text('${S.current.QIANBAOGUANLI2} ',style: YSColors.title2Style(context),),
  50. GestureDetector(
  51. onTap: (){
  52. _isDrag = !_isDrag;
  53. // _walletArray = _walletArray.reversed.toList();
  54. setState(() {});
  55. },
  56. child: Transform.rotate(angle: _isDrag?3.14:0,child: Image.asset(YSColors.imageStyle(context, '排序'),height: hsp(17),width: hsp(17),),)
  57. ),
  58. const YSPingView(),
  59. const Expanded(child: SizedBox()),
  60. GestureDetector(
  61. onTap: (){
  62. YSData().isManager = true;
  63. ysShowBottomAlertView(context, const YSChooseWalletType());
  64. },
  65. child: Image.asset(YSColors.imageStyle(context, '添 加'),height: hsp(17),width: hsp(17),),
  66. )
  67. ],
  68. ),
  69. ),
  70. Consumer(
  71. builder: (context,YSWalletNotifier value,child) {
  72. _walletArray = value.walletArray;
  73. return ListView.separated(
  74. itemBuilder: (context,index){
  75. Map item = _walletArray[index];
  76. return _isDrag==true?LongPressDraggable(
  77. onDragEnd: (DraggableDetails detail) async{
  78. int moveIndex = (detail.offset.dy-130)~/hsp(70);
  79. if(moveIndex<_walletArray.length&&moveIndex!=index){
  80. Map moveItem = _walletArray[moveIndex];
  81. int itemSort = item['sort'];
  82. int moveSort = moveItem['sort'];
  83. YSSqflite sq = YSSqflite().init();
  84. sq.rawUpdate(YSWalletDbData(moveItem['name'],moveItem['password'] , moveItem['word'], moveItem['private'],
  85. moveItem['public'],moveItem['chooseType']), itemSort, '${moveItem['id']}');
  86. sq.rawUpdate(YSWalletDbData(item['name'],item['password'] , item['word'], item['private'],
  87. item['public'],item['chooseType']), moveSort, '${item['id']}');
  88. List array2 = await sq.rawQuery();
  89. if(!mounted)return;
  90. YSSqflite.notifier(context, array2);
  91. }
  92. },
  93. feedback: YSWalletManagerListItemView(item: item,isDetail: true),
  94. child: YSWalletManagerListItemView(item: item,isDetail: true,),
  95. ):GestureDetector(
  96. onTap: () async{
  97. if(widget.isChoose){
  98. Navigator.of(context).pop(item);
  99. }else{
  100. YSSqflite sq = YSSqflite().init();
  101. List array = await sq.rawQuery();
  102. Map chooseItem = array.firstWhere((element) => element['chooseType']==1,orElse: ()=>{});
  103. if(chooseItem.isNotEmpty){
  104. sq.rawUpdate(YSWalletDbData(chooseItem['name'],chooseItem['password'] , chooseItem['word'], chooseItem['private'],
  105. chooseItem['public'],0),chooseItem['sort'],'${chooseItem['id']}');
  106. }
  107. sq.rawUpdate(YSWalletDbData(item['name'],item['password'] , item['word'], item['private'], item['public'],1),item['sort'],'${item['id']}');
  108. List array2 = await sq.rawQuery();
  109. if(!mounted)return;
  110. YSData().wallet = item;
  111. YSSqflite.notifier(context, array2);
  112. addToken(context);
  113. Navigator.pop(context);
  114. }
  115. },
  116. behavior: HitTestBehavior.opaque,
  117. child: YSWalletManagerListItemView(item: item,isDetail: true,),
  118. );
  119. },
  120. separatorBuilder: (context,index){
  121. return Container(height: hsp(20),);
  122. },
  123. itemCount: _walletArray.length,
  124. padding: EdgeInsets.only(top: hsp(5),bottom: hsp(10)),
  125. physics: const NeverScrollableScrollPhysics(),
  126. shrinkWrap: true,
  127. );
  128. }
  129. )
  130. ],
  131. ),
  132. ),
  133. );
  134. }
  135. }
  136. class YSWalletManager2 extends StatefulWidget {
  137. const YSWalletManager2({Key? key}) : super(key: key);
  138. @override
  139. YSWalletManager2State createState() => YSWalletManager2State();
  140. }
  141. class YSWalletManager2State extends State<YSWalletManager2> {
  142. int _index = 0;
  143. List _walletArray = [];
  144. bool _isDrag = false;
  145. @override
  146. void initState() {
  147. _getWalletData();
  148. super.initState();
  149. }
  150. _getWalletData() async{
  151. YSSqflite sqflite = YSSqflite().init();
  152. String tabName = '${YSData().typeArray[_index]['name']}'.replaceAll('-', '').replaceAll(' ', '');
  153. _walletArray = await sqflite.rawQuery(name: tabName);
  154. if(!mounted)return;
  155. YSSqflite.notifier(context, _walletArray);
  156. }
  157. @override
  158. Widget build(BuildContext context) {
  159. return YSBase(
  160. ysTitle: S.current.QIANBAOGUANLI,
  161. ysRightWidget: GestureDetector(
  162. onTap: (){
  163. _isDrag = !_isDrag;
  164. setState(() {});
  165. },
  166. child: Text(_isDrag?S.current.WANCHENG:S.current.PAIXU),
  167. ),
  168. ysChild: SizedBox(
  169. width: ysWidth(context),
  170. height: ysHeight(context)-ysTOP(context)-60,
  171. child: Row(
  172. children: [
  173. Container(
  174. color: const Color(0xFFF1F3F7),
  175. height: ysHeight(context)-ysTOP(context)-60,
  176. width: hsp(60),
  177. child: ListView.builder(
  178. itemBuilder: (context,index){
  179. Map item = YSData().typeArray[index];
  180. // LogUtil.d(item);
  181. return GestureDetector(
  182. onTap: (){
  183. _index = index;
  184. _getWalletData();
  185. setState(() {});
  186. },
  187. child: Container(
  188. color: _index==index?Colors.white:Colors.transparent,
  189. padding: EdgeInsets.only(left: hsp(15),right: hsp(15),bottom: hsp(15),top: hsp(15)),
  190. child: YSImage.network(item['icon'],height: hsp(30),width: hsp(30),),
  191. ),
  192. );
  193. },
  194. itemCount: YSData().typeArray.length,
  195. padding: const EdgeInsets.all(0),
  196. ),
  197. ),
  198. Container(
  199. color: Colors.white,
  200. width: ysWidth(context)-hsp(60),
  201. child: Consumer(
  202. builder: (context,YSWalletNotifier value,child) {
  203. _walletArray = value.walletArray;
  204. return ListView.builder(
  205. itemBuilder: (context,index){
  206. Map item = _walletArray[index];
  207. return _isDrag==true?LongPressDraggable(
  208. onDragEnd: (DraggableDetails detail) async{
  209. int moveIndex = (detail.offset.dy-ysTOP(context)-60)~/hsp(70);
  210. String tabName = '${YSData().typeArray[_index]['name']}'.replaceAll('-', '').replaceAll(' ', '');
  211. if(moveIndex<_walletArray.length&&moveIndex!=index){
  212. Map moveItem = _walletArray[moveIndex];
  213. int itemSort = item['sort'];
  214. int moveSort = moveItem['sort'];
  215. YSSqflite sq = YSSqflite().init(name: tabName);
  216. LogUtil.d('$moveItem======$itemSort $item======$moveSort');
  217. sq.rawUpdate(YSWalletDbData(moveItem['name'],moveItem['password'] , moveItem['word'], moveItem['private'],
  218. moveItem['public'],moveItem['chooseType']), itemSort, '${moveItem['id']}',name: tabName);
  219. sq.rawUpdate(YSWalletDbData(item['name'],item['password'] , item['word'], item['private'],
  220. item['public'],item['chooseType']), moveSort, '${item['id']}',name: tabName);
  221. List array2 = await sq.rawQuery(name: tabName);
  222. LogUtil.d('$array2');
  223. if(!mounted)return;
  224. YSSqflite.notifier(context, array2);
  225. }
  226. },
  227. feedback: Padding(
  228. padding: EdgeInsets.only(bottom: hsp(20)),
  229. child: Row(
  230. children: [
  231. Padding(
  232. padding: EdgeInsets.only(right: hsp(10)),
  233. child: YSWalletManagerItem2View(item: item,width: ysWidth(context)-hsp(130)),
  234. ),
  235. Icon(Icons.menu,size: hsp(30),color: Colors.grey.withOpacity(0.5),)
  236. ],
  237. ),
  238. ),
  239. childWhenDragging: Container(height: hsp(90),),
  240. child: Padding(
  241. padding: EdgeInsets.only(bottom: hsp(20)),
  242. child: Row(
  243. children: [
  244. Padding(
  245. padding: EdgeInsets.only(right: hsp(10)),
  246. child: YSWalletManagerItem2View(item: item,width: ysWidth(context)-hsp(130)),
  247. ),
  248. Icon(Icons.menu,size: hsp(30),color: Colors.grey.withOpacity(0.5),)
  249. ],
  250. ),
  251. ),
  252. ):GestureDetector(
  253. onTap: () async{
  254. Navigator.of(context).push(
  255. CupertinoPageRoute(builder: (context){
  256. return YSWalletDetail(wallet: item,);
  257. },)
  258. );
  259. },
  260. behavior: HitTestBehavior.opaque,
  261. child: Padding(
  262. padding: EdgeInsets.only(bottom: hsp(20)),
  263. child: YSWalletManagerItem2View(item: item,width: ysWidth(context)-hsp(90)),
  264. )
  265. );
  266. },
  267. itemCount: _walletArray.length,
  268. padding: EdgeInsets.only(top: hsp(15),bottom: hsp(15),left: hsp(15),right: hsp(15)),
  269. );
  270. }
  271. )
  272. ,
  273. )
  274. ],
  275. ),
  276. ),
  277. );
  278. }
  279. }
  280. class YSWalletManagerItem2View extends StatelessWidget {
  281. final Map item;
  282. final double width;
  283. const YSWalletManagerItem2View({Key? key, required this.item, required this.width}) : super(key: key);
  284. @override
  285. Widget build(BuildContext context) {
  286. return Container(
  287. width: width,
  288. height: hsp(70),
  289. padding: EdgeInsets.all(hsp(10)),
  290. decoration: BoxDecoration(
  291. color: Colors.black,
  292. borderRadius: const BorderRadius.all(Radius.circular(10)),
  293. boxShadow: [
  294. BoxShadow(color: YSColors.shadowColor(context),blurRadius: 5)
  295. ]
  296. ),
  297. child: Row(
  298. children: [
  299. Expanded(child: Padding(
  300. padding: EdgeInsets.only(right: hsp(10),left: hsp(10)),
  301. child: Column(
  302. crossAxisAlignment: CrossAxisAlignment.start,
  303. mainAxisSize: MainAxisSize.min,
  304. children: [
  305. Row(
  306. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  307. children: [
  308. RichText(text: TextSpan(
  309. text: '${item['name']}',
  310. style: YSColors.contentStyle(context),
  311. children: [
  312. WidgetSpan(child: YSTagView(wallet: item,),alignment: PlaceholderAlignment.middle)
  313. ]
  314. )),
  315. if(item['chooseType']==1)Icon(Icons.check_circle,size: hsp(20),color: YSColors.iconColor(context),)
  316. ],
  317. ),
  318. Padding(
  319. padding: EdgeInsets.only(top: hsp(5)),
  320. child: Row(
  321. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  322. children: [
  323. Row(
  324. children: [
  325. Container(
  326. constraints: BoxConstraints(
  327. maxWidth: ysWidth(context)/2
  328. ),
  329. child: Text(ysTextCut(item['public']),style: YSColors.subStyle(context),maxLines: 1,),
  330. ),
  331. GestureDetector(
  332. onTap: (){
  333. YSCopyPaste.copy(item['public']);
  334. },
  335. child: Image.asset(YSColors.imageStyle(context, '复制'),height: hsp(15),width: hsp(15),),
  336. )
  337. ],
  338. ),
  339. // Text('10.1 Layer3',style: TextStyle(fontSize: zsp(8),color: const Color(0xFF3D5AFF)),),
  340. ],
  341. ),
  342. )
  343. ],
  344. ),
  345. )),
  346. ],
  347. ),
  348. );
  349. }
  350. }