import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:healthcare_user/emergency.dart'; import 'package:healthcare_user/invitations.dart'; import 'package:healthcare_user/medicines.dart'; import 'package:healthcare_user/my_health.dart'; import 'package:healthcare_user/prescriptions.dart'; import 'package:healthcare_user/reports.dart'; import 'package:healthcare_user/seekopinion.dart'; import 'package:healthcare_user/settings.dart'; import 'package:healthcare_user/updateprofile.dart'; import 'package:image_picker/image_picker.dart'; import 'package:carousel_slider/carousel_slider.dart'; import 'dart:ui' as ui; import 'login.dart'; import 'dart:io'; class Dashboard extends StatefulWidget { const Dashboard({super.key}); @override State createState() => _DashboardState(); } class _DashboardState extends State { int _selectedIndex = 0; final List imgList = [ 'images/mobilebg.png', 'images/mobilebg2.png', 'images/mobilebg3.png' ]; final ImagePicker _picker = ImagePicker(); bool isTablet = false; bool isPhone = true; final double devicePixelRatio = ui.window.devicePixelRatio; static final ui.Size size1 = ui.window.physicalSize; final double width = size1.width; final double height = size1.height; devicedetection() { if (devicePixelRatio < 2 && (width >= 1000 || height >= 1000)) { isTablet = true; isPhone = false; } else if (devicePixelRatio == 2 && (width >= 1920 || height >= 1920)) { isTablet = true; isPhone = false; } else { isTablet = false; isPhone = true; } } List images = [ "images/seekopinion.png", "images/reports.png", "images/prescriptions.png", "images/medicines.png", "images/invitations.png", "images/emergency.png" ]; gridOntap(int ind){ if(ind==0){ Navigator.push( context, MaterialPageRoute( builder: (context) => const SeekOpinion()), ); } else if(ind==1){ Navigator.push( context, MaterialPageRoute( builder: (context) => const Reports()), ); } else if(ind==2){ Navigator.push( context, MaterialPageRoute( builder: (context) => const Prescriptions()), ); } else if(ind==3){ Navigator.push( context, MaterialPageRoute( builder: (context) => const Medicines()), ); } else if(ind==4){ Navigator.push( context, MaterialPageRoute( builder: (context) => const Invitations()), ); } else if(ind==5){ Navigator.push( context, MaterialPageRoute( builder: (context) => const Emergency()), ); } } Widget _dashBoard() { return Container( color: Colors.white, child: Column( children: [ CarouselSlider( options: CarouselOptions( height: MediaQuery.of(context).size.height * .250, aspectRatio: 16 / 9, viewportFraction: 0.8, initialPage: 0, enableInfiniteScroll: true, reverse: false, autoPlay: true, autoPlayInterval: Duration(seconds: 3), autoPlayAnimationDuration: Duration(milliseconds: 800), autoPlayCurve: Curves.ease, enlargeCenterPage: true, enlargeFactor: 0.2, scrollDirection: Axis.horizontal, ), items: imgList.map((i) { return Builder( builder: (BuildContext context) { return Container( height: MediaQuery.of(context).size.height * .250, width: double.infinity, decoration: BoxDecoration( borderRadius: BorderRadius.circular(0), ), //color: Colors.red, child: FittedBox( child: Image( image: AssetImage(i), ), fit: BoxFit.fill, )); }, ); }).toList(), ), SizedBox(height: 5), Expanded(child: Container( padding: EdgeInsets.all(12.0), child: GridView.builder( itemCount: images.length, gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( crossAxisCount: 3, crossAxisSpacing: 4.0, mainAxisSpacing: 4.0,), itemBuilder: (BuildContext context, int index) { return GestureDetector( onTap: (){ gridOntap(index); }, child: Image.asset(images[index]), ); }, )),) ], ), ); } @override void initState() { super.initState(); devicedetection(); } Future uploadProfileApi(image) async { var payload = new Map(); payload["formData"] = image.toString(); var response1 = await AppSettings.updateProfilePicture(payload); print(response1); } Future pickImageFromGallery() async { try { final image = await _picker.pickImage(source: ImageSource.gallery); if (image == null) return; final imageTemp = File(image.path); setState(() { AppSettings.updatedImage = imageTemp; }); uploadProfileApi(image.path); AppSettings.saveProfile(image.path); } on PlatformException catch (e) { print('Failed to pick image: $e'); } } Future takeImageFromCamera() async { try { final image = await _picker.pickImage(source: ImageSource.camera); if (image == null) return; final imageTemp = File(image.path); setState(() { AppSettings.updatedImage = imageTemp; }); uploadProfileApi(image.path); AppSettings.saveProfile(image.path); } on PlatformException catch (e) { print('Failed to pick image: $e'); } } showLogoutAlertDialog(context) { return showDialog( context: context, barrierDismissible: false, builder: (BuildContext context) { return StatefulBuilder( builder: (BuildContext context, StateSetter setState) { return AlertDialog( title: const Text('Do you really want to logout?'), actions: [ TextButton( child: Text('No', style: textButtonStyle()), onPressed: () { Navigator.of(context).pop(); }, ), TextButton( child: Text('Yes', style: textButtonStyle()), onPressed: () async { await AppSettings.clearSharedPreferences(); await Navigator.pushAndRemoveUntil( context, MaterialPageRoute(builder: (context) => Login()), (Route route) => false, ); }, ), ]); }); }); } @override Widget build(BuildContext context) { return WillPopScope( onWillPop: () async { final shouldPop = await showDialog( context: context, builder: (context) { return AlertDialog( title: const Text('Do you want to exit app?', style: TextStyle( color: primaryColor, fontSize: 20, )), actionsAlignment: MainAxisAlignment.spaceBetween, actions: [ TextButton( onPressed: () { SystemNavigator.pop(); }, child: const Text('Yes', style: TextStyle( color: primaryColor, fontSize: 20, )), ), TextButton( onPressed: () { Navigator.of(context).pop(false); }, child: const Text('No', style: TextStyle( color: primaryColor, fontSize: 20, )), ), ], ); }, ); return shouldPop!; }, child: Scaffold( resizeToAvoidBottomInset: false, appBar: AppSettings.appBar('Health Care'), drawer: Drawer( child: ListView( padding: EdgeInsets.zero, children: [ DrawerHeader( decoration: const BoxDecoration( color: primaryColor, ), child: Row( children: [ Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Expanded( child: GestureDetector( child: Container( width: MediaQuery.of(context).size.width * .20, height: MediaQuery.of(context).size.height * .15, decoration: BoxDecoration( shape: BoxShape.circle, image: DecorationImage( image: (AppSettings.updatedImage != null) ? FileImage( AppSettings.updatedImage!) as ImageProvider : AssetImage( "images/profile_pic.png"), // picked file fit: BoxFit.cover)), ), onTap: () { showModalBottomSheet( context: context, builder: (BuildContext context) { return SizedBox( height: 200, child: Center( child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ GestureDetector( child: Icon( Icons.camera_alt_outlined, size: 100, color: greyColor, ), onTap: () async { await takeImageFromCamera(); Navigator.pop(context); }, ), SizedBox( width: MediaQuery.of(context) .size .width * .20, ), GestureDetector( child: Icon( Icons.photo, size: 100, color: greyColor, ), onTap: () async { await pickImageFromGallery(); Navigator.pop(context); }, ), ], ), ), ); }); }, ), ), Text( AppSettings.userName, style: TextStyle(color: Colors.white, fontSize: 15), ), Text( AppSettings.phoneNumber, style: TextStyle(color: Colors.white, fontSize: 15), ), Text( AppSettings.email, style: TextStyle(color: Colors.white, fontSize: 15), ), ], ), Container() ], )), ListTile( title: Row( children: const [ Image( image: const AssetImage('images/editprofile.png'), height: 25, width: 25, fit: BoxFit.fill), const SizedBox( width: 10, ), const SizedBox( width: 10, ), Text('Edit Profile', style: TextStyle(color: primaryColor)), ], ), onTap: () { Navigator.push( context, MaterialPageRoute( builder: (context) => const UpdateProfile()), ); }, ), Divider( color: Colors.grey, ), ListTile( title: Row( children: const [ Image( image: const AssetImage('images/myhealth.png'), height: 25, width: 25, fit: BoxFit.fill), const SizedBox( width: 10, ), const SizedBox( width: 10, ), Text('My Health', style: TextStyle(color: primaryColor)), ], ), onTap: () { Navigator.push( context, MaterialPageRoute( builder: (context) => const MyHealth()), ); }, ), Divider( color: Colors.grey, ), ListTile( title: Row( children: const [ Image( image: const AssetImage('images/reportmyself.png'), height: 25, width: 25, fit: BoxFit.fill), const SizedBox( width: 10, ), const SizedBox( width: 10, ), Text('Report Myself', style: TextStyle(color: primaryColor)), ], ), onTap: () {}, ), Divider( color: Colors.grey, ), ListTile( title: Row( children: const [ Image( image: const AssetImage('images/myconnections.png'), height: 25, width: 25, fit: BoxFit.fill), const SizedBox( width: 10, ), const SizedBox( width: 10, ), Text('My Connections', style: TextStyle(color: primaryColor)), ], ), onTap: () {}, ), Divider( color: Colors.grey, ), ListTile( title: Row( children: const [ Image( image: const AssetImage('images/mymedicinetimings.png'), height: 25, width: 25, fit: BoxFit.fill), const SizedBox( width: 10, ), const SizedBox( width: 10, ), Text('My Medicine Timings', style: TextStyle(color: primaryColor)), ], ), onTap: () {}, ), Divider( color: Colors.grey, ), ListTile( title: Row( children: const [ Image( image: const AssetImage('images/updatepin.png'), height: 25, width: 25, fit: BoxFit.fill), const SizedBox( width: 10, ), const SizedBox( width: 10, ), Text('Update Pin', style: TextStyle(color: primaryColor)), ], ), onTap: () {}, ), Divider( color: Colors.grey, ), ListTile( title: Row( children: const [ Image( image: const AssetImage('images/updatemobilenumber.png'), height: 25, width: 25, fit: BoxFit.fill), const SizedBox( width: 10, ), const SizedBox( width: 10, ), Text('Update Mobile Number', style: TextStyle(color: primaryColor)), ], ), onTap: () {}, ), Divider( color: Colors.grey, ), ListTile( title: Row( children: const [ Image( image: const AssetImage('images/updatemylocation.png'), height: 25, width: 25, fit: BoxFit.fill), const SizedBox( width: 10, ), const SizedBox( width: 10, ), Text('Update My Location', style: TextStyle(color: primaryColor)), ], ), onTap: () {}, ), Divider( color: Colors.grey, ), ListTile( title: Row( children: const [ Image( image: const AssetImage('images/logout.png'), height: 25, width: 25, fit: BoxFit.fill), const SizedBox( width: 10, ), const SizedBox( width: 10, ), Text('Logout', style: TextStyle(color: primaryColor)), ], ), onTap: () {}, ), ], ), ), body: _dashBoard(), ), ); } }