import 'dart:async'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:generp/Notifiers/Counter.dart'; import 'package:generp/Notifiers/HomeScreenNotifier.dart'; import 'package:generp/Notifiers/LogoutNotifier.dart'; import 'package:generp/Notifiers/ProfileNotifier.dart'; import 'package:generp/screens/LoginScreen.dart'; import 'package:generp/screens/ScannerLogin.dart'; import 'package:generp/screens/WebERPScreen.dart'; import 'package:generp/screens/WebWhizzdomScreen.dart'; import 'package:generp/screens/genTracker/GenTrackerDashboard.dart'; import 'package:generp/screens/serviceEngineer/serviceEngineerDashboard.dart'; import 'package:provider/provider.dart'; import 'package:cached_network_image/cached_network_image.dart'; import '../Utils/app_colors.dart'; import 'AttendanceScreen.dart'; import 'inventory/InventoryScreen.dart'; class MyHomePage extends StatefulWidget { const MyHomePage({super.key}); @override State createState() => _MyHomePageState(); } class _MyHomePageState extends State { Timer? timer; @override void initState() { // TODO: implement initState var prov = Provider.of(context, listen: false); var prof_prov = Provider.of(context, listen: false); Future.microtask(() { prov.DashboardApiFunction(context); }); Future.delayed(Duration(milliseconds: 600), () { prof_prov.ProfileApiFunction(prov, context); prof_prov.VersionApiFunction(); }); super.initState(); } Future onBackPressed() async { return await showDialog( context: context, builder: (context) => AlertDialog( title: const Text('Are you sure?'), content: const Text('Do you want to exit the App'), actions: [ TextButton( style: ButtonStyle( backgroundColor: MaterialStateProperty.all(Colors.white), overlayColor: MaterialStateProperty.all(Colors.white), ), onPressed: () => Navigator.of(context).pop(false), child: Text( "NO", style: TextStyle( fontWeight: FontWeight.w500, ), ), ), const SizedBox(height: 16), TextButton( style: ButtonStyle( backgroundColor: MaterialStateProperty.all(Colors.white), overlayColor: MaterialStateProperty.all(Colors.white70), ), onPressed: () => SystemChannels.platform.invokeMethod('SystemNavigator.pop'), child: Text( "YES", style: TextStyle( fontWeight: FontWeight.w500, ), ), ), ], elevation: 30.0, ), barrierDismissible: false, ) ?? false; } @override Widget build(BuildContext context) { return Consumer2( builder: (context, homescreen, profile, child) { return WillPopScope( onWillPop: onBackPressed, child: RefreshIndicator.adaptive( color: AppColors.app_blue, onRefresh: () async { await Future.delayed(const Duration(milliseconds: 600)); homescreen.DashboardApiFunction(context); }, child: Scaffold( backgroundColor: AppColors.scaffold_bg_color, body: Container( child: Column( children: [ Expanded( flex: 3, child: Container( padding: EdgeInsets.symmetric(vertical: 10), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.vertical( bottom: Radius.circular(30), ), ), child: Container( margin: EdgeInsets.only( bottom: 15, left: 15, right: 15, top: 30, ), decoration: BoxDecoration( borderRadius: BorderRadius.circular(30), gradient: LinearGradient( colors: [AppColors.profile_card_gradient1, AppColors.profile_card_gradient2], ), ), child: Row( crossAxisAlignment: CrossAxisAlignment.center, children: [ Expanded( flex: 2, child: SizedBox( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ SizedBox( width:66, height: 66, child: ClipRRect( borderRadius: BorderRadius.circular(50), child: CachedNetworkImage( cacheKey: profile.profileImage, fit: BoxFit.cover, imageUrl: "${profile.profileImage}", useOldImageOnUrlChange: false, placeholder: (context, url) => CircularProgressIndicator.adaptive( ), errorWidget: (context, url, error) => Icon(Icons.error), ), ), ), Row( mainAxisAlignment: MainAxisAlignment.center, children: [ Container( width: 10, height: 10, decoration: BoxDecoration( shape: BoxShape.circle, color: homescreen.onlineStatus=="Online"?Colors.green:Colors.yellow, ), ), SizedBox(width: 5), Text( "${homescreen.onlineStatus}", style: TextStyle( fontSize: 14, color: Colors.black, ), ), ], ), ], ), ), ), Expanded( flex: 3, child: SizedBox( child: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.center, children: [ Text( "${profile.employeeName}", style: TextStyle( color: AppColors.app_blue, fontSize: 16, ), ), Text( "${profile.designation}", style: TextStyle( color: AppColors.semi_black, fontSize: 14, ), ), Text( "${profile.employeeeID}", style: TextStyle( color: AppColors.semi_black, fontSize: 14, ), ), InkResponse( onTap: () { _showProfileBottomSheet(context); }, child: Row( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.center, children: [ Text( "View Profile", style: TextStyle( color: AppColors.app_blue, fontSize: 16, ), ), SizedBox(width: 5), SizedBox( width: 15, height: 15, child: Center( child: SvgPicture.asset( "assets/svg/next_button.svg", ), ), ), ], ), ), ], ), ), ), ], ), ), ), ), Expanded( flex: 8, child: Container( padding: EdgeInsets.only( left: 20, right: 20, top: 0, bottom: 10, ), child: GridView.builder( itemCount: 8, gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( crossAxisCount: 2, crossAxisSpacing: 10, mainAxisSpacing: 10, ), itemBuilder: (context, index) { var roles = homescreen.roleStatus; final names = [ "Attendance", "ERP", "Gen Tracker", "Service Engineer", "Nearby", "Inventory", "Whizzdom", "CRM", ]; return InkResponse( onTap: () async { var res; switch (names[index]) { case "Attendance": res = await Navigator.push(context,MaterialPageRoute(builder: (context) => AttendanceScreen())); break; case "ERP": res = await Navigator.push(context,MaterialPageRoute(builder: (context) => WebErpScreen(erp_url: homescreen.webPageUrl))); break; case "Gen Tracker": res = await Navigator.push(context, MaterialPageRoute(builder: (context)=>Gentrackerdashboard())); break; case "Service Engineer": res = await Navigator.push(context, MaterialPageRoute(builder: (context)=>Serviceengineerdashboard())); break; case "Nearby": //res = await Navigator.push(context, MaterialPageRoute(builder: (context)=>NearByGeneratorsScreen())); break; case "Inventory": res = await Navigator.push(context, MaterialPageRoute(builder: (context)=>InventoryScreen())); break; case "Whizzdom": res = await Navigator.push(context, MaterialPageRoute(builder: (context)=>WebWhizzdomScreen( whizzdom_url: homescreen.whizzdomPageUrl ))); break; case "CRM": //res = await Navigator.push(context, MaterialPageRoute(builder: (context)=>CRMScreen())); break; default: print("111"); break; } if(res==true){ homescreen.DashboardApiFunction(context); } }, child: Container( decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(30), ), child: Column( crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center, children: [ SvgPicture.asset( "assets/svg/home_icons_${index + 1}.svg", ), Text(names[index]), ], ), ), ); }, ), ), ), ], ), ), ), ), ); }, ); } Future _showProfileBottomSheet(BuildContext context) { return showModalBottomSheet( useSafeArea: true, isDismissible: true, isScrollControlled: true, showDragHandle: true, enableDrag: true, context: context, builder: (context) { return StatefulBuilder( builder: (context, setState) { return SafeArea( child: Container( margin: EdgeInsets.only( bottom: 15, left: 15, right: 15, top: 30, ), child: Consumer3< HomescreenNotifier, ProfileNotifer, LogoutNotifier >( builder: (context, home, profile, logout, child) { return SingleChildScrollView( child: Column( mainAxisSize: MainAxisSize.min, children: [ Padding( padding: const EdgeInsets.symmetric( horizontal: 5.0, ), child: Row( children: [ SizedBox( height: 35, child: Image.asset( "assets/images/gen_horiz_logo.png", ), ), Spacer(), InkResponse( onTap: () { Navigator.push(context, MaterialPageRoute(builder: (context) => Scannerlogin(),)); }, child: SizedBox( height: 25, width: 25, child: SvgPicture.asset( "assets/svg/scanner.svg", ), ), ), ], ), ), SizedBox(height: 15), Container( decoration: BoxDecoration( borderRadius: BorderRadius.circular(30), gradient: LinearGradient( colors: [AppColors.profile_card_gradient1, AppColors.profile_card_gradient2], ), ), child: Column( crossAxisAlignment: CrossAxisAlignment.center, children: [ Padding( padding: EdgeInsets.all(10), child:SizedBox( width:70, height: 70, child: ClipRRect( borderRadius: BorderRadius.circular(50), child: CachedNetworkImage( cacheKey: profile.profileImage, fit: BoxFit.cover, imageUrl: "${profile.profileImage}", useOldImageOnUrlChange: false, placeholder: (context, url) => CircularProgressIndicator.adaptive( ), errorWidget: (context, url, error) => Icon(Icons.error), ), ), ), ), Text( "${profile.employeeName}", style: TextStyle( color: AppColors.app_blue, fontSize: 16, ), ), Text( "${profile.employeeEmail}", style: TextStyle( color: AppColors.semi_black, fontSize: 14, ), ), Container( padding: EdgeInsets.symmetric(horizontal: 20), alignment: Alignment.center, child: Row( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: [ Expanded( flex: 1, child: ListView.builder( shrinkWrap: true, itemCount: 5, physics: NeverScrollableScrollPhysics(), itemBuilder: (context, index) { final textHeadings = [ "Company", "Branch", "Designation", "Employee ID", "Mobile Number", ]; return SizedBox( height: 40, child: Align( alignment: Alignment.centerLeft, child: Text( "${textHeadings[index]}", textAlign: TextAlign.left, style: TextStyle( fontSize: 14, color: AppColors.app_blue, ), ), ), ); }, ), ), Expanded( flex: 1, child: ListView.builder( shrinkWrap: true, itemCount: 5, physics: NeverScrollableScrollPhysics(), itemBuilder: (context, index) { final textHeadings = [ profile.company, profile.branch, profile.designation, profile.employeeeID, profile.mobileNUmber, ]; return SizedBox( height: 40, child: Align( alignment: Alignment.centerLeft, child: Text( "${textHeadings[index].toString()}", textAlign: TextAlign.left, style: TextStyle( fontSize: 14, color: AppColors.semi_black, ), ), ), ); }, ), ), ], ), ), ], ), ), InkWell( onTap: () { // LoginApiFunction(); var f = FocusScope.of(context); if (!f.hasPrimaryFocus) { f.unfocus(); } _showLogoutBottomSheet(context); // Navigator.push(context,MaterialPageRoute(builder: (context)=>Profile())); }, child: Container( alignment: Alignment.center, height: 45, margin: EdgeInsets.only( left: 5.0, right: 5.0, top: 5.0, bottom: 5.0, ), decoration: BoxDecoration( color: AppColors.app_blue, //1487C9 borderRadius: BorderRadius.circular(30.0), ), child: Center( child: Text( "Logout", textAlign: TextAlign.center, style: TextStyle(color: Colors.white), ), ), ), ), Text( profile.releaseNotes, style: TextStyle( fontSize: 14, color: AppColors.grey_thick, ), ), ], ), ); }, ), ), ); }, ); }, ); } Future _showLogoutBottomSheet(BuildContext context) { return showModalBottomSheet( useSafeArea: true, isDismissible: true, isScrollControlled: true, showDragHandle: true, enableDrag: true, context: context, builder: (context) { return StatefulBuilder( builder: (context, setState) { return SafeArea( child: Container( margin: EdgeInsets.only( bottom: 15, left: 15, right: 15, top: 30, ), child: Consumer3< HomescreenNotifier, ProfileNotifer, LogoutNotifier >( builder: (context, home, profile, logout, child) { return SingleChildScrollView( child: Column( mainAxisSize: MainAxisSize.min, children: [ Column( crossAxisAlignment: CrossAxisAlignment.center, children: [ Text( "Are you sure you want \nto logout ?", textAlign: TextAlign.center, style: TextStyle( color: AppColors.semi_black, fontSize: 18, ), ), ], ), SizedBox(height: 20), InkWell( onTap: () { // LoginApiFunction(); var f = FocusScope.of(context); if (!f.hasPrimaryFocus) { f.unfocus(); } logout.LogoutApiFunction(home, context); // Navigator.push(context,MaterialPageRoute(builder: (context)=>Profile())); }, child: Container( alignment: Alignment.center, height: 45, margin: EdgeInsets.only( left: 5.0, right: 5.0, top: 5.0, bottom: 5.0, ), decoration: BoxDecoration( color: AppColors.app_blue, //1487C9 borderRadius: BorderRadius.circular(30.0), ), child: Center( child: Text( "Yes, Logout", textAlign: TextAlign.center, style: TextStyle(color: Colors.white), ), ), ), ), InkWell( onTap: () { // LoginApiFunction(); var f = FocusScope.of(context); if (!f.hasPrimaryFocus) { f.unfocus(); } Navigator.pop(context); }, child: Container( alignment: Alignment.center, height: 45, margin: EdgeInsets.only( left: 5.0, right: 5.0, top: 5.0, bottom: 5.0, ), child: Center( child: Text( "Cancel", textAlign: TextAlign.center, style: TextStyle(color: AppColors.app_blue), ), ), ), ), ], ), ); }, ), ), ); }, ); }, ); } }