121 lines
3.2 KiB
Dart
121 lines
3.2 KiB
Dart
|
import 'package:flutter/material.dart';
|
||
|
import 'package:fluttertoast/fluttertoast.dart';
|
||
|
import 'package:medcify/components/button.dart';
|
||
|
import 'package:medcify/components/custom_textfield.dart';
|
||
|
import 'package:medcify/components/loader.dart';
|
||
|
import 'package:medcify/navigation/navigation.dart';
|
||
|
import '../../../components/alert.dart';
|
||
|
import '../../../network/api_provider.dart';
|
||
|
|
||
|
class UpiPage extends StatefulWidget {
|
||
|
@override
|
||
|
State<UpiPage> createState() => _UpiPageState();
|
||
|
}
|
||
|
|
||
|
class _UpiPageState extends State<UpiPage> {
|
||
|
bool isLoading = false;
|
||
|
TextEditingController upiController = TextEditingController();
|
||
|
|
||
|
Future<void> fetchMyStore() async{
|
||
|
setState((){
|
||
|
isLoading = true;
|
||
|
});
|
||
|
final response = await ApiProvider.instance.fetchMyStore();
|
||
|
if(response.status ?? false){
|
||
|
setState((){
|
||
|
isLoading = false;
|
||
|
upiController.text = response.store?.upi ?? "";
|
||
|
});
|
||
|
}else{
|
||
|
setState((){
|
||
|
isLoading = false;
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Future<void> updateUpi() async{
|
||
|
Navigation.instance.navigate("/loading");
|
||
|
final response = await ApiProvider.instance.updateUpi(upiController.text);
|
||
|
Navigation.instance.goBack();
|
||
|
if(response.status ?? false){
|
||
|
showToast("Upi updated");
|
||
|
fetchMyStore();
|
||
|
}else{
|
||
|
showAlert(response.message ?? "Something went wrong");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void showAlert(String err){
|
||
|
AlertX.instance.showAlert(
|
||
|
title: "Error",
|
||
|
msg: err,
|
||
|
positiveButtonText: "Done",
|
||
|
positiveButtonPressed: (){
|
||
|
Navigation.instance.goBack();
|
||
|
}
|
||
|
);
|
||
|
}
|
||
|
|
||
|
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
|
||
|
);
|
||
|
}
|
||
|
|
||
|
@override
|
||
|
initState(){
|
||
|
fetchMyStore();
|
||
|
super.initState();
|
||
|
}
|
||
|
|
||
|
@override
|
||
|
Widget build(BuildContext context) {
|
||
|
return GestureDetector(
|
||
|
behavior: HitTestBehavior.opaque,
|
||
|
onTap: (){
|
||
|
FocusManager.instance.primaryFocus?.unfocus();
|
||
|
},
|
||
|
child: Scaffold(
|
||
|
backgroundColor: Colors.white,
|
||
|
appBar: AppBar(
|
||
|
backgroundColor: Colors.white,
|
||
|
elevation: 0.25,
|
||
|
automaticallyImplyLeading: false,
|
||
|
title: const Text("Upi",style: TextStyle(color: Colors.black,fontSize: 17),),
|
||
|
leading: IconButton(
|
||
|
onPressed: (){
|
||
|
Navigation.instance.goBack();
|
||
|
},
|
||
|
icon: const Icon(Icons.keyboard_backspace_rounded,color: Colors.black,),
|
||
|
),
|
||
|
),
|
||
|
body: (isLoading) ? const Loader() : Padding(
|
||
|
padding: const EdgeInsets.all(20.0),
|
||
|
child: Column(
|
||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||
|
children: [
|
||
|
CustomTextField(
|
||
|
hint: "Enter upi",
|
||
|
controller: upiController,
|
||
|
),
|
||
|
const SizedBox(height: 24,),
|
||
|
Button(
|
||
|
text: "Update",
|
||
|
onPressed: (){
|
||
|
updateUpi();
|
||
|
}
|
||
|
),
|
||
|
],
|
||
|
),
|
||
|
),
|
||
|
),
|
||
|
);
|
||
|
}
|
||
|
}
|