import 'package:farmer_client/widgets/NullCard.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get_rx/src/rx_types/rx_types.dart';

import '../../../../models/entities/OrderListAll.dart';
import '../../../../services/orderAPI.dart';
import '../../../../widgets/OrderListCard.dart';
import '../../../orderInfo/index.dart';

class OrderPage extends StatefulWidget {
  const OrderPage({Key? key}) : super(key: key);

  @override
  State<OrderPage> createState() => _OrderPageState();
}

class _OrderPageState extends State<OrderPage> {
  final orderListItem = Rx<List<OrderListAll>>([]);

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    getOrderList(true).then((value) {
      final list = <OrderListAll>[];
      setState(() {
        value['records'].forEach((item) {
          list.add(OrderListAll.fromJson(item));

        });
      });
      orderListItem(list);

    });
  }

  @override
  Widget build(BuildContext context) {
    return orderListItem().length>0?
      Column(
      children: [
        Container(
          padding: EdgeInsets.fromLTRB(15, 0, 15, 0),
          height: 55.w,
          decoration: BoxDecoration(color: Colors.white),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Row(
                children: [
                  Padding(
                    padding: EdgeInsets.fromLTRB(0, 0, 8, 0),
                    child: Image(
                      image: AssetImage('images/ordersListImga.png'),
                      fit: BoxFit.cover,
                      width: 18.w,
                    ),
                  ),
                  Text(
                    '订单列表',
                    style: TextStyle(
                        color: Color(0xff222222),
                        fontSize: 20.sp,
                        fontWeight: FontWeight.bold),
                  )
                ],
              ),
            ],
          ),
        ),
        Column(
          mainAxisSize: MainAxisSize.min,
          children:
          orderListItem().map((item) => OrderListCard(item: item)).toList(),
        ),
      ],
    ):NullCard(text: '您还没有新的订单！');
  }
}
