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.
diplomatic-quarter/lib/pages/landing/landing_page.dart

671 lines
25 KiB
Dart

import 'dart:io';
import 'package:diplomaticquarterapp/config/config.dart';
4 years ago
import 'package:diplomaticquarterapp/config/shared_pref_kay.dart';
import 'package:diplomaticquarterapp/core/model/ImagesInfo.dart';
4 years ago
import 'package:diplomaticquarterapp/core/model/geofencing/requests/GeoZonesRequestModel.dart';
import 'package:diplomaticquarterapp/core/service/AuthenticatedUserObject.dart';
4 years ago
import 'package:diplomaticquarterapp/core/service/geofencing/GeofencingServices.dart';
import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart';
import 'package:diplomaticquarterapp/models/Appointments/toDoCountProviderModel.dart';
4 years ago
import 'package:diplomaticquarterapp/models/Authentication/authenticated_user.dart';
import 'package:diplomaticquarterapp/models/Authentication/select_device_imei_res.dart';
import 'package:diplomaticquarterapp/models/LiveCare/IncomingCallData.dart';
import 'package:diplomaticquarterapp/pages/BookAppointment/BookingOptions.dart';
import 'package:diplomaticquarterapp/pages/BookAppointment/Search.dart';
4 years ago
import 'package:diplomaticquarterapp/pages/DrawerPages/family/my-family.dart';
4 years ago
import 'package:diplomaticquarterapp/pages/ToDoList/ToDo.dart';
3 years ago
import 'package:diplomaticquarterapp/pages/landing/home_page_2.dart';
import 'package:diplomaticquarterapp/pages/livecare/incoming_call.dart';
3 years ago
import 'package:diplomaticquarterapp/pages/medical/medical_profile_page_new.dart';
import 'package:diplomaticquarterapp/services/authentication/auth_provider.dart';
import 'package:diplomaticquarterapp/services/family_files/family_files_provider.dart' as family;
4 years ago
import 'package:diplomaticquarterapp/services/robo_search/event_provider.dart';
import 'package:diplomaticquarterapp/theme/colors.dart';
4 years ago
import 'package:diplomaticquarterapp/uitl/HMGNetworkConnectivity.dart';
import 'package:diplomaticquarterapp/uitl/LocalNotification.dart';
4 years ago
import 'package:diplomaticquarterapp/uitl/PlatformBridge.dart';
import 'package:diplomaticquarterapp/uitl/app_toast.dart';
4 years ago
import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart';
4 years ago
import 'package:diplomaticquarterapp/uitl/location_util.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/widgets/bottom_navigation/bottom_nav_bar.dart';
import 'package:diplomaticquarterapp/widgets/buttons/floatingActionButton.dart';
4 years ago
import 'package:diplomaticquarterapp/widgets/dialogs/confirm_dialog.dart';
import 'package:diplomaticquarterapp/widgets/drawer/app_drawer_widget.dart';
3 years ago
import 'package:diplomaticquarterapp/widgets/others/not_auh_page.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:provider/provider.dart';
import '../../locator.dart';
4 years ago
import '../../routes.dart';
class LandingPage extends StatefulWidget {
3 years ago
static LandingPage shared;
_LandingPageState state;
3 years ago
LandingPage() {
LandingPage.shared = this;
}
static bool isOpenCallPage = false;
static IncomingCallData incomingCallData = new IncomingCallData();
@override
3 years ago
_LandingPageState createState() => state = _LandingPageState();
switchToDoFromHMGServices() {
state.changeCurrentTab(4);
}
}
class _LandingPageState extends State<LandingPage> with WidgetsBindingObserver {
4 years ago
var authProvider = new AuthProvider();
int currentTab = 0;
PageController pageController;
ProjectViewModel projectViewModel;
3 years ago
ToDoCountProviderModel model;
var notificationCount = '';
var themeNotifier;
DateTime currentBackPressTime;
3 years ago
bool _showBottomNavigationBar = true;
///inject the user data
AuthenticatedUserObject authenticatedUserObject = locator<AuthenticatedUserObject>();
4 years ago
final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
4 years ago
final authService = new AuthProvider();
3 years ago
4 years ago
var event = RobotProvider();
4 years ago
var familyFileProvider = family.FamilyFilesProvider();
void _requestIOSPermissions() {
flutterLocalNotificationsPlugin.resolvePlatformSpecificImplementation<IOSFlutterLocalNotificationsPlugin>()?.requestPermissions(
alert: true,
badge: true,
sound: true,
);
}
bool isPageNavigated = false;
4 years ago
LocationUtils locationUtils;
4 years ago
Future<bool> onWillPop() {
DateTime now = DateTime.now();
if (currentBackPressTime == null || now.difference(currentBackPressTime) > Duration(seconds: 2)) {
currentBackPressTime = now;
AppToast.showToast(message: TranslationBase.of(context).pressAgain);
return Future.value(false);
}
return Future.value(true);
}
3 years ago
changeCurrentTab(int tab) {
if (!projectViewModel.isLogin) {
if (tab == 3) {
List<ImagesInfo> imagesInfo = [];
imagesInfo.add(
ImagesInfo(
imageEn: 'https://hmgwebservices.com/Images/MobileApp/images-info-home/family-file/en/0.png',
imageAr: 'https://hmgwebservices.com/Images/MobileApp/images-info-home/family-file/ar/0.png'),
);
imagesInfo.add(
ImagesInfo(
imageEn: 'https://hmgwebservices.com/Images/MobileApp/images-info-home/family-file/en/1.png',
imageAr: 'https://hmgwebservices.com/Images/MobileApp/images-info-home/family-file/ar/1.png'),
);
Navigator.push(
context,
MaterialPageRoute(
builder: (cxt) => NotAutPage(
title: TranslationBase.of(context).myFamilyFiles,
description: TranslationBase.of(context).familyInfo,
infoList: [],
imagesInfo: imagesInfo,
icon: "assets/images/new/bottom_nav/family_files.svg",
),
),
);
return;
}
if (tab == 4) {
List<ImagesInfo> imagesInfo = [];
imagesInfo.add(
ImagesInfo(imageEn: 'https://hmgwebservices.com/Images/MobileApp/images-info-home/todo/en/0.png', imageAr: 'https://hmgwebservices.com/Images/MobileApp/images-info-home/todo/ar/0.png'));
Navigator.push(
context,
MaterialPageRoute(
builder: (cxt) => NotAutPage(
title: TranslationBase.of(context).todoList,
description: TranslationBase.of(context).infoTodo,
infoList: [],
imagesInfo: imagesInfo,
icon: "assets/images/new/bottom_nav/todo.svg",
),
),
);
return;
}
3 years ago
}
setState(() {
3 years ago
if (currentTab > 0 && tab == 2)
pageController.jumpToPage(0);
3 years ago
else if (tab != 0) {
if (tab == 4 && model.count == 0) {
3 years ago
AppToast.showErrorToast(message: TranslationBase.of(context).noBookedAppo);
3 years ago
} else {
pageController.jumpToPage(tab);
}
} else {
IS_VOICE_COMMAND_CLOSED = false;
3 years ago
pageController.jumpToPage(tab);
}
3 years ago
currentTab = tab;
});
}
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
super.didChangeAppLifecycleState(state);
var route = ModalRoute.of(context);
if (route != null) {}
4 years ago
//setState(() {
AppGlobal.context = context;
if (state == AppLifecycleState.resumed) {
if (LandingPage.isOpenCallPage) {
if (!isPageNavigated) {
isPageNavigated = true;
Navigator.push(context, MaterialPageRoute(builder: (context) => IncomingCall(incomingCallData: LandingPage.incomingCallData))).then((value) {
isPageNavigated = false;
});
4 years ago
}
}
}
4 years ago
if (state == AppLifecycleState.paused) {
isPageNavigated = false;
}
4 years ago
if (state == AppLifecycleState.inactive) {
isPageNavigated = false;
}
4 years ago
//});
}
@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}
@override
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
3 years ago
AppGlobal.context = context;
3 years ago
_requestIOSPermissions();
4 years ago
pageController = PageController(keepPage: true);
_firebaseMessaging.setAutoInitEnabled(true);
locationUtils = new LocationUtils(isShowConfirmDialog: false, context: context);
3 years ago
WidgetsBinding.instance.addPostFrameCallback((_) {
3 years ago
// locationUtils.getCurrentLocation();
3 years ago
if (projectViewModel.isLogin) {
familyFileProvider.getSharedRecordByStatus();
}
});
4 years ago
// HMG (Guest/Internet) Wifi Access [Zohaib Kambrani]
//for now commented to reduce this call will enable it when needed
// HMGNetworkConnectivity(context, () {
// GifLoaderDialogUtils.showMyDialog(context);
// PlatformBridge().connectHMGGuestWifi().then((value) => {GifLoaderDialogUtils.hideDialog(context)});
// }).checkAndConnectIfNoInternet();
if (Platform.isIOS) {
_firebaseMessaging.requestNotificationPermissions();
}
4 years ago
requestPermissions().then((results) {
_firebaseMessaging.getToken().then((String token) {
3 years ago
print("Firebase Token: " + token);
sharedPref.setString(PUSH_TOKEN, token);
if (token != null && DEVICE_TOKEN == "") {
DEVICE_TOKEN = token;
checkUserStatus(token);
if (projectViewModel.isLogin) this.getNotificationCount(DEVICE_TOKEN);
}
});
3 years ago
if (results[Permission.location].isGranted) {}
3 years ago
// if (results[Permission.storage].isGranted) ;
// if (results[Permission.camera].isGranted) ;
// if (results[Permission.photos].isGranted) ;
// if (results[Permission.accessMediaLocation].isGranted) ;
4 years ago
// if (results[Permission.calendar].isGranted) ;
});
3 years ago
4 years ago
requestPermissions();
3 years ago
4 years ago
// });
//
// //_firebase Background message handler
// _firebaseMessaging.configure(
// // onMessage: (Map<String, dynamic> message) async {
// // showDialog("onMessage: $message");
// // print("onMessage: $message");
// // print(message);
// // print(message['name']);
// // print(message['appointmentdate']);
// //
// // if (Platform.isIOS) {
// // if (message['is_call'] == "true") {
// // var route = ModalRoute.of(context);
// //
// // if (route != null) {
// // print(route.settings.name);
// // }
// //
// // Map<String, dynamic> myMap = new Map<String, dynamic>.from(message);
// // print(myMap);
// // LandingPage.isOpenCallPage = true;
// // LandingPage.incomingCallData = IncomingCallData.fromJson(myMap);
// // if (!isPageNavigated) {
// // isPageNavigated = true;
// // Navigator.push(
// // context,
// // MaterialPageRoute(
// // builder: (context) => IncomingCall(
// // incomingCallData: LandingPage.incomingCallData)))
// // .then((value) {
// // isPageNavigated = false;
// // });
// // }
// // } else {
// // print("Is Call Not Found iOS");
// // }
// // } else {
// // print("Is Call Not Found iOS");
// // }
// //
// // if (Platform.isAndroid) {
// // if (message['data'].containsKey("is_call")) {
// // var route = ModalRoute.of(context);
// //
// // if (route != null) {
// // print(route.settings.name);
// // }
// //
// // Map<String, dynamic> myMap =
// // new Map<String, dynamic>.from(message['data']);
// // print(myMap);
// // LandingPage.isOpenCallPage = true;
// // LandingPage.incomingCallData = IncomingCallData.fromJson(myMap);
// // if (!isPageNavigated) {
// // isPageNavigated = true;
// // Navigator.push(
// // context,
// // MaterialPageRoute(
// // builder: (context) => IncomingCall(
// // incomingCallData: LandingPage.incomingCallData)))
// // .then((value) {
// // isPageNavigated = false;
// // });
// // }
// // } else {
// // print("Is Call Not Found Android");
// // }
// // } else {
// // print("Is Call Not Found Android");
// // }
// // },
// // onBackgroundMessage: Platform.isIOS ? null : myBackgroundMessageHandler,
// // onLaunch: (Map<String, dynamic> message) async {
// // print("onLaunch: $message");
// // showDialog("onLaunch: $message");
// // },
// // onResume: (Map<String, dynamic> message) async {
// // print("onResume: $message");
// // print(message);
// // print(message['name']);
// // print(message['appointmentdate']);
// //
// // showDialog("onResume: $message");
// //
// // if (Platform.isIOS) {
// // if (message['is_call'] == "true") {
// // var route = ModalRoute.of(context);
// //
// // if (route != null) {
// // print(route.settings.name);
// // }
// //
// // Map<String, dynamic> myMap =
// // new Map<String, dynamic>.from(message);
// // print(myMap);
// // LandingPage.isOpenCallPage = true;
// // LandingPage.incomingCallData = IncomingCallData.fromJson(myMap);
// // if (!isPageNavigated) {
// // isPageNavigated = true;
// // Navigator.push(
// // context,
// // MaterialPageRoute(
// // builder: (context) => IncomingCall(
// // incomingCallData: LandingPage.incomingCallData)))
// // .then((value) {
// // isPageNavigated = false;
// // });
// // }
// // } else {
// // print("Is Call Not Found iOS");
// // }
// // } else {
// // print("Is Call Not Found iOS");
// // }
// // },
// );
}
showDialogs(String message) {
4 years ago
ConfirmDialog dialog = new ConfirmDialog(
context: context, confirmMessage: message, okText: TranslationBase.of(context).confirm, cancelText: TranslationBase.of(context).cancel_nocaps, okFunction: () => {}, cancelFunction: () => {});
4 years ago
dialog.showAlertDialog(context);
}
4 years ago
Future<Map<Permission, PermissionStatus>> requestPermissions() async {
var permissionResults = [
Permission.location,
4 years ago
Permission.locationAlways,
3 years ago
// Permission.storage,
// Permission.camera,
// Permission.photos,
// Permission.notification,
// Permission.accessMediaLocation,
4 years ago
// Permission.calendar,
Permission.activityRecognition
].request();
4 years ago
// var permissionsGranted = await deviceCalendarPlugin.hasPermissions();
// if (permissionsGranted.isSuccess && !permissionsGranted.data) {
// permissionsGranted = await deviceCalendarPlugin.requestPermissions();
// if (!permissionsGranted.isSuccess || !permissionsGranted.data) {}
// }
4 years ago
return permissionResults;
}
static Future<dynamic> myBackgroundMessageHandler(Map<String, dynamic> message) async {
Map<String, dynamic> myMap = new Map<String, dynamic>.from(message['data']);
if (message.containsKey('data')) {
LandingPage.incomingCallData = IncomingCallData.fromJson(myMap);
LandingPage.isOpenCallPage = true;
}
if (message.containsKey('notification')) {
final dynamic notification = message['notification'];
}
}
void setUserValues(value) async {
if (value != null) sharedPref.setObject(IMEI_USER_DATA, value);
}
Future<dynamic> getUserInformation() async {
var userInfoJson = sharedPref.getObject(IMEI_USER_DATA);
return userInfoJson;
4 years ago
}
4 years ago
checkValue(projectProvider) {
if (projectProvider.searchValue != null) {
3 years ago
changeCurrentTab(2);
}
}
4 years ago
registerGeofences() async {
await locator<GeofencingServices>().getAllGeoZones(GeoZonesRequestModel());
4 years ago
void doIt() {
getUserInformation().then((value) {
if (value != null) projectViewModel.platformBridge().registerHmgGeofences();
4 years ago
});
}
4 years ago
if (await Permission.location.isGranted) {
doIt();
} else {
[Permission.location].request().then((value) async {
if (await Permission.location.isGranted) {
doIt();
}
});
}
4 years ago
}
4 years ago
login() async {
var data = await sharedPref.getObject(IMEI_USER_DATA);
sharedPref.remove(REGISTER_DATA_FOR_LOGIIN);
if (data != null) {
Navigator.of(context).pushNamed(CONFIRM_LOGIN);
} else {
4 years ago
GifLoaderDialogUtils.showMyDialog(context);
authService.selectDeviceImei(DEVICE_TOKEN).then((SelectDeviceIMEIRES value) {
4 years ago
GifLoaderDialogUtils.hideDialog(context);
if (value != null) {
setUserValues(value);
Navigator.of(context).pushNamed(CONFIRM_LOGIN);
} else {
Navigator.of(context).pushNamed(
WELCOME_LOGIN,
);
}
4 years ago
}).catchError((err) {
GifLoaderDialogUtils.hideDialog(context);
Navigator.of(context).pushNamed(
WELCOME_LOGIN,
);
});
}
4 years ago
}
4 years ago
getNotificationCount(token) async {
if (await sharedPref.getObject(USER_PROFILE) != null) {
var data = AuthenticatedUser.fromJson(await sharedPref.getObject(USER_PROFILE));
4 years ago
if (data != null) {
3 years ago
// authService
// .registeredAuthenticatedUser(data, token, 0, 0)
// .then((res) => {print(res)});
authService.getDashboard().then((value) => {
3 years ago
if (value != null)
{
setState(() {
notificationCount =
value['List_PatientDashboard'][0]['UnreadPatientNotificationCount'] > 99 ? '99+' : value['List_PatientDashboard'][0]['UnreadPatientNotificationCount'].toString();
3 years ago
sharedPref.setString(NOTIFICATION_COUNT, notificationCount);
})
}
});
4 years ago
}
}
}
@override
Widget build(BuildContext context) {
4 years ago
projectViewModel = Provider.of(context);
3 years ago
model = Provider.of<ToDoCountProviderModel>(context);
3 years ago
return Scaffold(
appBar: PreferredSize(
preferredSize: Size.fromHeight(currentTab == 0 ? 45 : 0.0),
child: AppBar(
elevation: 0,
backgroundColor: CustomColors.backgroudGreyColor,
textTheme: TextTheme(
headline6: TextStyle(color: Theme.of(context).textTheme.headline1.color, fontWeight: FontWeight.bold),
),
title: Text(
getText(currentTab).toUpperCase(),
style: TextStyle(
fontWeight: FontWeight.bold,
color: currentTab == 0 ? CustomColors.backgroudGreyColor : Theme.of(context).textTheme.headline1.color,
3 years ago
fontFamily: projectViewModel.isArabic ? 'Cairo' : 'Poppins'),
// bold: true,
),
leading: Builder(
builder: (BuildContext context) {
return new Stack(
children: <Widget>[
currentTab == 0
? IconButton(
icon: SvgPicture.asset("assets/images/new/menu.svg"),
color: Theme.of(context).textTheme.headline1.color,
onPressed: () => Scaffold.of(context).openDrawer(),
)
: IconButton(
icon: Icon(Icons.arrow_back),
onPressed: () {
setState(() {
currentTab = 0;
});
pageController.jumpToPage(0);
},
),
notificationCount != ''
? new Positioned(
right: projectViewModel.isArabic ? 35 : 0,
top: 5,
child: new Container(
padding: EdgeInsets.all(4),
decoration: new BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(20),
),
constraints: BoxConstraints(
minWidth: 20,
minHeight: 20,
),
child: new Text(
notificationCount,
style: new TextStyle(
color: Colors.white,
fontSize: projectViewModel.isArabic ? 8 : 9,
),
textAlign: TextAlign.center,
),
),
)
: SizedBox()
],
);
},
),
actions: [
// IconButton(
// //iconSize: 70,
// icon: Icon(
// projectViewModel.isLogin ? Icons.settings : Icons.login,
// color: Theme.of(context).textTheme.headline1.color,
// ),
// onPressed: () {
// if (projectViewModel.isLogin)
// Navigator.of(context).pushNamed(
// SETTINGS,
// );
// else
// login();
// }, //do something,
// )
],
centerTitle: true,
),
),
4 years ago
drawer: SafeArea(child: AppDrawer()),
extendBody: true,
body: WillPopScope(
onWillPop: onWillPop,
child: PageView(
physics: NeverScrollableScrollPhysics(),
controller: pageController,
children: [
HomePage2(
goToMyProfile: () {
changeCurrentTab(1);
},
onLoginClick: () {
login();
},
),
MedicalProfilePageNew(),
Search(),
MyFamily(isAppbarVisible: false),
ToDo(isShowAppBar: false),
], // Please do not remove the BookingOptions from this array
),
),
4 years ago
bottomNavigationBar: BottomNavBar(
3 years ago
changeIndex: changeCurrentTab,
4 years ago
index: currentTab,
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
floatingActionButton: (projectViewModel.havePrivilege(34) && currentTab == 0)
? FloatingButton(
elevation: true,
onTap: () {
changeCurrentTab(2);
})
: null);
}
4 years ago
triggerRobot() {
4 years ago
event.setValue({"isRobot": 'true'});
4 years ago
}
getText(currentTab) {
switch (currentTab) {
case 0:
return TranslationBase.of(context).home;
case 1:
return TranslationBase.of(context).medicalProfile;
case 2:
return TranslationBase.of(context).bookAppo;
4 years ago
case 5:
return TranslationBase.of(context).bookAppo;
case 3:
return TranslationBase.of(context).services;
case 4:
4 years ago
return TranslationBase.of(context).bookAppo;
}
}
void checkUserStatus(token) async {
authService.selectDeviceImei(token).then((SelectDeviceIMEIRES value) => setUserValues(value));
if (projectViewModel.isLoading == true) {
var data = AuthenticatedUser.fromJson(await sharedPref.getObject(USER_PROFILE));
if (data != null) {
authService.registeredAuthenticatedUser(data, token, 0, 0).then((res) => {});
authService.getDashboard().then((value) => {
setState(() {
if (value != null) {
notificationCount = value['List_PatientDashboard'][0]['UnreadPatientNotificationCount'].toString();
}
})
});
}
}
4 years ago
}
}