import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:medcify/models/order_item.dart'; import 'package:medcify/models/pincode_item.dart'; import 'package:medcify/network/api_provider.dart'; import '../../../components/alert.dart'; import '../../../constants.dart'; import '../../../helpers.dart'; import '../../../models/banner_item.dart'; import '../../../models/medicine_item.dart'; import '../../../navigation/navigation.dart'; abstract class DeliveringPincodesState{} class DeliveringPincodesInitial extends DeliveringPincodesState{} class DeliveringPincodesLoading extends DeliveringPincodesState{} class DeliveringPincodesSuccess extends DeliveringPincodesState{} class DeliveringPincodesFailure extends DeliveringPincodesState{ String error; DeliveringPincodesFailure(this.error); } class DeliveringPincodesCubit extends Cubit { DeliveringPincodesCubit() : super(DeliveringPincodesInitial()); List pincodes = []; Future fetchPincodes() async{ emit(DeliveringPincodesLoading()); final response = await ApiProvider.instance.fetchPincodes(); if(response.status ?? false){ pincodes = response.pincodes ?? []; emit(DeliveringPincodesSuccess()); }else{ emit(DeliveringPincodesFailure(response.message ?? "Something went wrong")); } } Future deletePincode(String id) async{ var isNetworkConnection = await Helpers.isNetwork(); if(isNetworkConnection){ Navigation.instance.navigate("/loading"); final response = await ApiProvider.instance.deletePincode(id); Navigation.instance.goBack(); if(response.status ?? false){ fetchPincodes(); }else{ showAlert(response.message ?? "Something went wrong"); } }else{ showAlert(Constants.noInternet); } } Future editPincode(PincodeItem pincode) async{ final response = await Navigation.instance.navigate("/editPincode",args: pincode); if(response != null){ fetchPincodes(); } } void showAlert(String msg){ AlertX.instance.showAlert( title: "Error", msg: msg, positiveButtonText: "Done", positiveButtonPressed: (){ Navigation.instance.goBack(); } ); } }