CarsCard.dart 7.5KB

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