import 'package:driverapp/core/enum/viewstate.dart';
import 'package:driverapp/core/viewModels/orders_view_model.dart';
import 'package:driverapp/widgets/order/order_info_card.dart';
import 'package:driverapp/widgets/others/app_scaffold_widget.dart';
import 'package:driverapp/widgets/others/network_base_view.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import '../base/base_view.dart';

class DeliverdOrdersPage extends StatefulWidget {
  @override
  _DeliverdOrdersPageState createState() => _DeliverdOrdersPageState();
}

class _DeliverdOrdersPageState extends State<DeliverdOrdersPage> {
  @override
  Widget build(BuildContext context) {
    return BaseView<OrdersViewModel>(
      onModelReady: (model) => model.getDeliveredOrders(),
      builder: (BuildContext context, OrdersViewModel model, Widget child) =>
          AppScaffold(
        isShowAppBar: true,
        appBarTitle: 'Delivered List',
        baseViewModel: model,
        isShowBackIcon: true,
        titleColor: Colors.black,
        body: Column(
          children: <Widget>[
            SizedBox(
              height: 20,
            ),
            if (model.state == ViewState.Idle)
              model.deliverdOrders.length == 0
                  ? Text("There's No Orders To deliver")
                  : SizedBox(),
            NetworkBaseView(
              baseViewModel: model,
              child: Expanded(
                child: ListView.builder(
                  shrinkWrap: true,
                  scrollDirection: Axis.vertical,
                  itemCount: model.deliverdOrders == null
                      ? 0
                      : model.deliverdOrders.length,
                  itemBuilder: (BuildContext context, int index) {
                    return Padding(
                        padding: EdgeInsets.symmetric(horizontal: 12.2),
                        child: OrderInfoCard(
                          order: model.deliverdOrders[index],
                          showStatus: true,
                          onTap: () {},
                        ));
                  },
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
