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.
467 lines
19 KiB
Dart
467 lines
19 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:test_sa/controllers/localization/localization.dart';
|
|
import 'package:test_sa/controllers/notification/firebase_notification_manger.dart';
|
|
import 'package:test_sa/controllers/providers/api/departments_provider.dart';
|
|
import 'package:test_sa/controllers/providers/api/devices_provider.dart';
|
|
import 'package:test_sa/controllers/providers/api/preventive_maintenance_visits_provider.dart';
|
|
import 'package:test_sa/controllers/providers/api/regular_visits_provider.dart';
|
|
import 'package:test_sa/controllers/providers/api/service_requests_provider.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/models/enums/user_types.dart';
|
|
import 'package:test_sa/models/subtitle.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/request_device_transfer.dart';
|
|
import 'package:test_sa/views/pages/device_transfer/track_device_transfer.dart';
|
|
import 'package:test_sa/views/pages/user/gas_refill/request_gas_refill.dart';
|
|
import 'package:test_sa/views/pages/user/gas_refill/track_gas_refill.dart';
|
|
import 'package:test_sa/views/pages/user/notifications/notifications_page.dart';
|
|
import 'package:test_sa/views/pages/user/requests/create_request.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 '../../widgets/land_page/land_page_item.dart';
|
|
import 'profile_page.dart';
|
|
import 'requests/requests_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> {
|
|
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<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;
|
|
_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,
|
|
body: SafeArea(
|
|
child: Stack(
|
|
children: [
|
|
ListView(
|
|
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"),
|
|
),
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.all(16.0),
|
|
child: GridView.count(
|
|
shrinkWrap: true,
|
|
physics: const ClampingScrollPhysics(),
|
|
crossAxisCount: 2,
|
|
crossAxisSpacing: 5,
|
|
mainAxisSpacing: 5,
|
|
childAspectRatio: 1.15,
|
|
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);
|
|
},
|
|
),
|
|
],
|
|
),
|
|
),
|
|
SizedBox(height: 100,)
|
|
],
|
|
),
|
|
Align(
|
|
alignment: Alignment.topLeft,
|
|
child: ABackButton(
|
|
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();
|
|
},
|
|
),
|
|
),
|
|
),
|
|
Align(
|
|
alignment: Alignment.bottomCenter,
|
|
child: Container(
|
|
padding: EdgeInsets.all(16),
|
|
color: AColors.primaryColor,
|
|
child: Row(
|
|
children: [
|
|
AIconButton(
|
|
iconData: Icons.mail,
|
|
onPressed: (){
|
|
launch("mailto:customerservice@Test SA.com");
|
|
|
|
},
|
|
),
|
|
Spacer(),
|
|
// Expanded(
|
|
// child: MaterialButton(
|
|
// splashColor: AColors.secondaryColor.withOpacity(.5),
|
|
// child: Row(
|
|
// mainAxisAlignment: MainAxisAlignment.center,
|
|
// children: [
|
|
// Container(
|
|
// padding: EdgeInsets.all(12),
|
|
// decoration: BoxDecoration(
|
|
// borderRadius: BorderRadius.circular(
|
|
// 8 * AppStyle.getScaleFactor(context)
|
|
// ),
|
|
// color: AColors.onPrimaryColor
|
|
// ),
|
|
// child: Icon(
|
|
// Icons.phone_in_talk,
|
|
// color: AColors.primaryColor ,
|
|
// size: 32,
|
|
// ),
|
|
// ),
|
|
// SizedBox(
|
|
// width: 12 * AppStyle.getScaleFactor(context),
|
|
// ),
|
|
// Text(
|
|
// "${_subtitle.hotLine}\n ",
|
|
//
|
|
// style: Theme.of(context).textTheme.headline6.copyWith(
|
|
// color: AColors.white,
|
|
// letterSpacing: 2.75,
|
|
// fontWeight: FontWeight.bold
|
|
// ),
|
|
// ),
|
|
// ],
|
|
// ),
|
|
// onPressed: (){
|
|
// //launch("tel:15564");
|
|
// },
|
|
// ),
|
|
// ),
|
|
AIconButton(
|
|
iconData: Icons.notifications,
|
|
onPressed: (){
|
|
Navigator.of(context).pushNamed(NotificationsPage.id);
|
|
},
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
endDrawer: Drawer(
|
|
child: Container(
|
|
color: AColors.primaryColor,
|
|
child: Column(
|
|
children: [
|
|
SizedBox(
|
|
width: MediaQuery.of(context).size.width,
|
|
child: DrawerHeader(
|
|
decoration: BoxDecoration(
|
|
color: Theme.of(context).colorScheme.onPrimary,
|
|
),
|
|
padding: EdgeInsets.zero,
|
|
child: MaterialButton(
|
|
padding: EdgeInsets.zero,
|
|
onPressed: (){
|
|
Navigator.of(context).pop();
|
|
Navigator.of(context).pushNamed(ProfilePage.id);
|
|
},
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Container(
|
|
height: 100 * AppStyle.getScaleFactor(context),
|
|
width: 100 * 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: Icon(Icons.person,size: 72,color: Theme.of(context).colorScheme.primary,),
|
|
),
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.all(8.0),
|
|
child: FittedBox(
|
|
child: Text(
|
|
_userProvider.user?.userName ?? "??",
|
|
style: Theme.of(context).textTheme.headline6.copyWith(
|
|
fontWeight: FontWeight.normal,
|
|
),
|
|
textScaleFactor: AppStyle.getScaleFactor(context),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
Row(
|
|
children: [
|
|
Radio(
|
|
value: "en",
|
|
activeColor: Colors.white,
|
|
focusColor: Colors.white,
|
|
groupValue: _settingProvider.language,
|
|
onChanged: (value){
|
|
_settingProvider.setLanguage(value);
|
|
}
|
|
),
|
|
Text(
|
|
"English",
|
|
style: Theme.of(context).textTheme.bodyText1.copyWith(
|
|
color: Colors.white
|
|
),
|
|
textScaleFactor: AppStyle.getScaleFactor(context),
|
|
),
|
|
Radio(
|
|
value: "ar",
|
|
activeColor: Colors.white,
|
|
focusColor: Colors.white,
|
|
groupValue: _settingProvider.language,
|
|
onChanged: (value){
|
|
_settingProvider.setLanguage(value);
|
|
}
|
|
),
|
|
Text(
|
|
"عربي",
|
|
style: Theme.of(context).textTheme.bodyText1.copyWith(
|
|
color: Colors.white
|
|
),
|
|
textScaleFactor: AppStyle.getScaleFactor(context),
|
|
),
|
|
],
|
|
),
|
|
// 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(child: Center(child: Image.asset("assets/images/qr.jpeg"))),
|
|
Padding(
|
|
padding: const EdgeInsets.all(8.0),
|
|
child: Text(
|
|
"Powered By NewTrack",
|
|
style: Theme.of(context).textTheme.bodyText2.copyWith(
|
|
fontWeight: FontWeight.normal,
|
|
color: AColors.white
|
|
),
|
|
textScaleFactor: AppStyle.getScaleFactor(context),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|