485 lines
20 KiB
Dart
485 lines
20 KiB
Dart
import 'dart:developer';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:flutter_svg/flutter_svg.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
import 'package:traderscircuit/Utils/Common/CommonAppbar.dart';
|
|
import 'package:traderscircuit/Utils/Common/commonBotton.dart';
|
|
import 'package:traderscircuit/Utils/Common/comonGlassmorphicContainer.dart';
|
|
import 'package:traderscircuit/Utils/Common/sized_box.dart';
|
|
import 'package:traderscircuit/Utils/base_manager.dart';
|
|
import 'package:traderscircuit/Utils/text.dart';
|
|
import 'package:traderscircuit/Utils/utils.dart';
|
|
import 'package:traderscircuit/resources/routes/route_name.dart';
|
|
import 'package:traderscircuit/view/onBoarding/splashScreen1.dart';
|
|
import 'package:traderscircuit/view_model/Login/delete_account_api.dart';
|
|
import 'package:traderscircuit/Utils/Dialogs.dart';
|
|
import 'package:traderscircuit/view_model/ProfileAPI/GetProfileApi.dart';
|
|
import 'package:traderscircuit/view_model/SettingApi/setting_api.dart';
|
|
|
|
class Settings extends StatefulWidget {
|
|
const Settings({super.key});
|
|
|
|
@override
|
|
State<Settings> createState() => _SettingsState();
|
|
}
|
|
|
|
class _SettingsState extends State<Settings> {
|
|
late bool isSwitched = false;
|
|
late bool isSwitched1 = false;
|
|
late bool isSwitched2 = false;
|
|
late bool isSwitched3 = false;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
isSwitched = ProfileObj!.data?.alertWhatsAppNotification == 1;
|
|
isSwitched1 = ProfileObj!.data?.alertInAppNotification == 1;
|
|
isSwitched2 = ProfileObj!.data?.alertPushAppNotification == 1;
|
|
isSwitched3 = ProfileObj!.data?.alertSmsAppNotification == 1;
|
|
}
|
|
|
|
Future<void> _verifycheck({
|
|
required int alertWhatsAppNotification,
|
|
required int alertInAppNotification,
|
|
required int alertPushAppNotification,
|
|
required int alertSmsAppNotification,
|
|
}) async {
|
|
Map<String, String> updata = {
|
|
"alert_whats_app_notification": alertWhatsAppNotification.toString(),
|
|
"alert_in_app_notification": alertInAppNotification.toString(),
|
|
"alert_push_app_notification": alertPushAppNotification.toString(),
|
|
"alert_sms_app_notification": alertSmsAppNotification.toString(),
|
|
};
|
|
final resp = await SettingAPI(updata).verifysettingApi();
|
|
if (resp.status == ResponseStatus.SUCCESS) {
|
|
log(resp.data.toString());
|
|
} else if (resp.status == ResponseStatus.PRIVATE) {
|
|
String? message = resp.data['message'];
|
|
Utils.showToast("$message");
|
|
} else if (resp.status == ResponseStatus.ERROR) {
|
|
Get.back();
|
|
String? message = resp.data['message'];
|
|
Utils.showToast("$message");
|
|
} else {
|
|
Get.back();
|
|
String? message = resp.message;
|
|
Utils.showToast(message);
|
|
}
|
|
}
|
|
|
|
void _toggleSwitch(bool value) async {
|
|
setState(() {
|
|
isSwitched = value;
|
|
ProfileObj?.data?.alertWhatsAppNotification = value ? 1 : 0;
|
|
});
|
|
await _verifycheck(
|
|
alertWhatsAppNotification:
|
|
ProfileObj?.data?.alertWhatsAppNotification ?? 0,
|
|
alertInAppNotification: ProfileObj?.data?.alertInAppNotification ?? 0,
|
|
alertPushAppNotification: ProfileObj?.data?.alertPushAppNotification ?? 0,
|
|
alertSmsAppNotification: ProfileObj?.data?.alertSmsAppNotification ?? 0,
|
|
);
|
|
}
|
|
|
|
void _toggleSwitch1(bool value1) async {
|
|
setState(() {
|
|
isSwitched1 = value1;
|
|
ProfileObj?.data?.alertInAppNotification = value1 ? 1 : 0;
|
|
});
|
|
await _verifycheck(
|
|
alertWhatsAppNotification:
|
|
ProfileObj?.data?.alertWhatsAppNotification ?? 0,
|
|
alertInAppNotification: ProfileObj?.data?.alertInAppNotification ?? 0,
|
|
alertPushAppNotification: ProfileObj?.data?.alertPushAppNotification ?? 0,
|
|
alertSmsAppNotification: ProfileObj?.data?.alertSmsAppNotification ?? 0,
|
|
);
|
|
}
|
|
|
|
void _toggleSwitch2(bool value2) async {
|
|
setState(() {
|
|
isSwitched2 = value2;
|
|
ProfileObj?.data?.alertPushAppNotification = value2 ? 1 : 0;
|
|
});
|
|
await _verifycheck(
|
|
alertWhatsAppNotification:
|
|
ProfileObj?.data?.alertWhatsAppNotification ?? 0,
|
|
alertInAppNotification: ProfileObj?.data?.alertInAppNotification ?? 0,
|
|
alertPushAppNotification: ProfileObj?.data?.alertPushAppNotification ?? 0,
|
|
alertSmsAppNotification: ProfileObj?.data?.alertSmsAppNotification ?? 0,
|
|
);
|
|
}
|
|
|
|
void _toggleSwitch3(bool value3) async {
|
|
setState(() {
|
|
isSwitched3 = value3;
|
|
ProfileObj?.data?.alertSmsAppNotification = value3 ? 1 : 0;
|
|
});
|
|
await _verifycheck(
|
|
alertWhatsAppNotification:
|
|
ProfileObj?.data?.alertWhatsAppNotification ?? 0,
|
|
alertInAppNotification: ProfileObj?.data?.alertInAppNotification ?? 0,
|
|
alertPushAppNotification: ProfileObj?.data?.alertPushAppNotification ?? 0,
|
|
alertSmsAppNotification: ProfileObj?.data?.alertSmsAppNotification ?? 0,
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: CommonAppbar(
|
|
titleTxt: "Settings",
|
|
),
|
|
backgroundColor: Colors.black,
|
|
extendBody: true,
|
|
body: Stack(
|
|
children: [
|
|
CommonBlurLeft(),
|
|
CommonBlurRight(),
|
|
Stack(
|
|
children: [
|
|
Padding(
|
|
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 16),
|
|
child: ListView(
|
|
physics: BouncingScrollPhysics(),
|
|
// mainAxisAlignment: MainAxisAlignment.start,
|
|
// crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
// CommonDropdownBtn(hint: "hint", items: ["hi", "hii"]),
|
|
|
|
SizedBox(
|
|
height: 40.h,
|
|
),
|
|
Row(
|
|
children: [
|
|
text18W500("Setup your security"),
|
|
Spacer(),
|
|
Icon(
|
|
Icons.arrow_forward_ios_rounded,
|
|
color: Colors.white,
|
|
size: 24,
|
|
)
|
|
],
|
|
),
|
|
SizedBox(
|
|
height: 50.h,
|
|
),
|
|
text25W600("Notifications"),
|
|
SizedBox(
|
|
height: 30.h,
|
|
),
|
|
Row(
|
|
children: [
|
|
text20W400("WhatsApp Notifications"),
|
|
Spacer(),
|
|
Switch(
|
|
value: isSwitched,
|
|
onChanged: _toggleSwitch,
|
|
activeTrackColor: Colors.green,
|
|
activeColor: Colors.white,
|
|
inactiveTrackColor: Colors.white,
|
|
inactiveThumbColor: Colors.black,
|
|
),
|
|
],
|
|
),
|
|
SizedBox(
|
|
height: 40.h,
|
|
),
|
|
Row(
|
|
children: [
|
|
text20W400("In - App Notifications"),
|
|
Spacer(),
|
|
Switch(
|
|
value: isSwitched1,
|
|
onChanged: _toggleSwitch1,
|
|
activeTrackColor: Colors.green,
|
|
activeColor: Colors.white,
|
|
inactiveTrackColor: Colors.white,
|
|
inactiveThumbColor: Colors.black,
|
|
),
|
|
],
|
|
),
|
|
SizedBox(
|
|
height: 40.h,
|
|
),
|
|
Row(
|
|
children: [
|
|
text20W400("Push Notifications"),
|
|
Spacer(),
|
|
Switch(
|
|
value: isSwitched2,
|
|
onChanged: _toggleSwitch2,
|
|
activeTrackColor: Colors.green,
|
|
activeColor: Colors.white,
|
|
inactiveTrackColor: Colors.white,
|
|
inactiveThumbColor: Colors.black,
|
|
),
|
|
],
|
|
),
|
|
SizedBox(
|
|
height: 40.h,
|
|
),
|
|
Row(
|
|
children: [
|
|
text20W400("E-mail Notifications"),
|
|
Spacer(),
|
|
Switch(
|
|
value: isSwitched3,
|
|
onChanged: _toggleSwitch3,
|
|
activeTrackColor: Colors.green,
|
|
activeColor: Colors.white,
|
|
inactiveTrackColor: Colors.white,
|
|
inactiveThumbColor: Colors.black,
|
|
),
|
|
],
|
|
),
|
|
SizedBox(
|
|
height: 60.h,
|
|
),
|
|
Row(
|
|
children: [
|
|
InkWell(
|
|
child: Image.asset(
|
|
"assets/images/png/Delete.png",
|
|
width: 20,
|
|
height: 22,
|
|
),
|
|
onTap: () {
|
|
Get.bottomSheet(
|
|
commonGlassContainer(
|
|
width: double.infinity,
|
|
height: 363.h,
|
|
borderradius: 4,
|
|
customWidget: Center(
|
|
child: Padding(
|
|
padding:
|
|
EdgeInsets.symmetric(horizontal: 20.w),
|
|
child: Column(
|
|
children: [
|
|
sizedBoxHeight(60.h),
|
|
// Image.asset(
|
|
// 'assets/images/png/Group 1000003722.png',
|
|
// height: 100.h,
|
|
// ),
|
|
// sizedBoxHeight(25.h),
|
|
text22W600('Confirm Delete'),
|
|
sizedBoxHeight(30.h),
|
|
text20W400_center(
|
|
'Are you sure you want to delete your account?'),
|
|
sizedBoxHeight(50.h),
|
|
CommonYesNoBtn(
|
|
yesonTap: () async {
|
|
utils.loader();
|
|
|
|
var resp = await DeleteAccountAPI()
|
|
.deleteAcountApi();
|
|
print(resp.status);
|
|
print('Api msg : ${resp.message}');
|
|
|
|
if (resp.status ==
|
|
ResponseStatus.SUCCESS) {
|
|
Get.back();
|
|
print(
|
|
"api response is ${resp.data}");
|
|
Utils.showToast(
|
|
"Account deleted successfully");
|
|
|
|
Map<String, dynamic> res =
|
|
resp.data;
|
|
print(res);
|
|
|
|
Get.offNamed(
|
|
RouteName.loginscreen,
|
|
);
|
|
} else {
|
|
Get.back();
|
|
Utils.showToast(resp.message);
|
|
print(
|
|
'Api msg : ${resp.message}');
|
|
}
|
|
},
|
|
noonTap: () {
|
|
Get.back();
|
|
},
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
backgroundColor: Colors.black.withOpacity(0.3),
|
|
);
|
|
},
|
|
),
|
|
SizedBox(
|
|
width: 15.w,
|
|
),
|
|
InkWell(
|
|
child: text20W400("Delete Account"),
|
|
onTap: () {
|
|
Get.bottomSheet(
|
|
commonGlassContainer(
|
|
width: double.infinity,
|
|
height: 363.h,
|
|
borderradius: 4,
|
|
customWidget: Center(
|
|
child: Padding(
|
|
padding:
|
|
EdgeInsets.symmetric(horizontal: 20.w),
|
|
child: Column(
|
|
children: [
|
|
sizedBoxHeight(60.h),
|
|
// Image.asset(
|
|
// 'assets/images/png/Group 1000003722.png',
|
|
// height: 100.h,
|
|
// ),
|
|
// sizedBoxHeight(25.h),
|
|
text22W600('Confirm Delete'),
|
|
sizedBoxHeight(30.h),
|
|
text20W400_center(
|
|
'Are you sure you want to delete your account?'),
|
|
sizedBoxHeight(50.h),
|
|
CommonYesNoBtn(
|
|
yesonTap: () async {
|
|
utils.loader();
|
|
|
|
var resp = await DeleteAccountAPI()
|
|
.deleteAcountApi();
|
|
print(resp.status);
|
|
print('Api msg : ${resp.message}');
|
|
|
|
if (resp.status ==
|
|
ResponseStatus.SUCCESS) {
|
|
Get.back();
|
|
print(
|
|
"api response is ${resp.data}");
|
|
Utils.showToast(
|
|
"Account deleted successfully");
|
|
|
|
Map<String, dynamic> res =
|
|
resp.data;
|
|
print(res);
|
|
|
|
Get.offNamed(
|
|
RouteName.loginscreen,
|
|
);
|
|
} else {
|
|
Get.back();
|
|
Utils.showToast(resp.message);
|
|
print(
|
|
'Api msg : ${resp.message}');
|
|
}
|
|
},
|
|
noonTap: () {
|
|
Get.back();
|
|
},
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
backgroundColor: Colors.black.withOpacity(0.3),
|
|
);
|
|
},
|
|
)
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
Deletedialog(context) {
|
|
return showDialog(
|
|
// barrierDismissible: false,
|
|
context: context,
|
|
builder: (context) => Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
AlertDialog(
|
|
insetPadding: EdgeInsets.symmetric(horizontal: 16.w),
|
|
backgroundColor:
|
|
Get.isDarkMode ? Colors.black : const Color(0XFF1B243D),
|
|
contentPadding: EdgeInsets.fromLTRB(29.w, 44.h, 29.w, 35.h),
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.all(Radius.circular(5.r)),
|
|
),
|
|
content: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: [
|
|
Container(
|
|
height: 87.h,
|
|
width: 80.w,
|
|
decoration: const BoxDecoration(
|
|
shape: BoxShape.circle, color: Color(0xFFC18948)),
|
|
child: Align(
|
|
alignment: Alignment.topLeft,
|
|
child: Container(
|
|
height: 79.h,
|
|
width: 73.w,
|
|
decoration: BoxDecoration(
|
|
shape: BoxShape.circle,
|
|
color: const Color(0xFFE8C69F).withOpacity(0.5),
|
|
),
|
|
child: Center(
|
|
child: SvgPicture.asset(
|
|
'assets/images/svg/apps 1.svg',
|
|
// fit: BoxFit.fill,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
sizedBoxHeight(30.h),
|
|
Text(
|
|
"Are you sure you want to logout ?",
|
|
textAlign: TextAlign.center,
|
|
style: TextStyle(
|
|
fontFamily: "hiragino",
|
|
fontWeight: FontWeight.w400,
|
|
fontSize: 20.sp,
|
|
color: const Color(0xFFFFFFFF)),
|
|
),
|
|
sizedBoxHeight(40.h),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
SizedBox(
|
|
width: 140.w,
|
|
child: CommonYesNoBtn(
|
|
yesonTap: () async {
|
|
SharedPreferences prefs =
|
|
await SharedPreferences.getInstance();
|
|
await prefs.clear();
|
|
Get.offNamed(RouteName.loginscreen);
|
|
},
|
|
)),
|
|
SizedBox(
|
|
width: 140.w,
|
|
child: CommonYesNoBtn(
|
|
noonTap: () {
|
|
Get.back();
|
|
},
|
|
),
|
|
),
|
|
],
|
|
)
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|