CarsCard.dart 7.7KB

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