YSAlwayAddress.dart 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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/setting/YSAlwayAddressAdd.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. class YSAlwayAddress extends StatefulWidget {
  10. final bool isChoose;
  11. const YSAlwayAddress({Key? key, this.isChoose = false}) : super(key: key);
  12. @override
  13. YSAlwayAddressState createState() => YSAlwayAddressState();
  14. }
  15. class YSAlwayAddressState extends State<YSAlwayAddress> {
  16. List _dataArray = [];
  17. @override
  18. void initState() {
  19. networkDelay((){
  20. _getDataArray();
  21. });
  22. super.initState();
  23. }
  24. _getDataArray() async{
  25. YSAlwayAddressTable table = YSAlwayAddressTable().init();
  26. _dataArray = await table.rawQuery();
  27. setState(() {});
  28. }
  29. @override
  30. Widget build(BuildContext context) {
  31. return YSBase(
  32. ysTitle: S.current.TIANJIACHANGYONGDIZHI,
  33. ysChild: SizedBox(
  34. width: ysWidth(context),
  35. child: Column(
  36. children: [
  37. Container(
  38. height: hsp(45),
  39. color: YSColors.containColor(context),
  40. padding: EdgeInsets.only(left: hsp(15),right: hsp(15)),
  41. child: Row(
  42. children: [
  43. Expanded(child: Text(S.current.QUANBUWANGLUO,style: YSColors.contentStyle(context),)),
  44. GestureDetector(
  45. onTap: (){
  46. Navigator.of(context).push(
  47. CupertinoPageRoute(builder: (context){
  48. return const YSAlwayAddressAdd();
  49. })
  50. ).then((value) {
  51. _getDataArray();
  52. });
  53. },
  54. child: Image.asset(YSColors.imageStyle(context, '添 加'),color: Colors.black,height: hsp(20),width: hsp(20),),
  55. )
  56. ],
  57. ),
  58. ),
  59. SizedBox(
  60. height: ysHeight(context)-ysTOP(context)-hsp(115),
  61. child: _dataArray.isEmpty?Padding(
  62. padding: EdgeInsets.only(top: hsp(150)),
  63. child: Column(
  64. mainAxisSize: MainAxisSize.min,
  65. children: [
  66. Image.asset(YSColors.imageStyle(context, '资源 2'),height: hsp(40),width: hsp(70),),
  67. Padding(
  68. padding: EdgeInsets.only(top: hsp(15)),
  69. child: Text(S.current.NINXIANZAIHAIMEIYOULIANXIREN,style: YSColors.subStyle(context),)
  70. ),
  71. GestureDetector(
  72. onTap: (){
  73. Navigator.of(context).push(
  74. CupertinoPageRoute(builder: (context){
  75. return const YSAlwayAddressAdd();
  76. })
  77. ).then((value) {
  78. _getDataArray();
  79. });
  80. },
  81. behavior: HitTestBehavior.opaque,
  82. child: Container(
  83. margin: EdgeInsets.only(top: hsp(50)),
  84. height: hsp(30),
  85. width: hsp(150),
  86. decoration: BoxDecoration(
  87. color: YSColors.buttonColor(context),
  88. borderRadius: const BorderRadius.all(Radius.circular(5))
  89. ),
  90. alignment: Alignment.center,
  91. child: Text(S.current.XINJIANLIANXIREN,style: YSColors.sub2Style(context),),
  92. ),
  93. )
  94. ],
  95. ),
  96. ):ListView.separated(
  97. itemBuilder: (context,index){
  98. Map item = _dataArray[index];
  99. return Container(
  100. padding: EdgeInsets.only(top: hsp(10),bottom: hsp(10),left: hsp(15),right: hsp(15)),
  101. color: Colors.white,
  102. child: Row(
  103. children: [
  104. YSImage.network(item['icon'],height: hsp(40),width: hsp(40),),
  105. Expanded(child: Padding(
  106. padding: EdgeInsets.only(left: hsp(5),right: hsp(5)),
  107. child: Column(
  108. crossAxisAlignment: CrossAxisAlignment.start,
  109. children: [
  110. Text(item['name'],style: YSColors.contentStyle(context),),
  111. Text(ysTextCut(item['address'],number: 8),style: YSColors.subStyle(context),)
  112. ],
  113. ),
  114. ),),
  115. widget.isChoose?GestureDetector(
  116. onTap: () async{
  117. Navigator.of(context).pop(item);
  118. },
  119. child: Icon(Icons.add_circle_outline,size: hsp(20),color: Colors.black,),
  120. ):Icon(Icons.chevron_right,size: hsp(20),color: YSColors.shadowColor(context),)
  121. ],
  122. ),
  123. );
  124. },
  125. separatorBuilder: (context,index){
  126. return Divider(height: hsp(1),color: YSColors.lineColor(context),);
  127. },
  128. itemCount: _dataArray.length,
  129. padding: const EdgeInsets.all(0),
  130. ),
  131. )
  132. ],
  133. ),
  134. ),
  135. );
  136. }
  137. }