Application/medcify/lib/pages/main/settings/wide_discount_page.dart
2022-09-26 12:03:52 +05:30

108 lines
3.1 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:medcify/components/button.dart';
import 'package:medcify/components/custom_textfield.dart';
import 'package:medcify/navigation/navigation.dart';
import '../../../components/alert.dart';
import '../../../network/api_provider.dart';
class WideDiscountPage extends StatefulWidget {
String discount;
WideDiscountPage(this.discount);
@override
State<WideDiscountPage> createState() => _WideDiscountPageState();
}
class _WideDiscountPageState extends State<WideDiscountPage> {
TextEditingController discountController= TextEditingController();
@override
initState(){
discountController.text = widget.discount;
super.initState();
}
Future<void> updateDiscount() async{
Navigation.instance.navigate("/loading");
final response = await ApiProvider.instance.updateWideDiscount(discountController.text);
Navigation.instance.goBack();
if(response.status ?? false){
showToast("Wide discount updated");
}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
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("Wide Discount",style: TextStyle(color: Colors.black,fontSize: 17),),
leading: IconButton(
onPressed: (){
Navigation.instance.goBack();
},
icon: const Icon(Icons.keyboard_backspace_rounded,color: Colors.black,),
),
),
body: Padding(
padding: const EdgeInsets.all(20.0),
child: Column(
children: [
CustomTextField(
hint: "Enter wide discount",
controller: discountController,
keyboardType: TextInputType.number,
inputFormatters: [
FilteringTextInputFormatter.digitsOnly
],
maxLength: 3,
),
const Spacer(),
Button(
text: "Update",
onPressed: (){
updateDiscount();
}
)
],
),
),
),
);
}
}