332 lines
14 KiB
Dart
332 lines
14 KiB
Dart
import 'package:cached_network_image/cached_network_image.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:medcify/components/loader.dart';
|
|
import 'package:medcify/constants.dart';
|
|
import 'package:medcify/navigation/navigation.dart';
|
|
import 'package:medcify/pages/main/settings/settings_bloc.dart';
|
|
import 'package:url_launcher/url_launcher.dart';
|
|
|
|
import '../../../helpers.dart';
|
|
|
|
class SettingsPage extends StatelessWidget {
|
|
const SettingsPage({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: Colors.white,
|
|
appBar: AppBar(
|
|
backgroundColor: Colors.white,
|
|
elevation: 0.25,
|
|
automaticallyImplyLeading: false,
|
|
title: const Text("Settings",style: TextStyle(color: Colors.black,fontSize: 17),),
|
|
),
|
|
body: BlocProvider<SettingsCubit>(
|
|
create: (context) => SettingsCubit(),
|
|
child: SettingsWidget(),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class SettingsWidget extends StatelessWidget {
|
|
late SettingsCubit settingsCubit;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
settingsCubit = BlocProvider.of<SettingsCubit>(context);
|
|
settingsCubit.fetchMyStore();
|
|
return BlocBuilder<SettingsCubit, SettingsState>(
|
|
builder: (context, state) {
|
|
if(state is SettingsLoading){
|
|
return const Loader();
|
|
}else if(state is SettingsFailure){
|
|
return Container(
|
|
alignment: Alignment.center,
|
|
margin: const EdgeInsets.symmetric(horizontal: 24),
|
|
child: Text(state.error,style: TextStyle(color: Colors.grey.shade800, fontSize: 13, height: 1.6),),
|
|
);
|
|
}
|
|
return SingleChildScrollView(
|
|
padding: const EdgeInsets.all(16),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
const Text("Pharmacy Status",style: TextStyle(color: Colors.black,fontSize: 14,fontWeight: FontWeight.w500),),
|
|
const SizedBox(height: 4,),
|
|
Text((settingsCubit.pharmacyStatus) ? "You are currently online" : "You are currently offline",style: TextStyle(color: (settingsCubit.pharmacyStatus) ? Constants.primaryColor : Colors.red,fontSize: 12),)
|
|
],
|
|
),
|
|
),
|
|
CupertinoSwitch(
|
|
value: settingsCubit.pharmacyStatus,
|
|
onChanged: settingsCubit.changePharmacyStatus,
|
|
activeColor: Constants.primaryColor,
|
|
),
|
|
],
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 16.0),
|
|
child: Divider(height: 1,color: Colors.grey.shade300,),
|
|
),
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: const [
|
|
Text("Return Policy",style: TextStyle(color: Colors.black,fontSize: 14,fontWeight: FontWeight.w500),),
|
|
SizedBox(height: 4,),
|
|
Text("Add/Edit return policy for your store",style: TextStyle(color: Constants.primaryColor,fontSize: 12),)
|
|
],
|
|
),
|
|
),
|
|
MaterialButton(
|
|
onPressed: () async{
|
|
final response = await Navigation.instance.navigate("/returnPolicy",args: settingsCubit.returnPolicy);
|
|
settingsCubit.fetchMyStore();
|
|
},
|
|
elevation: 0,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(30),
|
|
side: const BorderSide(color: Constants.primaryColor)
|
|
),
|
|
child: const Text("Add Policy",style: TextStyle(color: Colors.black,fontSize: 13, fontWeight: FontWeight.w500),),
|
|
)
|
|
],
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 16.0),
|
|
child: Divider(height: 1,color: Colors.grey.shade300,),
|
|
),
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
const Text("Pickup",style: TextStyle(color: Colors.black,fontSize: 14,fontWeight: FontWeight.w500),),
|
|
const SizedBox(height: 4,),
|
|
Text((settingsCubit.pickup) ? "Pickup Enabled" : "Pickup Disabled",style: TextStyle(color: (settingsCubit.pickup) ? Constants.primaryColor : Colors.red,fontSize: 12),)
|
|
],
|
|
),
|
|
),
|
|
CupertinoSwitch(
|
|
value: settingsCubit.pickup,
|
|
onChanged: settingsCubit.changePickup,
|
|
activeColor: Constants.primaryColor,
|
|
),
|
|
],
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 16.0),
|
|
child: Divider(height: 1,color: Colors.grey.shade300,),
|
|
),
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
const Text("Cash On Delivery",style: TextStyle(color: Colors.black,fontSize: 14,fontWeight: FontWeight.w500),),
|
|
const SizedBox(height: 4,),
|
|
Text((settingsCubit.codEnabled) ? "COD Enabled" : "COD Disabled",style: TextStyle(color: (settingsCubit.codEnabled) ? Constants.primaryColor : Colors.red,fontSize: 12),)
|
|
],
|
|
),
|
|
),
|
|
CupertinoSwitch(
|
|
value: settingsCubit.codEnabled,
|
|
onChanged: settingsCubit.changeCodStatus,
|
|
activeColor: Constants.primaryColor,
|
|
),
|
|
],
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 16.0),
|
|
child: Divider(height: 1,color: Colors.grey.shade300,),
|
|
),
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
const Text("Prescription",style: TextStyle(color: Colors.black,fontSize: 14,fontWeight: FontWeight.w500),),
|
|
const SizedBox(height: 4,),
|
|
Text((settingsCubit.prescriptionEnabled) ? "Prescription Enabled" : "Prescription Disabled",style: TextStyle(color: (settingsCubit.prescriptionEnabled) ? Constants.primaryColor : Colors.red,fontSize: 12),)
|
|
],
|
|
),
|
|
),
|
|
CupertinoSwitch(
|
|
value: settingsCubit.prescriptionEnabled,
|
|
onChanged: settingsCubit.changePrescriptionStatus,
|
|
activeColor: Constants.primaryColor,
|
|
),
|
|
],
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 16.0),
|
|
child: Divider(height: 1,color: Colors.grey.shade300,),
|
|
),
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
const Text("Store-Wide Discount",style: TextStyle(color: Colors.black,fontSize: 14,fontWeight: FontWeight.w500),),
|
|
const SizedBox(height: 4,),
|
|
Text((settingsCubit.discountEnabled) ? "${settingsCubit.wideDiscount}% Discount - Enabled" : "Discount Disabled",style: TextStyle(color: (settingsCubit.discountEnabled) ? Constants.primaryColor : Colors.red,fontSize: 12),)
|
|
],
|
|
),
|
|
),
|
|
Visibility(
|
|
visible: settingsCubit.discountEnabled,
|
|
child: MaterialButton(
|
|
onPressed: () async{
|
|
final response = await Navigation.instance.navigate("/wideDiscount",args: settingsCubit.wideDiscount);
|
|
settingsCubit.fetchMyStore();
|
|
},
|
|
elevation: 0,
|
|
minWidth: 40,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(30),
|
|
side: const BorderSide(color: Constants.primaryColor)
|
|
),
|
|
child: const Text("Edit",style: TextStyle(color: Colors.black,fontSize: 13, fontWeight: FontWeight.w500),),
|
|
),
|
|
),
|
|
const SizedBox(width: 8,),
|
|
CupertinoSwitch(
|
|
value: settingsCubit.discountEnabled,
|
|
onChanged: settingsCubit.changeDiscountStatus,
|
|
activeColor: Constants.primaryColor,
|
|
),
|
|
],
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 16.0),
|
|
child: Divider(height: 1,color: Colors.grey.shade300,),
|
|
),
|
|
Row(
|
|
children: [
|
|
const Text("Store Image",style: TextStyle(color: Colors.black,fontSize: 14,fontWeight: FontWeight.w500),),
|
|
const Spacer(),
|
|
MaterialButton(
|
|
onPressed: () async{
|
|
Helpers.showPhotoSelectionDialog(settingsCubit.getStoreImage);
|
|
},
|
|
elevation: 0,
|
|
minWidth: 40,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(30),
|
|
side: const BorderSide(color: Constants.primaryColor)
|
|
),
|
|
child: const Text("Change",style: TextStyle(color: Colors.black,fontSize: 13, fontWeight: FontWeight.w500),),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 16,),
|
|
ClipRRect(
|
|
borderRadius: BorderRadius.circular(4),
|
|
child: CachedNetworkImage(
|
|
imageUrl: settingsCubit.image ?? "",
|
|
fit: BoxFit.cover,
|
|
height: 150,
|
|
width: 150,
|
|
),
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 16.0),
|
|
child: Divider(height: 1,color: Colors.grey.shade300,),
|
|
),
|
|
Row(
|
|
children: [
|
|
const Text("Document Image",style: TextStyle(color: Colors.black,fontSize: 14,fontWeight: FontWeight.w500),),
|
|
const Spacer(),
|
|
MaterialButton(
|
|
onPressed: () async{
|
|
Helpers.showPhotoSelectionDialog(settingsCubit.getDocumentImage);
|
|
},
|
|
elevation: 0,
|
|
minWidth: 40,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(30),
|
|
side: const BorderSide(color: Constants.primaryColor)
|
|
),
|
|
child: const Text("Change",style: TextStyle(color: Colors.black,fontSize: 13, fontWeight: FontWeight.w500),),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 16,),
|
|
ClipRRect(
|
|
borderRadius: BorderRadius.circular(4),
|
|
child: CachedNetworkImage(
|
|
imageUrl: settingsCubit.document ?? "",
|
|
fit: BoxFit.cover,
|
|
height: 150,
|
|
width: 150,
|
|
),
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 16.0),
|
|
child: Divider(height: 1,color: Colors.grey.shade300,),
|
|
),
|
|
GestureDetector(
|
|
behavior: HitTestBehavior.opaque,
|
|
onTap: () async{
|
|
await launch("https://www.medcify.com/terms.php");
|
|
},
|
|
child: Row(
|
|
children: const [
|
|
Text("Terms and Conditions",style: TextStyle(color: Colors.black,fontSize: 14,fontWeight: FontWeight.w500),),
|
|
Spacer(),
|
|
Icon(Icons.arrow_forward_ios,color: Colors.grey,size: 16,),
|
|
],
|
|
),
|
|
),
|
|
const SizedBox(height: 30,),
|
|
GestureDetector(
|
|
behavior: HitTestBehavior.opaque,
|
|
onTap: () async{
|
|
await launch("https://www.medcify.com/privacy.php");
|
|
},
|
|
child: Row(
|
|
children: const [
|
|
Text("Privacy Policy",style: TextStyle(color: Colors.black,fontSize: 14,fontWeight: FontWeight.w500),),
|
|
Spacer(),
|
|
Icon(Icons.arrow_forward_ios,color: Colors.grey,size: 16,),
|
|
],
|
|
),
|
|
),
|
|
const SizedBox(height: 30,),
|
|
GestureDetector(
|
|
behavior: HitTestBehavior.opaque,
|
|
onTap: () async{
|
|
await launch("https://www.medcify.com/refundpolicy.php");
|
|
},
|
|
child: Row(
|
|
children: const [
|
|
Text("Refund Policy",style: TextStyle(color: Colors.black,fontSize: 14,fontWeight: FontWeight.w500),),
|
|
Spacer(),
|
|
Icon(Icons.arrow_forward_ios,color: Colors.grey,size: 16,),
|
|
],
|
|
),
|
|
),
|
|
const SizedBox(height: 30,),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
);
|
|
}
|
|
}
|