AddressCard.dart 5.9KB

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