import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:fluttertoast/fluttertoast.dart'; import 'package:medcify/network/api_provider.dart'; import '../../../../components/alert.dart'; import '../../../../navigation/navigation.dart'; abstract class AddPincodeState{} class AddPincodeInitial extends AddPincodeState{} class AddPincodeCubit extends Cubit { AddPincodeCubit() : super(AddPincodeInitial()); TextEditingController pincodeController = TextEditingController(); TextEditingController deliveryFeeController = TextEditingController(); TextEditingController freeAboveController = TextEditingController(); Future addPincode() async{ if(pincodeController.text.isEmpty){ showToast("Enter pincode"); }else if(deliveryFeeController.text.isEmpty){ showToast("Enter delivery fee"); }else if(freeAboveController.text.isEmpty){ showToast("Enter free above"); }else{ Navigation.instance.navigate("/loading"); final response = await ApiProvider.instance.addPincode(pincodeController.text,deliveryFeeController.text,freeAboveController.text); Navigation.instance.goBack(); if(response.status ?? false){ BuildContext? context = Navigation.instance.navigatorKey.currentContext; if(context != null){ Navigator.pop(context,true); } showToast("Pincode added successfully"); }else{ showAlert(response.message ?? "Something went wrong"); } } } void showToast(String msg) { Fluttertoast.showToast( msg: msg, toastLength: Toast.LENGTH_SHORT, gravity: ToastGravity.BOTTOM, timeInSecForIosWeb: 1, backgroundColor: Colors.grey.shade200, textColor: Colors.black, fontSize: 14.0 ); } void showAlert(String err){ AlertX.instance.showAlert( title: "Error", msg: err, positiveButtonText: "Done", positiveButtonPressed: (){ Navigation.instance.goBack(); } ); } }