Application/medcify/lib/pages/main/orders/orders_page.dart

99 lines
3.3 KiB
Dart
Raw Normal View History

2022-09-26 06:33:52 +00:00
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:medcify/components/loader.dart';
import 'package:medcify/constants.dart';
import 'package:medcify/models/order_item.dart';
import 'package:medcify/pages/main/orders/orders_bloc.dart';
import 'orders_card.dart';
class OrdersPage extends StatelessWidget {
const OrdersPage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return BlocProvider<OrdersCubit>(
create: (context) => OrdersCubit(),
child: OrdersWidget(),
);
}
}
class OrdersWidget extends StatelessWidget {
late OrdersCubit ordersCubit;
@override
Widget build(BuildContext context) {
ordersCubit = BlocProvider.of<OrdersCubit>(context);
ordersCubit.fetchOrders();
return DefaultTabController(
length: 3,
child: Scaffold(
appBar: AppBar(
backgroundColor: Colors.white,
elevation: 0.25,
automaticallyImplyLeading: false,
title: const Text("Orders",style: TextStyle(color: Colors.black,fontSize: 17),),
bottom: PreferredSize(
preferredSize: const Size.fromHeight(50),
child: Align(
alignment: Alignment.centerLeft,
child: TabBar(
onTap: ordersCubit.onTap,
labelColor: Constants.primaryColor,
unselectedLabelColor: Constants.secondaryTextColor,
indicatorColor: Constants.primaryColor,
isScrollable: true,
tabs: const [
Tab(
text: "Pending",
),
Tab(
text: "Completed",
),
Tab(
text: "Cancelled",
),
],
),
),
),
),
body: BlocBuilder<OrdersCubit, OrdersState>(
builder: (context, state){
if(state is OrdersLoading){
return const Loader();
}else if(state is OrdersFailure){
return Container(
alignment: Alignment.center,
margin: const EdgeInsets.symmetric(horizontal: 24),
child: Text(state.error,style: TextStyle(color: Colors.grey.shade800, fontSize: 13, height: 1.6),),
);
}else{
return (ordersCubit.orders.isEmpty) ? Container(
alignment: Alignment.center,
margin: const EdgeInsets.symmetric(horizontal: 24),
child: Text("No orders found",style: TextStyle(color: Colors.grey.shade800, fontSize: 13),),
) : ListView.builder(
itemCount: ordersCubit.orders.length,
padding: const EdgeInsets.all(16),
physics: const BouncingScrollPhysics(),
itemBuilder: (context, pos){
OrderItem orderItem = ordersCubit.orders[pos];
return OrdersCard(
item: orderItem,
currentIndex: ordersCubit.currentIndex,
acceptOrder: ordersCubit.acceptOrder,
cancelOrder: ordersCubit.cancelOrder,
fetchOrders: ordersCubit.fetchOrders
);
},
);
}
},
),
),
);
}
}