import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; import '../models/entities/CardListModel.dart'; import '../pages/machinery/detail/index.dart'; import 'LinearGradientText.dart'; class CarsCard extends StatefulWidget { final CardListModel item; const CarsCard({Key? key, required this.item}) : super(key: key); @override _CarsCardPage createState() => _CarsCardPage(); } class _CarsCardPage extends State { // final CardListModel item; // _CarsCardPage(this.item); setMorKm() { String n = ''; if (widget.item.distance != null) { if ((widget.item.distance ?? 0) >= 1000) { n = ((widget.item.distance ?? 0) / 1000).toStringAsFixed(2).toString() + '公里'; } else { n = widget.item.distance.toString() + '米'; } } else { n = '0m'; } return n; } @override Widget build(BuildContext context) { // print(widget.item); return Container( margin: EdgeInsets.fromLTRB(0, 20, 0, 20), decoration: BoxDecoration( color: Color(0xfff2f2f2), ), width: 345.w, // height: 389.h, child: Column( children: [ GestureDetector( onTap: () { Get.to(MachineryDetailPage(), arguments: { 'id': widget.item.machineryId, 'km': setMorKm().toString() }); }, child: Image.network( widget.item.thumb ?? 'https://dz-machinery.oss-cn-nanjing.aliyuncs.com/images/no_image.png', width: 345.w, height: 230.h, fit: BoxFit.cover, ), ), Container( padding: EdgeInsets.fromLTRB(15, 20, 0, 0), child: Row( crossAxisAlignment: CrossAxisAlignment.start, verticalDirection: VerticalDirection.up, children: [ Container( width: 210.w, child: Text( widget.item.name ?? '', softWrap: true, textAlign: TextAlign.left, overflow: TextOverflow.ellipsis, style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold), ), ), ], ), ), Container( padding: const EdgeInsets.fromLTRB(19, 0, 0, 0), child: Row( crossAxisAlignment: CrossAxisAlignment.start, verticalDirection: VerticalDirection.up, mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Container( child: LinearGradientText( colors: const [ Color(0xFFFA7878), Color(0xFFB61515), ], child: RichText( text: TextSpan(children: [ TextSpan( text: ((widget.item.price ?? 0) / 100).toString(), style: TextStyle( fontSize: 22, fontWeight: FontWeight.bold, )), TextSpan( text: "元/", style: TextStyle( fontSize: 22, fontWeight: FontWeight.bold, )), TextSpan( text: "亩", style: TextStyle( fontSize: 12, fontWeight: FontWeight.bold, )), ]), ), ), ), Align( widthFactor: 1.2, heightFactor: 1.2, alignment: Alignment(1.2, -5), child: Container( margin: EdgeInsets.only(right: 13), width: 86.w, //+6 height: 44.h, //+10 child: ElevatedButton( onPressed: () { Get.toNamed('/orderConfirmation', arguments: {'id': widget.item.machineryId}); }, child: const Text( "预约", style: TextStyle( fontSize: 19, color: Colors.white, fontWeight: FontWeight.bold), ), style: ButtonStyle( backgroundColor: MaterialStateProperty.all(const Color(0xFFFF703B)), shape: MaterialStateProperty.all( const RoundedRectangleBorder( //这个0像素圆角style如果删掉的话,按钮会变成默认样式,自带圆角 borderRadius: BorderRadius.all(Radius.circular(0)))), ), ), ), ), ], ), ), // 地址信息 进入地图 Container( padding: EdgeInsets.fromLTRB(19, 20, 0, 10), child: Row( children: [ Image.asset( "images/gpsImgae.png", width: 11.w, height: 13.h, fit: BoxFit.cover, ), Container( padding: EdgeInsets.fromLTRB(5, 0, 0, 0), width: 300.w, child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Container( child: Row( children: [ Text( '距离当前位置', style: TextStyle( fontSize: 15, fontWeight: FontWeight.bold), ), Text( setMorKm().toString(), style: TextStyle( fontSize: 15, fontWeight: FontWeight.bold), ), ], ), ), GestureDetector( child: Text( '进入地图 >>', style: TextStyle( fontSize: 15, fontWeight: FontWeight.bold), ), onTap: () { print('进入地图'); Get.toNamed('/machineryMap', arguments: { 'id': widget.item.machineryId, 'km': setMorKm().toString() }); }, ) ], )), ], )), ], ), ); } }