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/pincode_item.dart'; import 'package:medcify/pages/main/deliveryPincodes/pincode_card.dart'; import '../../../navigation/navigation.dart'; import 'delivery_pincodes_bloc.dart'; class DeliveringPincodesPage extends StatelessWidget { const DeliveringPincodesPage({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( backgroundColor: Colors.white, elevation: 0.25, automaticallyImplyLeading: false, leading: IconButton( onPressed: (){ Navigation.instance.goBack(); }, icon: const Icon(Icons.keyboard_backspace_rounded,color: Colors.black,), ), title: const Text("Delivering Pincodes",style: TextStyle(color: Colors.black,fontSize: 17),), ), body: BlocProvider( create: (context) => DeliveringPincodesCubit(), child: ProductWidget(), ), ); } } class ProductWidget extends StatelessWidget { late DeliveringPincodesCubit deliveringPincodesCubit; @override Widget build(BuildContext context) { deliveringPincodesCubit = BlocProvider.of(context); deliveringPincodesCubit.fetchPincodes(); return BlocBuilder( builder: (context, state) { if(state is DeliveringPincodesLoading){ return const Loader(); }else if(state is DeliveringPincodesFailure){ 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 Stack( children: [ (deliveringPincodesCubit.pincodes.isEmpty) ? Container( alignment: Alignment.center, margin: const EdgeInsets.symmetric(horizontal: 24), child: Text("No pincodes found",style: TextStyle(color: Colors.grey.shade800, fontSize: 13),), ) : ListView.builder( itemCount: deliveringPincodesCubit.pincodes.length, padding: const EdgeInsets.only(top: 16,bottom: 80,left: 16,right: 16), physics: const BouncingScrollPhysics(), itemBuilder: (context, pos){ PincodeItem pincode = deliveringPincodesCubit.pincodes[pos]; return PincodeCard(item: pincode,deletePincode: deliveringPincodesCubit.deletePincode, editPincode: deliveringPincodesCubit.editPincode,); }, ), Positioned( bottom: 16, right: 16, child: FloatingActionButton( onPressed: () async{ final response = await Navigation.instance.navigate("/addPincode"); if(response != null){ deliveringPincodesCubit.fetchPincodes(); } }, backgroundColor: Constants.primaryColor, elevation: 0, child: const Icon(Icons.add_rounded,color: Colors.white,), ), ) ], ); } } ); } }