You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
398 lines
16 KiB
Dart
398 lines
16 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
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:url_launcher/url_launcher.dart';
|
|
|
|
import '../../../controllers/localization/localization.dart';
|
|
import '../../../controllers/notification/firebase_notification_manger.dart';
|
|
import '../../../controllers/providers/api/departments_provider.dart';
|
|
import '../../../controllers/providers/api/devices_provider.dart';
|
|
import '../../../controllers/providers/api/preventive_maintenance_visits_provider.dart';
|
|
import '../../../controllers/providers/api/regular_visits_provider.dart';
|
|
import '../../../controllers/providers/api/service_requests_provider.dart';
|
|
import '../../../controllers/providers/api/user_provider.dart';
|
|
import '../../../controllers/providers/settings/setting_provider.dart';
|
|
import '../../../extensions/int_extensions.dart';
|
|
import '../../../extensions/widget_extensions.dart';
|
|
import '../../../models/enums/user_types.dart';
|
|
import '../../../models/subtitle.dart';
|
|
import '../../app_style/colors.dart';
|
|
import '../../app_style/sizing.dart';
|
|
import '../../widgets/buttons/app_back_button.dart';
|
|
import '../../widgets/buttons/app_icon_button.dart';
|
|
import '../../widgets/dialogs/dialog.dart';
|
|
import '../../widgets/drawer/drawer_item.dart';
|
|
import '../../widgets/land_page/land_page_item.dart';
|
|
import '../device_transfer/request_device_transfer.dart';
|
|
import '../device_transfer/track_device_transfer.dart';
|
|
import 'gas_refill/request_gas_refill.dart';
|
|
import 'gas_refill/track_gas_refill.dart';
|
|
import 'notifications/notifications_page.dart';
|
|
import 'requests/create_request.dart';
|
|
import 'requests/requests_page.dart';
|
|
import 'visits/regular_visits_page.dart';
|
|
|
|
class LandPage extends StatefulWidget {
|
|
static const String id = "/land-page";
|
|
|
|
const LandPage({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
State<LandPage> createState() => _LandPageState();
|
|
}
|
|
|
|
class _LandPageState extends State<LandPage> {
|
|
late double _height;
|
|
late double _width;
|
|
late UserProvider _userProvider;
|
|
late SettingProvider _settingProvider;
|
|
late DepartmentsProvider _departmentsProvider;
|
|
late DevicesProvider _devicesProvider;
|
|
late double _buttonHeight;
|
|
late bool firstTime = true;
|
|
late ServiceRequestsProvider _serviceRequestsProvider;
|
|
late PreventiveMaintenanceVisitsProvider _preventiveMaintenanceVisitsProvider;
|
|
late RegularVisitsProvider _regularVisitsProvider;
|
|
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
|
|
|
|
@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.toString();
|
|
_height = MediaQuery.of(context).size.height;
|
|
_width = MediaQuery.of(context).size.width;
|
|
_settingProvider = Provider.of<SettingProvider>(context);
|
|
_userProvider = Provider.of<UserProvider>(context);
|
|
_departmentsProvider = Provider.of<DepartmentsProvider>(context);
|
|
_devicesProvider = Provider.of<DevicesProvider>(context);
|
|
_serviceRequestsProvider = Provider.of<ServiceRequestsProvider>(context);
|
|
_preventiveMaintenanceVisitsProvider = Provider.of<PreventiveMaintenanceVisitsProvider>(context);
|
|
_regularVisitsProvider = Provider.of<RegularVisitsProvider>(context);
|
|
Subtitle _subtitle = AppLocalization.of(context)!.subtitle!;
|
|
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: (_) => AAlertDialog(
|
|
title: _subtitle.exit,
|
|
content: _subtitle.exitAlert,
|
|
));
|
|
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: [
|
|
if (_userProvider.user!.type == UsersTypes.normal_user)
|
|
LandPageItem(
|
|
text: _subtitle.newServiceRequest,
|
|
icon: FontAwesomeIcons.tools,
|
|
onPressed: () {
|
|
Navigator.of(context).pushNamed(CreateRequestPage.id);
|
|
},
|
|
),
|
|
LandPageItem(
|
|
text: _subtitle.trackServiceRequest,
|
|
icon: FontAwesomeIcons.tasks,
|
|
onPressed: () {
|
|
Navigator.of(context).pushNamed(ServiceRequestsPage.id);
|
|
},
|
|
),
|
|
//if (_userProvider.user.type == UsersTypes.engineer)
|
|
LandPageItem(
|
|
text: _subtitle.preventiveMaintenance,
|
|
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);
|
|
// },
|
|
// ),
|
|
if (_userProvider.user?.type != UsersTypes.engineer)
|
|
LandPageItem(
|
|
text: "Request Gas Refill",
|
|
icon: FontAwesomeIcons.truckFast,
|
|
onPressed: () {
|
|
Navigator.of(context).pushNamed(RequestGasRefill.id);
|
|
},
|
|
),
|
|
LandPageItem(
|
|
text: "Track Gas Refill",
|
|
icon: Icons.content_paste_search,
|
|
onPressed: () {
|
|
Navigator.of(context).pushNamed(TrackGasRefillPage.id);
|
|
},
|
|
),
|
|
LandPageItem(
|
|
text: "transfer Device",
|
|
icon: FontAwesomeIcons.rightLeft,
|
|
onPressed: () {
|
|
Navigator.of(context).pushNamed(RequestDeviceTransfer.id);
|
|
},
|
|
),
|
|
LandPageItem(
|
|
text: "Track Device Transfer",
|
|
icon: FontAwesomeIcons.peopleCarryBox,
|
|
onPressed: () {
|
|
Navigator.of(context).pushNamed(TrackDeviceTransferPage.id);
|
|
},
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
Align(
|
|
alignment: Alignment.topLeft,
|
|
child: ABackButton(
|
|
icon: Icons.power_settings_new_rounded,
|
|
onPressed: () async {
|
|
bool result = await showDialog(
|
|
context: context,
|
|
builder: (_) => AAlertDialog(
|
|
title: _subtitle.signOut,
|
|
content: _subtitle.signOutAlert,
|
|
));
|
|
if (result) {
|
|
_devicesProvider.reset();
|
|
_departmentsProvider.reset();
|
|
_serviceRequestsProvider.reset();
|
|
_regularVisitsProvider.reset();
|
|
_preventiveMaintenanceVisitsProvider.reset();
|
|
_settingProvider.resetSettings();
|
|
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),
|
|
),
|
|
],
|
|
),
|
|
DrawerItem(
|
|
icon: Icons.notifications,
|
|
title: _subtitle.notifications,
|
|
onPressed: () {
|
|
Navigator.of(context).pushNamed(NotificationsPage.id);
|
|
},
|
|
),
|
|
DrawerItem(
|
|
icon: Icons.mail,
|
|
title: _subtitle.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,
|
|
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 NewTrack",
|
|
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/qr.jpeg", width: 32, height: 32, color: AColors.grey3A)
|
|
],
|
|
).paddingOnly(left: 20, right: 20, top: 8, bottom: 8),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|