import 'dart:convert'; import 'dart:io'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:healthcare_pharmacy/companyoffrers.dart'; import 'package:healthcare_pharmacy/getallpharmacies.dart'; import 'package:healthcare_pharmacy/getmedicines.dart'; import 'package:healthcare_pharmacy/inactiveoffersview.dart'; import 'package:healthcare_pharmacy/medicinecart.dart'; import 'package:healthcare_pharmacy/createoffers.dart'; import 'package:healthcare_pharmacy/offerstabdata.dart'; import 'package:healthcare_pharmacy/offersview.dart'; import 'package:healthcare_pharmacy/biddingrequests.dart'; import 'package:healthcare_pharmacy/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 'seekopinion.dart'; import 'settings.dart'; 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/createoffer.png", "images/activeoffer.png", // "images/inactiveoffer.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 offers()), ); } else if(ind==1){ Navigator.push( context, MaterialPageRoute( builder: (context) => const OffersData()), ); } /* else if(ind==2){ Navigator.push( context, MaterialPageRoute( builder: (context) => const InActiveOffersView()), ); }*/ /* 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: Color(0xffA78966), child: Column( children: [ 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: const AssetImage('images/mobilebg2.png'), ), fit: BoxFit.fill, ) ), /*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); AppSettings.preLoaderDialog(context); var res = await AppSettings.uploadImageHTTPNew(image); print(jsonDecode(res)); Navigator.of(context, rootNavigator: true).pop(); setState(() { AppSettings.profilePictureUrl = jsonDecode(res)['picture']; }); AppSettings.saveData('profile', jsonDecode(res)['picture'], 'STRING'); } 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); AppSettings.preLoaderDialog(context); var res = await AppSettings.uploadImageHTTPNew(image); print(jsonDecode(res)); Navigator.of(context, rootNavigator: true).pop(); setState(() { AppSettings.profilePictureUrl = jsonDecode(res)['picture']; }); AppSettings.saveData('profile', jsonDecode(res)['picture'], 'STRING'); } 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( backgroundColor: secondaryColor, 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 * .60, height: MediaQuery.of(context).size.height * .25, decoration: BoxDecoration( shape: BoxShape.rectangle, border: Border.all(width: 2 , color: Colors.blueGrey), image: DecorationImage( image: (AppSettings.profilePictureUrl != '' && AppSettings.profilePictureUrl != 'null') ? NetworkImage(AppSettings .profilePictureUrl) as ImageProvider : AssetImage( "images/mobilebg.png"), // picked file fit: BoxFit.fitWidth)), ), 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.pharmacyName, 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), ), SizedBox( height: 10, ), ], ), Container() ], )), ListTile( title: Row( children: const [ Image( image: const AssetImage('images/editprofile.png'), height: 25, width: 25, fit: BoxFit.fill), const SizedBox( width: 10, ), Text('Edit Profile', style: TextStyle(color: Colors.black)), ], ), 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/createofferic.png'), height: 25, width: 25, fit: BoxFit.fill), const SizedBox( width: 10, ), Text('Create Offers', style: TextStyle(color: Colors.black)), ], ), onTap: () { Navigator.push( context, MaterialPageRoute( builder: (context) => const offers()), ); }, ), Divider( color: Colors.grey, ), ListTile( title: Row( children: const [ Image( image: const AssetImage('images/active.png'), height: 25, width: 25, fit: BoxFit.fill), const SizedBox( width: 10, ), Text('OffersData', style: TextStyle(color: Colors.black)), ], ), onTap: () { Navigator.push( context, MaterialPageRoute( builder: (context) => const OffersData()), ); }, ), Divider( color: Colors.grey, ), ListTile( title: Row( children: const [ Image( image: const AssetImage('images/inactive.png'), height: 25, width: 25, fit: BoxFit.fill), const SizedBox( width: 10, ), Text('BiddingRequests', style: TextStyle(color: Colors.black)), ], ), onTap: () { Navigator.push( context, MaterialPageRoute( builder: (context) => BiddingRequests()), ); }, ), Divider( color: Colors.grey, ), ListTile( title: Row( children: const [ Image( image: const AssetImage('images/inactive.png'), height: 25, width: 25, fit: BoxFit.fill), const SizedBox( width: 10, ), Text('Company Offers', style: TextStyle(color: Colors.black)), ], ), onTap: () { Navigator.push( context, MaterialPageRoute( builder: (context) => CompanyOffers()), ); }, ), Divider( color: Colors.grey, ), ListTile( title: Row( children: const [ Image( image: const AssetImage('images/inactive.png'), height: 25, width: 25, fit: BoxFit.fill), const SizedBox( width: 10, ), Text('GetAllPharmacies', style: TextStyle(color: Colors.black)), ], ), onTap: () { Navigator.push( context, MaterialPageRoute( builder: (context) => GetAllPharmacies()), ); }, ), 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, ), Text('Logout', style: TextStyle(color: Colors.black)), ], ), onTap: () async { showLogoutAlertDialog(context); }, ), ], ), ), body: _dashBoard(), ), ); } }