CarsCard.dart 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_screenutil/flutter_screenutil.dart';
  3. import 'package:get/get.dart';
  4. import '../models/entities/CardListModel.dart';
  5. import '../pages/machinery/detail/index.dart';
  6. import 'LinearGradientText.dart';
  7. class CarsCard extends StatefulWidget {
  8. final CardListModel item;
  9. const CarsCard({Key? key, required this.item}) : super(key: key);
  10. @override
  11. _CarsCardPage createState() => _CarsCardPage();
  12. }
  13. class _CarsCardPage extends State<CarsCard> {
  14. // final CardListModel item;
  15. // _CarsCardPage(this.item);
  16. setMorKm() {
  17. String n = '';
  18. if (widget.item.distance != null) {
  19. if ((widget.item.distance ?? 0) >= 1000) {
  20. n = ((widget.item.distance ?? 0) / 1000).toStringAsFixed(2).toString() +
  21. '公里';
  22. } else {
  23. n = widget.item.distance.toString() + '米';
  24. }
  25. } else {
  26. n = '0m';
  27. }
  28. return n;
  29. }
  30. @override
  31. Widget build(BuildContext context) {
  32. print(widget.item);
  33. return Container(
  34. margin: EdgeInsets.fromLTRB(0, 20, 0, 20),
  35. decoration: BoxDecoration(
  36. color: Color(0xfff2f2f2),
  37. ),
  38. width: 345.w,
  39. // height: 389.h,
  40. child: Column(
  41. children: [
  42. GestureDetector(
  43. onTap: () {
  44. Get.to(MachineryDetailPage(), arguments: {
  45. 'id': widget.item.machineryId,
  46. 'km': setMorKm().toString()
  47. });
  48. },
  49. child: Image.network(
  50. widget.item.thumb.toString(),
  51. width: 345.w,
  52. height: 230.h,
  53. fit: BoxFit.cover,
  54. ),
  55. ),
  56. Container(
  57. padding: EdgeInsets.fromLTRB(15, 20, 0, 0),
  58. child: Row(
  59. crossAxisAlignment: CrossAxisAlignment.start,
  60. verticalDirection: VerticalDirection.up,
  61. children: <Widget>[
  62. Container(
  63. width: 210.w,
  64. child: Text(
  65. widget.item.name.toString(),
  66. softWrap: true,
  67. textAlign: TextAlign.left,
  68. overflow: TextOverflow.ellipsis,
  69. style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
  70. ),
  71. ),
  72. ],
  73. ),
  74. ),
  75. Container(
  76. padding: const EdgeInsets.fromLTRB(19, 0, 0, 0),
  77. child: Row(
  78. crossAxisAlignment: CrossAxisAlignment.start,
  79. verticalDirection: VerticalDirection.up,
  80. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  81. children: <Widget>[
  82. Container(
  83. child: LinearGradientText(
  84. colors: const <Color>[
  85. Color(0xFFFA7878),
  86. Color(0xFFB61515),
  87. ],
  88. child: RichText(
  89. text: TextSpan(children: <InlineSpan>[
  90. TextSpan(
  91. text: (widget.item.price! / 100).toString(),
  92. style: TextStyle(
  93. fontSize: 22,
  94. fontWeight: FontWeight.bold,
  95. )),
  96. TextSpan(
  97. text: "元/",
  98. style: TextStyle(
  99. fontSize: 22,
  100. fontWeight: FontWeight.bold,
  101. )),
  102. TextSpan(
  103. text: "亩",
  104. style: TextStyle(
  105. fontSize: 12,
  106. fontWeight: FontWeight.bold,
  107. )),
  108. ]),
  109. ),
  110. ),
  111. ),
  112. Align(
  113. widthFactor: 1.2,
  114. heightFactor: 1.2,
  115. alignment: Alignment(1.2, -5),
  116. child: Container(
  117. margin: EdgeInsets.only(right: 13),
  118. width: 86.w, //+6
  119. height: 44.h, //+10
  120. child: ElevatedButton(
  121. onPressed: () {
  122. Get.toNamed('/orderConfirmation',
  123. arguments: {'id': widget.item.machineryId});
  124. },
  125. child: const Text(
  126. "预约",
  127. style: TextStyle(
  128. fontSize: 19,
  129. color: Colors.white,
  130. fontWeight: FontWeight.bold),
  131. ),
  132. style: ButtonStyle(
  133. backgroundColor:
  134. MaterialStateProperty.all(const Color(0xFFFF703B)),
  135. shape: MaterialStateProperty.all(
  136. const RoundedRectangleBorder(
  137. //这个0像素圆角style如果删掉的话,按钮会变成默认样式,自带圆角
  138. borderRadius:
  139. BorderRadius.all(Radius.circular(0)))),
  140. ),
  141. ),
  142. ),
  143. ),
  144. ],
  145. ),
  146. ),
  147. // 地址信息 进入地图
  148. Container(
  149. padding: EdgeInsets.fromLTRB(19, 20, 0, 10),
  150. child: Row(
  151. children: [
  152. Image.asset(
  153. "images/gpsImgae.png",
  154. width: 11.w,
  155. height: 13.h,
  156. fit: BoxFit.cover,
  157. ),
  158. Container(
  159. padding: EdgeInsets.fromLTRB(5, 0, 0, 0),
  160. width: 300.w,
  161. child: Row(
  162. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  163. children: [
  164. Container(
  165. child: Row(
  166. children: [
  167. Text(
  168. '距离当前位置',
  169. style: TextStyle(
  170. fontSize: 15,
  171. fontWeight: FontWeight.bold),
  172. ),
  173. Text(
  174. setMorKm().toString(),
  175. style: TextStyle(
  176. fontSize: 15,
  177. fontWeight: FontWeight.bold),
  178. ),
  179. ],
  180. ),
  181. ),
  182. GestureDetector(
  183. child: Text(
  184. '进入地图 >>',
  185. style: TextStyle(
  186. fontSize: 15, fontWeight: FontWeight.bold),
  187. ),
  188. onTap: () {
  189. print('进入地图');
  190. Get.toNamed('/machineryMap', arguments: {
  191. 'id': widget.item.machineryId,
  192. 'km': setMorKm().toString()
  193. });
  194. },
  195. )
  196. ],
  197. )),
  198. ],
  199. )),
  200. ],
  201. ),
  202. );
  203. }
  204. }