import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:get/get_core/src/get_main.dart';

import '../models/entities/CardInfo.dart';
import '../models/entities/CardListModel.dart';
import '../pages/OrderConfirmation/index.dart';
import '../pages/machinery/detail/index.dart';
import '../pages/machinery/map/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(item);
}

class _CarsCardPage extends State<CarsCard> {
  final CardListModel item;
  _CarsCardPage(this.item);

  @override
  Widget build(BuildContext context) {
    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':item.machineryId});
            },
            child: Image.network(
              item.thumb.toString(),
              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: <Widget>[
                Container(
                  width: 210.w,
                  child: Text(
                    item.name.toString(),
                    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: <Widget>[
                Container(
                  child: LinearGradientText(
                    colors: const <Color>[
                      Color(0xFFFA7878),
                      Color(0xFFB61515),
                    ],
                    child: RichText(
                      text: TextSpan(children: <InlineSpan>[
                        TextSpan(
                            text: (item.price! / 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: {'machineryId': 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: [
                          Text(
                            '距离当前位置2.6公里',
                            style: TextStyle(
                                fontSize: 15, fontWeight: FontWeight.bold),
                          ),
                          GestureDetector(
                            child: Text(
                              '进入地图 >>',
                              style: TextStyle(
                                  fontSize: 15, fontWeight: FontWeight.bold),
                            ),
                            onTap: () {
                              print('进入地图');
                              Get.toNamed('/machineryMap',
                                  arguments: {'machineryId': item.machineryId});
                            },
                          )
                        ],
                      )),
                ],
              )),
        ],
      ),
    );
  }
}