KonectarApp/lib/widgets/home_drawer.dart

482 lines
16 KiB
Dart
Raw Normal View History

2024-10-07 12:45:45 +00:00
import 'package:flutter/material.dart';
import 'package:konectar_events/utils/apicall.dart';
import 'package:konectar_events/utils/app_theme.dart';
import 'package:konectar_events/utils/constants.dart';
import 'package:konectar_events/utils/sessionmanager.dart';
import 'package:konectar_events/view/login.dart';
2024-12-10 09:36:43 +00:00
import 'package:konectar_events/viewmodel/hive_repository.dart';
2024-12-19 05:21:33 +00:00
import 'package:konectar_events/viewmodel/loginprovider.dart';
import 'package:provider/provider.dart';
2024-10-07 12:45:45 +00:00
import 'package:shared_preferences/shared_preferences.dart';
class HomeDrawer extends StatefulWidget {
const HomeDrawer(
{Key? key,
this.screenIndex,
this.iconAnimationController,
this.callBackIndex})
: super(key: key);
final AnimationController? iconAnimationController;
final DrawerIndex? screenIndex;
final Function(DrawerIndex)? callBackIndex;
@override
_HomeDrawerState createState() => _HomeDrawerState();
}
class _HomeDrawerState extends State<HomeDrawer> {
List<DrawerList>? drawerList;
final Future<SharedPreferences> _prefs = SharedPreferences.getInstance();
late Future<String> _useremail;
2024-12-16 11:26:32 +00:00
late Future<String> _deviceid;
2024-10-07 12:45:45 +00:00
@override
void initState() {
setDrawerListArray();
_useremail = _prefs.then((SharedPreferences prefs) {
return prefs.getString('useremail') ?? "";
});
2024-12-16 11:26:32 +00:00
_deviceid = _prefs.then((SharedPreferences prefs) {
2024-12-18 04:39:20 +00:00
return prefs.getString('deviceid') ?? "";
2024-10-07 12:45:45 +00:00
});
super.initState();
}
2024-12-10 09:36:43 +00:00
void setDrawerListArray() async {
2024-12-19 05:21:33 +00:00
print("HiiisetDrawerListArray");
2024-12-16 11:26:32 +00:00
bool checkContacts = await HiveOperations.checkIfApiExists(
EventsConstants.contactsListapi, EventsConstants.moduleName);
2024-12-19 05:21:33 +00:00
print("CheckContacts_123$checkContacts");
// if (!checkContacts) {
// drawerList = <DrawerList>[
// DrawerList(
// index: DrawerIndex.HOME,
// labelName: 'Events',
// icon: Icon(Icons.event),
// ),
2024-11-19 12:57:30 +00:00
2024-12-19 05:21:33 +00:00
// DrawerList(
// index: DrawerIndex.FeedBack,
// labelName: 'HelpDesk',
// icon: Icon(Icons.help),
// ),
// DrawerList(
// index: DrawerIndex.Invite,
// labelName: 'Medical Insight',
// icon: Icon(Icons.group),
// ),
// // DrawerList(
// // index: DrawerIndex.Share,
// // labelName: 'Rate the app',
// // icon: Icon(Icons.share),
// // ),
// // DrawerList(
// // index: DrawerIndex.About,
// // labelName: 'About Us',
// // icon: Icon(Icons.info),
// // ),
// ];
// } else {
drawerList = <DrawerList>[
DrawerList(
index: DrawerIndex.Contacts,
labelName: 'Contacts',
icon: Icon(Icons.account_circle),
// isAssetsImage: true,
// imageName: 'assets/images/supportIcon.png',
),
DrawerList(
index: DrawerIndex.HOME,
labelName: 'Events',
icon: Icon(Icons.event),
),
2024-12-10 09:36:43 +00:00
2024-12-19 05:21:33 +00:00
DrawerList(
index: DrawerIndex.FeedBack,
labelName: 'HelpDesk',
icon: Icon(Icons.help),
),
DrawerList(
index: DrawerIndex.Invite,
labelName: 'Medical Insight',
icon: Icon(Icons.group),
),
// DrawerList(
// index: DrawerIndex.Share,
// labelName: 'Rate the app',
// icon: Icon(Icons.share),
// ),
// DrawerList(
// index: DrawerIndex.About,
// labelName: 'About Us',
// icon: Icon(Icons.info),
// ),
];
// }
2024-10-07 12:45:45 +00:00
}
2024-12-19 05:21:33 +00:00
// void setDrawerListArray() async {
// bool checkContacts = await HiveOperations.checkIfApiExists(
// EventsConstants.contactsListapi, EventsConstants.moduleName);
// // if (!checkContacts) {
// // drawerList = <DrawerList>[
// // DrawerList(
// // index: DrawerIndex.HOME,
// // labelName: 'Events',
// // icon: Icon(Icons.event),
// // ),
// // DrawerList(
// // index: DrawerIndex.FeedBack,
// // labelName: 'HelpDesk',
// // icon: Icon(Icons.help),
// // ),
// // DrawerList(
// // index: DrawerIndex.Invite,
// // labelName: 'Medical Insight',
// // icon: Icon(Icons.group),
// // ),
// // // DrawerList(
// // // index: DrawerIndex.Share,
// // // labelName: 'Rate the app',
// // // icon: Icon(Icons.share),
// // // ),
// // // DrawerList(
// // // index: DrawerIndex.About,
// // // labelName: 'About Us',
// // // icon: Icon(Icons.info),
// // // ),
// // ];
// // } else {
// drawerList = <DrawerList>[
// DrawerList(
// index: DrawerIndex.Contacts,
// labelName: 'Contacts',
// icon: Icon(Icons.account_circle),
// // isAssetsImage: true,
// // imageName: 'assets/images/supportIcon.png',
// ),
// DrawerList(
// index: DrawerIndex.HOME,
// labelName: 'Events',
// icon: Icon(Icons.event),
// ),
// DrawerList(
// index: DrawerIndex.FeedBack,
// labelName: 'HelpDesk',
// icon: Icon(Icons.help),
// ),
// DrawerList(
// index: DrawerIndex.Invite,
// labelName: 'Medical Insight',
// icon: Icon(Icons.group),
// ),
// // DrawerList(
// // index: DrawerIndex.Share,
// // labelName: 'Rate the app',
// // icon: Icon(Icons.share),
// // ),
// // DrawerList(
// // index: DrawerIndex.About,
// // labelName: 'About Us',
// // icon: Icon(Icons.info),
// // ),
// ];
// // }
// }
2024-10-07 12:45:45 +00:00
@override
Widget build(BuildContext context) {
var brightness = MediaQuery.of(context).platformBrightness;
bool isLightMode = brightness == Brightness.light;
return Scaffold(
backgroundColor: AppTheme.notWhite.withOpacity(0.5),
body: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Container(
width: double.infinity,
padding: const EdgeInsets.only(top: 20.0),
child: Container(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
2024-11-19 12:57:30 +00:00
SizedBox(
height: 30,
child: Image.asset(
"assets/images/konector_image_logo.png",
fit: BoxFit.cover,
2024-10-07 12:45:45 +00:00
),
),
2024-11-19 12:57:30 +00:00
// AnimatedBuilder(
// animation: widget.iconAnimationController!,
// builder: (BuildContext context, Widget? child) {
// return ScaleTransition(
// scale: AlwaysStoppedAnimation<double>(1.0 -
// (widget.iconAnimationController!.value) * 0.2),
// child: RotationTransition(
// turns: AlwaysStoppedAnimation<double>(Tween<double>(
// begin: 0.0, end: 24.0)
// .animate(CurvedAnimation(
// parent: widget.iconAnimationController!,
// curve: Curves.fastOutSlowIn))
// .value /
// 360),
// child: Container(
// height: 100,
// width: 100,
// decoration: BoxDecoration(
// shape: BoxShape.circle,
// boxShadow: <BoxShadow>[
// BoxShadow(
// color: AppTheme.grey.withOpacity(0.6),
// offset: const Offset(2.0, 4.0),
// blurRadius: 8),
// ],
// ),
// child: ClipRRect(
// borderRadius:
// const BorderRadius.all(Radius.circular(60.0)),
// child: CircleAvatar(
// radius: 24,
// backgroundColor: EventsConstants.blueColor,
// // child: Icon(
// // Icons.person,
// // size: 18,
// // color: Colors.white,
// // ),
// child: Text(
// "S",
// style: TextStyle(
// fontSize: 24,
// fontWeight: FontWeight.bold,
// color: Colors.white),
// ),
// ),
// ),
// ),
// ),
// );
// },
// ),
2024-10-07 12:45:45 +00:00
],
),
),
),
const SizedBox(
height: 4,
),
Divider(
height: 1,
color: AppTheme.grey.withOpacity(0.6),
),
Expanded(
child: ListView.builder(
physics: const BouncingScrollPhysics(),
padding: const EdgeInsets.all(0.0),
itemCount: drawerList?.length,
itemBuilder: (BuildContext context, int index) {
return inkwell(drawerList![index]);
},
),
),
2024-11-19 12:57:30 +00:00
Padding(
padding: const EdgeInsets.only(top: 8, left: 4),
child: Text(
'Logged in as Snehalatha Desai',
style: TextStyle(
fontWeight: FontWeight.w300,
color: isLightMode ? AppTheme.grey : AppTheme.white,
fontSize: 18,
),
),
),
2024-10-07 12:45:45 +00:00
Divider(
height: 1,
color: AppTheme.grey.withOpacity(0.6),
),
Column(
children: <Widget>[
ListTile(
title: Text(
'Sign Out',
style: TextStyle(
fontFamily: AppTheme.fontName,
fontWeight: FontWeight.w600,
fontSize: 16,
color: AppTheme.darkText,
),
textAlign: TextAlign.left,
),
trailing: Icon(
Icons.power_settings_new,
color: Colors.red,
),
onTap: () {
2024-12-19 05:21:33 +00:00
// Provider.of<LoginProvider>(context, listen: false)
// .saveApiData();
2024-10-07 12:45:45 +00:00
onTapped();
},
),
SizedBox(
height: MediaQuery.of(context).padding.bottom,
)
],
),
],
),
);
}
void onTapped() async {
2024-12-16 11:26:32 +00:00
print("device id : ${await _deviceid}");
final resp = await ApiCall().logout(await _useremail, await _deviceid);
2024-10-07 12:45:45 +00:00
print("resp:$resp");
await SessionManager().logoutSession(false).then((value) {
Navigator.of(context).popUntil((route) => route.isFirst);
// Navigator.of(context, rootNavigator: true).pushReplacementNamed("/");
Navigator.pushReplacement(
context,
MaterialPageRoute(builder: (context) => LoginScreen()),
);
});
}
Widget inkwell(DrawerList listData) {
return Material(
color: Colors.transparent,
child: InkWell(
splashColor: Colors.grey.withOpacity(0.1),
highlightColor: Colors.transparent,
onTap: () {
navigationtoScreen(listData.index!);
},
child: Stack(
children: <Widget>[
Container(
padding: const EdgeInsets.only(top: 8.0, bottom: 8.0),
child: Row(
children: <Widget>[
Container(
width: 6.0,
height: 46.0,
// decoration: BoxDecoration(
// color: widget.screenIndex == listData.index
// ? Colors.blue
// : Colors.transparent,
// borderRadius: new BorderRadius.only(
// topLeft: Radius.circular(0),
// topRight: Radius.circular(16),
// bottomLeft: Radius.circular(0),
// bottomRight: Radius.circular(16),
// ),
// ),
),
const Padding(
padding: EdgeInsets.all(4.0),
),
listData.isAssetsImage
? Container(
width: 24,
height: 24,
child: Image.asset(listData.imageName,
color: widget.screenIndex == listData.index
? Colors.blue
: AppTheme.nearlyBlack),
)
: Icon(listData.icon?.icon,
color: widget.screenIndex == listData.index
? Colors.blue
: AppTheme.nearlyBlack),
const Padding(
padding: EdgeInsets.all(4.0),
),
Text(
listData.labelName,
style: TextStyle(
fontWeight: FontWeight.w500,
fontSize: 16,
color: widget.screenIndex == listData.index
? Colors.black
: AppTheme.nearlyBlack,
),
textAlign: TextAlign.left,
),
],
),
),
widget.screenIndex == listData.index
? AnimatedBuilder(
animation: widget.iconAnimationController!,
builder: (BuildContext context, Widget? child) {
return Transform(
transform: Matrix4.translationValues(
(MediaQuery.of(context).size.width * 0.75 - 64) *
(1.0 -
widget.iconAnimationController!.value -
1.0),
0.0,
0.0),
child: Padding(
padding: EdgeInsets.only(top: 8, bottom: 8),
child: Container(
width:
MediaQuery.of(context).size.width * 0.75 - 64,
height: 46,
decoration: BoxDecoration(
color: Colors.blue.withOpacity(0.2),
borderRadius: new BorderRadius.only(
topLeft: Radius.circular(0),
topRight: Radius.circular(28),
bottomLeft: Radius.circular(0),
bottomRight: Radius.circular(28),
),
),
),
),
);
},
)
: const SizedBox()
],
),
),
);
}
Future<void> navigationtoScreen(DrawerIndex indexScreen) async {
widget.callBackIndex!(indexScreen);
}
}
enum DrawerIndex {
HOME,
FeedBack,
2024-12-10 09:36:43 +00:00
Contacts,
2024-10-07 12:45:45 +00:00
Share,
About,
Invite,
Testing,
}
class DrawerList {
DrawerList({
this.isAssetsImage = false,
this.labelName = '',
this.icon,
this.index,
this.imageName = '',
});
String labelName;
Icon? icon;
bool isAssetsImage;
String imageName;
DrawerIndex? index;
}