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 createState() => _UpiPageState(); } class _UpiPageState extends State { bool isLoading = false; TextEditingController upiController = TextEditingController(); Future 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 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(); } ), ], ), ), ), ); } }