AddressCard.dart 4.9KB

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