AddressCard.dart 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. Row(
  57. children: [
  58. if (item.isDefault == true)
  59. Container(
  60. margin: EdgeInsets.fromLTRB(0, 0, 5.w, 0),
  61. padding: EdgeInsets.symmetric(vertical: 1.w, horizontal: 5.w),
  62. decoration: BoxDecoration(
  63. color: const Color(0xffff0000),
  64. borderRadius: BorderRadius.all(Radius.circular(5.w)),
  65. ),
  66. child: Text(
  67. '默认地址',
  68. style: TextStyle(
  69. fontSize: 15.sp,
  70. fontWeight: FontWeight.bold,
  71. color: const Color(0xffffffff),
  72. ),
  73. ),
  74. ),
  75. Text(
  76. '我的地址' + No.toString(),
  77. style: TextStyle(fontSize: 15.sp, fontWeight: FontWeight.w700),
  78. ),
  79. ],
  80. ),
  81. GestureDetector(
  82. onTap: onEdit,
  83. child: Container(
  84. padding: EdgeInsets.symmetric(vertical: 5.h, horizontal: 0),
  85. decoration: BoxDecoration(
  86. border: Border(
  87. bottom: BorderSide(
  88. width: 1.h,
  89. color: const Color(0xcc000000),
  90. style: BorderStyle.solid),
  91. ),
  92. ),
  93. child: Row(
  94. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  95. children: [
  96. Container(
  97. padding: EdgeInsets.symmetric(vertical: 5.w, horizontal: 0),
  98. width: 282.w,
  99. child: Text(
  100. item.address.toString(),
  101. //最多显示两行
  102. maxLines: 2,
  103. //多余文本用点点点表示
  104. overflow: TextOverflow.ellipsis,
  105. style: TextStyle(
  106. fontSize: 15.sp,
  107. color: const Color(0xff666666),
  108. ),
  109. ),
  110. ),
  111. Image.asset(
  112. 'images/icons/edit.png',
  113. width: 33.w,
  114. height: 33.w,
  115. ),
  116. ],
  117. ),
  118. ),
  119. ),
  120. if (isBack)
  121. GestureDetector(
  122. onTap: onBack,
  123. child: Container(
  124. width: 315.w,
  125. margin: EdgeInsets.fromLTRB(0, 5.w, 0, 0),
  126. child: Text(
  127. '选择此地址',
  128. style:
  129. TextStyle(fontSize: 17.sp, fontWeight: FontWeight.w800),
  130. ),
  131. ),
  132. ),
  133. if (!isBack)
  134. Row(
  135. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  136. children: [
  137. GestureDetector(
  138. onTap: onChange,
  139. child: Row(
  140. children: [
  141. const Text('设为默认地址'),
  142. Radio<bool>(
  143. value: true,
  144. activeColor: const Color(0xFFFF703B),
  145. groupValue: item.isDefault,
  146. onChanged: (value) {
  147. onChange();
  148. }),
  149. ],
  150. ),
  151. ),
  152. GestureDetector(
  153. onTap: onDelete,
  154. child: Row(
  155. children: [
  156. const Text('删除'),
  157. Image.asset(
  158. 'images/icons/delete.png',
  159. width: 25.w,
  160. height: 25.w,
  161. ),
  162. ],
  163. ),
  164. ),
  165. ],
  166. ),
  167. ],
  168. ),
  169. );
  170. }
  171. }