import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:worker_client/models/entities/Machinery.dart';
import 'package:worker_client/services/machinery.dart';
import 'package:worker_client/widgets/layout/BasicPage.dart';

class MachineryMap extends BasicPage {
  MachineryMap({Key? key}) : super(key: key);
  final machineryList = Rx<List<Machinery>>([]);
  final machinery = Rx<Machinery>(Machinery());

  @override
  void beforeShow() {
    super.beforeShow();
    if (Get.arguments != null) {
      getMachineryDetail(Get.arguments['id'], {
        'attached': true,
        'location': '118.84002,31.95266'
      }).then((res) => {machinery(Machinery.fromJson(res))});
    }
  }

  void goBack() {
    Get.back();
  }
  void goDetail() {
    Get.toNamed('/machineryDetail',
        arguments: {'id': machinery.value.machineryId});
  }

  @override
  Widget builder(BuildContext context) {
    naviTitle = '我的农机';
    return Stack(
      children: [
        Container(
          width: 375.w,
          decoration: const BoxDecoration(color: Colors.greenAccent),
        ),
        Positioned(
          bottom: 0,
          child: Container(
            width: 375.w,
            padding: EdgeInsets.symmetric(horizontal: 15.w, vertical: 30.h),
            decoration: BoxDecoration(
                borderRadius: BorderRadius.only(
                    topLeft: Radius.circular(20.w),
                    topRight: Radius.circular(20.w)),
                color: Colors.white),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                GestureDetector(
                  onTap: () {
                    goBack();
                  },
                  child: Text(
                    '<<农机列表',
                    style: TextStyle(
                        color: const Color(0xff666666),
                        fontSize: 15.sp,
                        fontWeight: FontWeight.bold),
                  ),
                ),
                Container(
                  margin: EdgeInsets.only(top: 30.h, bottom: 20.h),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text(
                        '第一台收割机',
                        style: TextStyle(
                            color: const Color(0xff222222),
                            fontSize: 18.sp,
                            fontWeight: FontWeight.bold),
                      ),
                      GestureDetector(
                        onTap: () {
                          goDetail();
                        },
                        child: Text(
                          '详情>>',
                          style: TextStyle(
                              color: const Color(0xff666666),
                              fontSize: 15.sp,
                              fontWeight: FontWeight.bold),
                        ),
                      )
                    ],
                  ),
                ),
                Row(
                  children: [
                    Container(
                      margin: EdgeInsets.only(right: 8.w),
                      child: Image.asset(
                        'images/index/position.png',
                        width: 17.w,
                      ),
                    ),
                    Expanded(
                      flex: 1,
                      child: Text(
                        '当前位置：  江苏省南京市南京南站城际空间站D2栋212南京云致科技服务有限公司',
                        style: TextStyle(
                          fontWeight: FontWeight.bold,
                          fontSize: 15.sp,
                          color: const Color(0xff222222),
                        ),
                      ),
                    )
                  ],
                )
              ],
            ),
          ),
        )
      ],
    );
  }
}
