Files
Traders_Circuit/lib/view/Sidemenu/Sidemenu.dart
Abhishek Raju Garad 57bd55cb50 logout
2024-06-18 11:26:15 +05:30

567 lines
18 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_svg/svg.dart';
import 'package:get/get.dart';
import 'package:shared_preferences/shared_preferences.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/resources/routes/route_name.dart';
import 'package:traderscircuit/view_model/LogoutApi/logout_api.dart';
import 'package:traderscircuit/view_model/ProfileAPI/GetProfileApi.dart';
import 'webview_subscription.dart';
class SideMenu extends StatefulWidget {
const SideMenu({super.key});
@override
State<SideMenu> createState() => _SideMenuState();
}
class _SideMenuState extends State<SideMenu> {
@override
void initState() {
// TODO: implement initState
super.initState();
}
List sideBarData = [
{
"imagePath": "assets/images/svg/sidemenu/Faq.svg",
"text": "FAQs",
},
{
"imagePath": "assets/images/svg/sidemenu/contact.svg",
"text": "Contact Us"
},
{
"imagePath": "assets/images/svg/sidemenu/rate.svg",
"text": "Rate this app"
},
{
"imagePath": "assets/images/svg/sidemenu/terms.svg",
"text": "Terms & Conditions"
},
{
"imagePath": "assets/images/svg/sidemenu/privacy.svg",
"text": "Privacy Policy"
},
{"imagePath": "assets/images/svg/sidemenu/about.svg", "text": "About Us"},
{
"imagePath": "assets/images/svg/sidemenu/settingmenu.svg",
"text": "Settings"
},
{"imagePath": "assets/images/svg/sidemenu/logout.svg", "text": "Logout"},
];
Color sideBarBackgroundColor = const Color(0xFF1B243D);
Color whitecolor = Colors.white;
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.black,
appBar: AppBar(
toolbarHeight: 60.h,
elevation: 0,
backgroundColor: Colors.black,
leading: Container(
child: Align(
alignment: Alignment.bottomCenter,
child: GestureDetector(
onTap: () {
// Get.back();
Scaffold.of(context).closeDrawer();
},
child: Container(
width: 25.w,
height: 25.h,
decoration: const ShapeDecoration(
color: Colors.black,
shape: OvalBorder(),
),
child: Align(
alignment: Alignment.center,
child: SizedBox(
width: 25.w,
height: 25.h,
child: Icon(
Icons.arrow_back_ios,
color: Colors.white,
size: 25.h,
weight: 25.w,
),
),
),
),
),
),
),
),
body: Stack(
children: [
// CommonBlurLeft(),
// CommonBlurRight(),
Stack(children: [
ListView(children: [
sizedBoxHeight(30.h),
InkWell(
onTap: () {
setState(() {
Get.toNamed(RouteName.myProfileScreen);
});
},
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 16.w),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Container(
width: 80.w,
height: 80.h,
decoration: ShapeDecoration(
image: DecorationImage(
image: NetworkImage(ProfileObj == null
? ""
: ProfileObj!.data!.profilePhoto ?? ""),
fit: BoxFit.fill,
),
shape: OvalBorder(),
),
),
sizedBoxWidth(20.w),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
text18W400(ProfileObj!.data!.userName ?? ""),
sizedBoxHeight(4.h),
text18W400('My Profile'),
],
),
],
),
),
),
sizedBoxHeight(25.h),
Container(
height: 1,
margin: EdgeInsets.symmetric(vertical: 10.h),
decoration: const BoxDecoration(
border: Border(
bottom: BorderSide(
color: Color.fromRGBO(176, 176, 176, 0.5),
width: 1,
),
),
),
),
ListTile(
leading:
SvgPicture.asset('assets/images/svg/sidemenu/sub.svg'),
title: text18W400('My Subscription'),
trailing: Container(
height: 35.h,
width: 80.w,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(6.r),
color: const Color(0xFF34C759),
),
child: Center(child: text14W500_black('Upgrade')),
),
selected: true,
onTap: () async {
SharedPreferences prefs =
await SharedPreferences.getInstance();
Get.to(WebViewSubscription(
token: prefs.getString('accessToken').toString()));
},
),
Container(
height: 1,
margin: EdgeInsets.symmetric(vertical: 10.h),
decoration: const BoxDecoration(
border: Border(
bottom: BorderSide(
color: Color.fromRGBO(176, 176, 176, 0.5),
width: 1,
),
),
),
),
ListTile(
leading: SvgPicture.asset(
'assets/images/svg/sidemenu/content.svg'),
title: text18W400('Content bytes'),
selected: true,
onTap: () {
setState(() {
Get.toNamed(RouteName.contentbytes);
});
},
),
Container(
height: 1,
margin: EdgeInsets.symmetric(vertical: 10.h),
decoration: const BoxDecoration(
border: Border(
bottom: BorderSide(
color: Color.fromRGBO(176, 176, 176, 0.5),
width: 1,
),
),
),
),
ListTile(
leading: SizedBox(
width: 25.w,
height: 25.h,
child: SvgPicture.asset(
'assets/images/svg/sidemenu/Gray.svg')),
title: text18W400('Update My KYC'),
trailing: Container(
height: 40.h,
width: 80.w,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(6.r),
color: const Color(0xFF3A3A3A).withOpacity(0.6),
border: Border.all(color: const Color(0xFF9A0000))),
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 4.w),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
text10W300('Pending'),
Container(
height: 22.h,
width: 22.w,
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage(
'assets/images/png/Ellipse 1498.png',
),
fit: BoxFit.cover)),
child: Center(child: text8W400('40%')),
),
],
),
),
),
selected: true,
onTap: () {
Get.toNamed(RouteName.kyc, arguments: {
"fromScreen": "sidemenu-flow",
});
},
),
Container(
height: 1,
margin: EdgeInsets.symmetric(vertical: 10.h),
decoration: const BoxDecoration(
border: Border(
bottom: BorderSide(
color: Color.fromRGBO(176, 176, 176, 0.5),
width: 1,
),
),
),
),
ListTile(
leading: SvgPicture.asset(
'assets/images/svg/sidemenu/Group 51347.svg'),
title: text18W400('My Risk Profile'),
trailing: Container(
height: 35.h,
width: 80.w,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(6.r),
color: const Color(0xFF0093FF),
),
child: Center(child: text10W300('Conservative')),
),
selected: true,
onTap: () {
setState(() {
Get.toNamed(RouteName.updateriskprofile, arguments: {
"fromScreen": "sidemenu-flow",
});
});
},
),
Column(
children: List.generate(sideBarData.length, (index) {
return sideBarTile(
image: sideBarData[index]["imagePath"],
text: sideBarData[index]["text"],
onTap: () {
print(index);
navigateTo(index, context);
},
);
}),
),
// SingleChildScrollView(
// physics: NeverScrollableScrollPhysics(),
// child: ListView.builder(
// shrinkWrap: true,
// padding: EdgeInsets.zero,
// itemCount: sideBarData.length,
// itemBuilder: (_, index) {
// return sideBarTile(
// image: sideBarData[index]["imagePath"],
// text: sideBarData[index]["text"],
// onTap: () {
// navigateTo(index, context);
// },
// );
// },
// ),
// ),
sizedBoxHeight(80.h),
]),
]),
],
));
}
}
LogOutdialog(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 {
_handleLogout();
// SharedPreferences prefs =
// await SharedPreferences.getInstance();
// await prefs.clear();
// Get.offNamed(RouteName.loginscreen);
},
)),
SizedBox(
width: 140.w,
child: CommonYesNoBtn(
noonTap: () {
Get.back();
},
),
),
],
)
],
),
),
],
),
);
}
void navigateTo(int index, BuildContext context) {
switch (index) {
case 0:
{
Get.toNamed(RouteName.faqscreen);
}
break;
case 1:
{
Get.toNamed(RouteName.contactUsMain);
}
break;
case 2:
{
// Get.toNamed(RouteName.settingsScreen);
}
break;
case 3:
{
Get.toNamed(RouteName.termsandcondition);
}
break;
case 4:
{
Get.toNamed(RouteName.privacypolicy);
}
break;
case 5:
{
Get.toNamed(RouteName.aboutus);
}
break;
case 6:
{
Get.toNamed(RouteName.settings);
}
break;
case 7:
{
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 Logout'),
sizedBoxHeight(30.h),
text20W400_center(
'Are you sure you want to logout your account?'),
sizedBoxHeight(50.h),
CommonYesNoBtn(
yesonTap: () {
_handleLogout();
// Get.toNamed(RouteName.loginscreen);
},
noonTap: () {
Get.back();
},
),
],
),
),
),
),
backgroundColor: Colors.black.withOpacity(0.3),
);
}
break;
default:
{
null;
}
}
}
class sideBarTile extends StatelessWidget {
final String image;
final String text;
final void Function()? onTap;
sideBarTile({
required this.image,
required this.text,
this.onTap,
super.key,
});
@override
Widget build(BuildContext context) {
return Column(
children: [
Container(
height: 1,
margin: EdgeInsets.symmetric(vertical: 10.h),
decoration: const BoxDecoration(
border: Border(
bottom: BorderSide(
color: Color.fromRGBO(176, 176, 176, 0.5),
width: 1,
),
),
),
),
ListTile(
leading: SvgPicture.asset(image),
title: text18W400(text),
selected: true,
onTap: onTap),
],
);
}
}
Future<void> _handleLogout() async {
// Create an instance of the API with required data
var logoutApi = LogoutAPI({
// Add any required data here, e.g., user token or ID
});
// Call the logout API
final response = await logoutApi.logoutApi();
// Handle the response
if (response.status == ResponseStatus.SUCCESS) {
// Clear any user-related data here if necessary
SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.clear();
// Navigate to the login screen
Get.offAllNamed(RouteName.loginscreen);
} else {
// Show an error message if logout failed
Get.snackbar('Error', response.message ?? 'Logout failed');
}
}