import 'dart:io'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:package_info/package_info.dart'; import 'package:provider/provider.dart'; import 'package:share/share.dart'; import 'package:test_sa/controllers/notification/firebase_notification_manger.dart'; import 'package:test_sa/controllers/providers/api/user_provider.dart'; import 'package:test_sa/controllers/providers/settings/setting_provider.dart'; import 'package:test_sa/extensions/int_extensions.dart'; import 'package:test_sa/extensions/widget_extensions.dart'; import 'package:test_sa/new_views/pages/new_gas_refill_request_page.dart'; import 'package:test_sa/new_views/pages/new_transfer_request_page.dart'; import 'package:test_sa/views/app_style/colors.dart'; import 'package:test_sa/views/app_style/sizing.dart'; import 'package:test_sa/views/pages/device_transfer/track_device_transfer.dart'; import 'package:test_sa/views/pages/sub_workorder/search_sub_workorder_page.dart'; import 'package:test_sa/views/pages/user/gas_refill/track_gas_refill.dart'; import 'package:test_sa/views/pages/user/visits/regular_visits_page.dart'; import 'package:test_sa/views/widgets/buttons/app_back_button.dart'; import 'package:test_sa/views/widgets/buttons/app_icon_button.dart'; import 'package:test_sa/views/widgets/dialogs/dialog.dart'; import 'package:test_sa/views/widgets/drawer/drawer_item.dart'; import 'package:url_launcher/url_launcher.dart'; import '../../../new_views/pages/new_service_request_page.dart'; import '../../widgets/land_page/land_page_item.dart'; import 'requests/requests_page.dart'; @Deprecated("Use the page which is inside the [new_views/pages/land_page] folder") class LandPage extends StatefulWidget { static const String id = "/old-land-page"; const LandPage({Key key}) : super(key: key); @override State createState() => _LandPageState(); } class _LandPageState extends State { double _height; double _width; UserProvider _userProvider; SettingProvider _settingProvider; // DepartmentsProvider _departmentsProvider; // DevicesProvider _devicesProvider; double _buttonHeight; bool firstTime = true; // ServiceRequestsProvider _serviceRequestsProvider; // PreventiveMaintenanceVisitsProvider _preventiveMaintenanceVisitsProvider; // RegularVisitsProvider _regularVisitsProvider; final GlobalKey _scaffoldKey = GlobalKey(); @override void initState() { WidgetsBinding.instance.addPostFrameCallback((timeStamp) async { try { FirebaseNotificationManger.initialized(context); } catch (error) {} }); super.initState(); } @override Widget build(BuildContext context) { String path = ModalRoute.of(context).settings.arguments; _height = MediaQuery.of(context).size.height; _width = MediaQuery.of(context).size.width; _settingProvider = Provider.of(context); _userProvider = Provider.of(context); // _departmentsProvider = Provider.of(context); // _devicesProvider = Provider.of(context); // _serviceRequestsProvider = Provider.of(context); // _preventiveMaintenanceVisitsProvider = Provider.of(context); // _regularVisitsProvider = Provider.of(context); // if (firstTime) { if (path != null) { Navigator.of(context).pushNamed("/" + path.split("/").first, arguments: path.split("/").last); } firstTime = false; } _buttonHeight = 68 * AppStyle.getScaleFactor(context); return WillPopScope( onWillPop: () async { bool result = await showDialog( context: context, builder: (_) => const AAlertDialog( // title: _subtitle.exit, title: "Exit", // content: _subtitle.exitAlert, content: "Are you sure you want to exit?", )); if (result == true) { if (Platform.isAndroid) { SystemChannels.platform.invokeMethod('SystemNavigator.pop'); } else { exit(0); } } return false; }, child: Scaffold( key: _scaffoldKey, //backgroundColor: Color(0xffF8F8F8), body: SafeArea( child: Stack( children: [ ListView( padding: const EdgeInsets.all(16.0), children: [ //AppNameBar(), // SizedBox( // height: _height/3.2, // width: _width, // child: CarouselSlider.builder( // options: CarouselOptions( // height: _height/3, // autoPlay: true, // viewportFraction: 1 // ), // itemCount: 4, // itemBuilder: (BuildContext context, int itemIndex, int pageViewIndex) => // Image( // //width: _width, // image: AssetImage("assets/images/$itemIndex.png"), // fit: BoxFit.cover, // ) // ), // ), SizedBox( height: 48 * AppStyle.getScaleFactor(context), ), // Hero( // tag: "logo", // child: Image( // height: _height / 6, // image: const AssetImage("assets/images/logo.png"), // ), // ), GridView.count( shrinkWrap: true, physics: const ClampingScrollPhysics(), crossAxisCount: 2, crossAxisSpacing: 12, mainAxisSpacing: 12, childAspectRatio: 1, children: [ /// enable this condition when the nurse account works // if (_userProvider.user != null && _userProvider.user.type == UsersTypes.normal_user) LandPageItem( // text: _subtitle.newServiceRequest, text: "New Service Request", icon: FontAwesomeIcons.screwdriverWrench, onPressed: () { // Navigator.of(context).pushNamed(CreateRequestPage.id); Navigator.of(context).pushNamed(NewServiceRequestPage.routeName); }, ), LandPageItem( // text: _subtitle.trackServiceRequest, text: "Track Service Request", icon: FontAwesomeIcons.listCheck, onPressed: () { Navigator.of(context).pushNamed(ServiceRequestsPage.id); }, ), //if (_userProvider.user.type == UsersTypes.engineer) LandPageItem( // text: _subtitle.preventiveMaintenance, text: "Preventive Maintenance", icon: FontAwesomeIcons.personWalking, onPressed: () { Navigator.of(context).pushNamed(RegularVisitsPage.id); }, ), //if (_userProvider.user.type == UsersTypes.engineer) // LandPageItem( // text: _subtitle.preventiveMaintenance, // icon: FontAwesomeIcons.toolbox, // onPressed: (){ // Navigator.of(context).pushNamed(PreventiveMaintenanceVisitsPage.id); // }, // ), /// enable this condition when the nurse account works // if (_userProvider?.user != null && _userProvider?.user?.type != UsersTypes.engineer) LandPageItem( text: "Request Gas Refill", icon: FontAwesomeIcons.truckFast, onPressed: () { // Navigator.of(context).pushNamed(RequestGasRefill.id); Navigator.of(context).pushNamed(NewGasRefillRequestPage.routeName); }, ), LandPageItem( text: "Track Gas Refill", icon: Icons.content_paste_search, onPressed: () { Navigator.of(context).pushNamed(TrackGasRefillPage.id); }, ), LandPageItem( text: "Transfer Asset", icon: FontAwesomeIcons.rightLeft, onPressed: () { // Navigator.of(context).pushNamed(RequestDeviceTransfer.id); Navigator.of(context).pushNamed(NewTransferRequestPage.routeName); }, ), LandPageItem( text: "Track Asset Transfer", icon: FontAwesomeIcons.peopleCarryBox, onPressed: () { Navigator.of(context).pushNamed(TrackDeviceTransferPage.id); }, ), /// enable this condition when the nurse account works // if (_userProvider?.user != null && _userProvider?.user?.type != UsersTypes.normal_user) LandPageItem( text: "Create Sub Work Order", svgPath: "assets/images/sub_workorder_icon.svg", onPressed: () { Navigator.of(context).pushNamed(SearchSubWorkOrderPage.id); }, ), ], ), ], ), Align( alignment: Alignment.topLeft, child: ABackButton( icon: Icons.power_settings_new_rounded, onPressed: () async { bool result = await showDialog( context: context, builder: (_) => const AAlertDialog( // title: _subtitle.signOut, title: "Sign Out", // content: _subtitle.signOutAlert, content: "Are you sure you want to exit?", )); if (result) { // _devicesProvider.reset(); // _departmentsProvider.reset(); // _serviceRequestsProvider.reset(); // _regularVisitsProvider.reset(); // _preventiveMaintenanceVisitsProvider.reset(); _settingProvider.resetSettings(); _userProvider.reset(); Navigator.of(context).pop(); } }, ), ), Align( alignment: Alignment.topRight, child: Padding( padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4), child: AIconButton( iconData: Icons.menu, color: AColors.primaryColor, buttonSize: 42, backgroundColor: AColors.white, onPressed: () { _scaffoldKey.currentState.openEndDrawer(); }, ), ), ), ], ), ), endDrawer: Drawer( backgroundColor: Colors.white, child: Column( children: [ 40.height, Row( mainAxisAlignment: MainAxisAlignment.end, children: [ const Icon(Icons.clear).onPress(() => Navigator.pop(context)), ], ).paddingOnly(left: 4, right: 14), Row( children: [ Container( height: 50 * AppStyle.getScaleFactor(context), width: 50 * AppStyle.getScaleFactor(context), padding: EdgeInsets.all(4), decoration: BoxDecoration(border: Border.all(color: Theme.of(context).primaryColor, width: 2), shape: BoxShape.circle), child: ClipOval( child: ClipOval( child: Icon( Icons.person, size: 36, color: Theme.of(context).colorScheme.primary, ), ), ), ), 12.width, Text( _userProvider.user?.userName ?? "??", style: Theme.of(context).textTheme.headline6.copyWith( fontWeight: FontWeight.w600, ), textScaleFactor: AppStyle.getScaleFactor(context), ).expanded ], ).paddingOnly(left: 14, right: 14, top: 21, bottom: 21), Divider( height: 1, thickness: 1, color: AColors.greyEF, ), ListView( children: [ Row( children: [ Radio( value: "en", activeColor: AColors.grey3A, focusColor: AColors.grey3A, groupValue: _settingProvider.language, onChanged: (value) { _settingProvider.setLanguage(value); }), Text( "English", style: Theme.of(context).textTheme.bodyText1.copyWith(color: AColors.grey3A), textScaleFactor: AppStyle.getScaleFactor(context), ), Radio( value: "ar", activeColor: AColors.grey3A, focusColor: AColors.grey3A, groupValue: _settingProvider.language, onChanged: (value) { _settingProvider.setLanguage(value); }), Text( "عربي", style: Theme.of(context).textTheme.bodyText1.copyWith(color: AColors.grey3A), textScaleFactor: AppStyle.getScaleFactor(context), ), ], ), Row( children: [ Radio( value: true, activeColor: AColors.grey3A, focusColor: AColors.grey3A, groupValue: _settingProvider.language, onChanged: (value) { _settingProvider.setDarkTheme(value); }), Text( "Dark", style: Theme.of(context).textTheme.bodyText1.copyWith(color: AColors.grey3A), textScaleFactor: AppStyle.getScaleFactor(context), ), Radio( value: false, activeColor: AColors.grey3A, focusColor: AColors.grey3A, groupValue: _settingProvider.language, onChanged: (value) { _settingProvider.setDarkTheme(value); }), Text( "Light", style: Theme.of(context).textTheme.bodyText1.copyWith(color: AColors.grey3A), textScaleFactor: AppStyle.getScaleFactor(context), ), ], ), // DrawerItem( // icon: Icons.notifications, // title: _subtitle.notifications, // onPressed: () { // Navigator.of(context).pushNamed(NotificationsPage.id); // }, // ), DrawerItem( icon: Icons.mail, // title: _subtitle.email, title: "Email", onPressed: () { launch("mailto:customerservice@Test SA.com"); }, ), // DrawerItem( // icon: Icons.phone_in_talk, // title: "${_subtitle.hotLine} 15564", // onPressed: () { // launch("tel:15564"); // }, // ), // DrawerItem( // icon: FontAwesomeIcons.linkedinIn, // title: _subtitle.linkedIn, // onPressed: () { // launch("https://www.linkedin.com/company/Test SA/"); // }, // ), // DrawerItem( // icon: FontAwesomeIcons.globe, // title: _subtitle.ourWebsite, // onPressed: () { // launch("https://www.Test SA.com/"); // }, // ), DrawerItem( icon: Icons.share, // title: _subtitle.shareApp, title: "Share App", onPressed: () async { PackageInfo packageInfo = await PackageInfo.fromPlatform(); String shareLink = "\n https://play.google.com/store/apps/details?id=" + packageInfo.packageName + "\n https://apps.apple.com/us/app/"; Share.share(shareLink); }, ), ], ).expanded, Divider(height: 1, thickness: 1, color: AColors.greyEF), Row( mainAxisAlignment: MainAxisAlignment.center, children: [ Text( "Powered By Cloud Solutions", style: Theme.of(context).textTheme.headline6.copyWith(fontWeight: FontWeight.w500, color: AColors.grey3A, fontSize: 12), textScaleFactor: AppStyle.getScaleFactor(context), ), 6.width, Image.asset("assets/images/cloud_logo.png", width: 32, height: 32) ], ).paddingOnly(left: 20, right: 20, top: 8, bottom: 8), ], ), ), ), ); } }