AddressCard.dart 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. import 'package:farmer_client/models/entities/Address.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter_screenutil/flutter_screenutil.dart';
  4. import 'package:get/get_rx/src/rx_typedefs/rx_typedefs.dart';
  5. class AddressCard extends StatefulWidget {
  6. final Address item;
  7. final int No;
  8. final bool isBack;
  9. final GestureTapCallback onChange;
  10. final GestureTapCallback onDelete;
  11. final GestureTapCallback onEdit;
  12. final GestureTapCallback onBack;
  13. const AddressCard(
  14. {Key? key,
  15. required this.item,
  16. required this.No,
  17. required this.isBack,
  18. required this.onChange,
  19. required this.onDelete,
  20. required this.onEdit,
  21. required this.onBack})
  22. : super(key: key);
  23. @override
  24. _AddressCard createState() =>
  25. _AddressCard(item, No, onChange, onDelete, onEdit, isBack, onBack);
  26. }
  27. class _AddressCard extends State<AddressCard> {
  28. final Address item;
  29. final int No;
  30. final bool isBack;
  31. final GestureTapCallback onChange;
  32. final GestureTapCallback onDelete;
  33. final GestureTapCallback onEdit;
  34. final GestureTapCallback onBack;
  35. _AddressCard(this.item, this.No, this.onChange, this.onDelete, this.onEdit,
  36. this.isBack, this.onBack);
  37. @override
  38. Widget build(BuildContext context) {
  39. return Container(
  40. width: 345.w,
  41. padding: EdgeInsets.all(15.w),
  42. margin: EdgeInsets.fromLTRB(0, 0, 0, 15.w),
  43. decoration: BoxDecoration(
  44. color: const Color(0xFFFFFFFF),
  45. borderRadius: BorderRadius.all(Radius.circular(10.w)),
  46. boxShadow: [
  47. BoxShadow(
  48. color: const Color(0x19000000),
  49. offset: Offset(0, 5.w),
  50. blurRadius: 12.w),
  51. ],
  52. ),
  53. child: Column(
  54. crossAxisAlignment: CrossAxisAlignment.start,
  55. children: [
  56. GestureDetector(
  57. onTap: isBack ? onBack : () {},
  58. child: Row(
  59. children: [
  60. if (item.isDefault == true)
  61. Container(
  62. margin: EdgeInsets.fromLTRB(0, 0, 5.w, 0),
  63. padding:
  64. EdgeInsets.symmetric(vertical: 1.w, horizontal: 5.w),
  65. decoration: BoxDecoration(
  66. color: const Color(0xffff0000),
  67. borderRadius: BorderRadius.all(Radius.circular(5.w)),
  68. ),
  69. child: Text(
  70. '默认地址',
  71. style: TextStyle(
  72. fontSize: 15.sp,
  73. fontWeight: FontWeight.bold,
  74. color: const Color(0xffffffff),
  75. ),
  76. ),
  77. ),
  78. Text(
  79. '我的地址' + No.toString(),
  80. style:
  81. TextStyle(fontSize: 15.sp, fontWeight: FontWeight.w700),
  82. ),
  83. ],
  84. ),
  85. ),
  86. Container(
  87. padding: EdgeInsets.symmetric(vertical: 5.h, horizontal: 0),
  88. decoration: BoxDecoration(
  89. border: Border(
  90. bottom: BorderSide(
  91. width: 1.h,
  92. color: const Color(0xcc000000),
  93. style: BorderStyle.solid),
  94. ),
  95. ),
  96. child: GestureDetector(
  97. onTap: isBack ? onBack : () {},
  98. child: Row(
  99. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  100. children: [
  101. Container(
  102. padding: EdgeInsets.symmetric(vertical: 5.w, horizontal: 0),
  103. width: 282.w,
  104. child: Text(
  105. item.address.toString(),
  106. //最多显示两行
  107. maxLines: 2,
  108. //多余文本用点点点表示
  109. overflow: TextOverflow.ellipsis,
  110. style: TextStyle(
  111. fontSize: 15.sp,
  112. color: const Color(0xff666666),
  113. ),
  114. ),
  115. ),
  116. GestureDetector(
  117. onTap: onEdit,
  118. child: Image.asset(
  119. 'images/icons/edit.png',
  120. width: 33.w,
  121. height: 33.w,
  122. ),
  123. ),
  124. ],
  125. ),
  126. ),
  127. ),
  128. if (isBack)
  129. GestureDetector(
  130. onTap: onBack,
  131. child: Container(
  132. width: 315.w,
  133. margin: EdgeInsets.fromLTRB(0, 5.w, 0, 0),
  134. child: Text(
  135. '选择此地址',
  136. style:
  137. TextStyle(fontSize: 17.sp, fontWeight: FontWeight.w800),
  138. ),
  139. ),
  140. ),
  141. if (!isBack)
  142. Row(
  143. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  144. children: [
  145. GestureDetector(
  146. // onTap: onChange,
  147. child: Row(
  148. children: [
  149. const Text('设为默认地址'),
  150. Radio<bool>(
  151. value: true,
  152. activeColor: const Color(0xFFFF703B),
  153. groupValue: item.isDefault,
  154. onChanged: (value) {
  155. onChange();
  156. }),
  157. ],
  158. ),
  159. ),
  160. GestureDetector(
  161. onTap: onDelete,
  162. child: Row(
  163. children: [
  164. const Text('删除'),
  165. Image.asset(
  166. 'images/icons/delete.png',
  167. width: 25.w,
  168. height: 25.w,
  169. ),
  170. ],
  171. ),
  172. ),
  173. ],
  174. ),
  175. ],
  176. ),
  177. );
  178. }
  179. }
  180. //
  181. // class UseEffect extends ChangeNotifier{//这里也可以使用with来进行实现
  182. // int _count = 0;//数值计算
  183. //
  184. // int get count => _count;
  185. //
  186. // addCount(){
  187. // _count++;
  188. // notifyListeners();
  189. // }
  190. //
  191. // }