|
|
|
@ -1,9 +1,12 @@
|
|
|
|
|
import 'dart:convert';
|
|
|
|
|
import 'dart:io';
|
|
|
|
|
import 'dart:typed_data';
|
|
|
|
|
|
|
|
|
|
import 'package:diplomaticquarterapp/config/config.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/config/shared_pref_kay.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/core/model/geofencing/requests/GeoZonesRequestModel.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/core/service/AuthenticatedUserObject.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/core/service/geofencing/GeofencingServices.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/models/Authentication/authenticated_user.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/models/Authentication/select_device_imei_res.dart';
|
|
|
|
@ -16,7 +19,11 @@ import 'package:diplomaticquarterapp/pages/medical/medical_profile_page.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/services/authentication/auth_provider.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/services/robo_search/event_provider.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/uitl/CalendarUtils.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/uitl/HMGNetworkConnectivity.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/uitl/HMG_Geofence.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/uitl/LocalNotification.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/uitl/PlatformBridge.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.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';
|
|
|
|
@ -44,24 +51,22 @@ class LandingPage extends StatefulWidget {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _LandingPageState extends State<LandingPage> with WidgetsBindingObserver {
|
|
|
|
|
var authProvider = new AuthProvider();
|
|
|
|
|
|
|
|
|
|
int currentTab = 0;
|
|
|
|
|
PageController pageController;
|
|
|
|
|
ProjectViewModel projectProvider;
|
|
|
|
|
ProjectViewModel projectViewModel;
|
|
|
|
|
var notificationCount = '';
|
|
|
|
|
|
|
|
|
|
///inject the user data
|
|
|
|
|
AuthenticatedUserObject authenticatedUserObject =
|
|
|
|
|
locator<AuthenticatedUserObject>();
|
|
|
|
|
AuthenticatedUserObject authenticatedUserObject = locator<AuthenticatedUserObject>();
|
|
|
|
|
|
|
|
|
|
final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
|
|
|
|
|
final authService = new AuthProvider();
|
|
|
|
|
var event = RobotProvider();
|
|
|
|
|
|
|
|
|
|
void _requestIOSPermissions() {
|
|
|
|
|
flutterLocalNotificationsPlugin
|
|
|
|
|
.resolvePlatformSpecificImplementation<
|
|
|
|
|
IOSFlutterLocalNotificationsPlugin>()
|
|
|
|
|
?.requestPermissions(
|
|
|
|
|
flutterLocalNotificationsPlugin.resolvePlatformSpecificImplementation<IOSFlutterLocalNotificationsPlugin>()?.requestPermissions(
|
|
|
|
|
alert: true,
|
|
|
|
|
badge: true,
|
|
|
|
|
sound: true,
|
|
|
|
@ -96,12 +101,7 @@ class _LandingPageState extends State<LandingPage> with WidgetsBindingObserver {
|
|
|
|
|
if (LandingPage.isOpenCallPage) {
|
|
|
|
|
if (!isPageNavigated) {
|
|
|
|
|
isPageNavigated = true;
|
|
|
|
|
Navigator.push(
|
|
|
|
|
context,
|
|
|
|
|
MaterialPageRoute(
|
|
|
|
|
builder: (context) => IncomingCall(
|
|
|
|
|
incomingCallData: LandingPage.incomingCallData)))
|
|
|
|
|
.then((value) {
|
|
|
|
|
Navigator.push(context, MaterialPageRoute(builder: (context) => IncomingCall(incomingCallData: LandingPage.incomingCallData))).then((value) {
|
|
|
|
|
isPageNavigated = false;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
@ -127,6 +127,7 @@ class _LandingPageState extends State<LandingPage> with WidgetsBindingObserver {
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
|
|
|
|
|
WidgetsBinding.instance.addObserver(this);
|
|
|
|
|
//setState(() {
|
|
|
|
|
AppGlobal.context = context;
|
|
|
|
@ -135,20 +136,35 @@ class _LandingPageState extends State<LandingPage> with WidgetsBindingObserver {
|
|
|
|
|
pageController = PageController(keepPage: true);
|
|
|
|
|
_firebaseMessaging.setAutoInitEnabled(true);
|
|
|
|
|
|
|
|
|
|
// HMG (Guest/Internet) Wifi Access [Zohaib Kambrani]
|
|
|
|
|
HMGNetworkConnectivity(context, () {
|
|
|
|
|
GifLoaderDialogUtils.showMyDialog(context);
|
|
|
|
|
PlatformBridge().connectHMGGuestWifi().then((value) => {GifLoaderDialogUtils.hideDialog(context)});
|
|
|
|
|
}).checkAndConnectIfNoInternet();
|
|
|
|
|
|
|
|
|
|
if (Platform.isIOS) {
|
|
|
|
|
_firebaseMessaging.requestNotificationPermissions();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_firebaseMessaging.getToken().then((String token) {
|
|
|
|
|
sharedPref.setString(PUSH_TOKEN, token);
|
|
|
|
|
if (token != null && DEVICE_TOKEN == "") {
|
|
|
|
|
DEVICE_TOKEN = token;
|
|
|
|
|
checkUserStatus(token);
|
|
|
|
|
}
|
|
|
|
|
requestPermissions();
|
|
|
|
|
}).catchError((err) {
|
|
|
|
|
print(err);
|
|
|
|
|
// Flip Permission Checks [Zohaib Kambrani]
|
|
|
|
|
requestPermissions().then((results) {
|
|
|
|
|
if (results[Permission.notification].isGranted)
|
|
|
|
|
_firebaseMessaging.getToken().then((String token) {
|
|
|
|
|
sharedPref.setString(PUSH_TOKEN, token);
|
|
|
|
|
if (token != null && DEVICE_TOKEN == "") {
|
|
|
|
|
DEVICE_TOKEN = token;
|
|
|
|
|
checkUserStatus(token);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (results[Permission.location].isGranted) ;
|
|
|
|
|
if (results[Permission.storage].isGranted) ;
|
|
|
|
|
if (results[Permission.camera].isGranted) ;
|
|
|
|
|
if (results[Permission.photos].isGranted) ;
|
|
|
|
|
if (results[Permission.accessMediaLocation].isGranted) ;
|
|
|
|
|
if (results[Permission.calendar].isGranted) ;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// //_firebase Background message handler
|
|
|
|
|
// _firebaseMessaging.configure(
|
|
|
|
@ -269,18 +285,14 @@ class _LandingPageState extends State<LandingPage> with WidgetsBindingObserver {
|
|
|
|
|
|
|
|
|
|
showDialogs(String message) {
|
|
|
|
|
ConfirmDialog dialog = new ConfirmDialog(
|
|
|
|
|
context: context,
|
|
|
|
|
confirmMessage: message,
|
|
|
|
|
okText: TranslationBase.of(context).confirm,
|
|
|
|
|
cancelText: TranslationBase.of(context).cancel_nocaps,
|
|
|
|
|
okFunction: () => {},
|
|
|
|
|
cancelFunction: () => {});
|
|
|
|
|
context: context, confirmMessage: message, okText: TranslationBase.of(context).confirm, cancelText: TranslationBase.of(context).cancel_nocaps, okFunction: () => {}, cancelFunction: () => {});
|
|
|
|
|
dialog.showAlertDialog(context);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void requestPermissions() async {
|
|
|
|
|
await [
|
|
|
|
|
Future<Map<Permission, PermissionStatus>> requestPermissions() async {
|
|
|
|
|
var permissionResults = [
|
|
|
|
|
Permission.location,
|
|
|
|
|
Permission.locationAlways,
|
|
|
|
|
Permission.storage,
|
|
|
|
|
Permission.camera,
|
|
|
|
|
Permission.photos,
|
|
|
|
@ -292,63 +304,24 @@ class _LandingPageState extends State<LandingPage> with WidgetsBindingObserver {
|
|
|
|
|
var permissionsGranted = await deviceCalendarPlugin.hasPermissions();
|
|
|
|
|
if (permissionsGranted.isSuccess && !permissionsGranted.data) {
|
|
|
|
|
permissionsGranted = await deviceCalendarPlugin.requestPermissions();
|
|
|
|
|
if (!permissionsGranted.isSuccess || !permissionsGranted.data) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!permissionsGranted.isSuccess || !permissionsGranted.data) {}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> _scheduleNotification() async {
|
|
|
|
|
var scheduledNotificationDateTime =
|
|
|
|
|
DateTime.now().add(Duration(seconds: 5));
|
|
|
|
|
var vibrationPattern = Int64List(4);
|
|
|
|
|
vibrationPattern[0] = 0;
|
|
|
|
|
vibrationPattern[1] = 1000;
|
|
|
|
|
vibrationPattern[2] = 5000;
|
|
|
|
|
vibrationPattern[3] = 2000;
|
|
|
|
|
|
|
|
|
|
var androidPlatformChannelSpecifics = AndroidNotificationDetails(
|
|
|
|
|
'your other channel id',
|
|
|
|
|
'your other channel name',
|
|
|
|
|
'your other channel description',
|
|
|
|
|
// icon: 'secondary_icon',
|
|
|
|
|
sound: RawResourceAndroidNotificationSound('slow_spring_board'),
|
|
|
|
|
largeIcon: DrawableResourceAndroidBitmap('sample_large_icon'),
|
|
|
|
|
vibrationPattern: vibrationPattern,
|
|
|
|
|
enableLights: true,
|
|
|
|
|
color: const Color.fromARGB(255, 255, 0, 0),
|
|
|
|
|
ledColor: const Color.fromARGB(255, 255, 0, 0),
|
|
|
|
|
ledOnMs: 1000,
|
|
|
|
|
ledOffMs: 500);
|
|
|
|
|
var iOSPlatformChannelSpecifics =
|
|
|
|
|
IOSNotificationDetails(sound: 'slow_spring_board.aiff');
|
|
|
|
|
// var platformChannelSpecifics = NotificationDetails(
|
|
|
|
|
// androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
|
|
|
|
|
// await flutterLocalNotificationsPlugin.schedule(
|
|
|
|
|
// 0,
|
|
|
|
|
// 'scheduled title',
|
|
|
|
|
// 'scheduled body',
|
|
|
|
|
// scheduledNotificationDateTime,
|
|
|
|
|
// platformChannelSpecifics);
|
|
|
|
|
return permissionResults;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
ProjectViewModel projectViewModel = Provider.of(context);
|
|
|
|
|
projectViewModel = Provider.of(context);
|
|
|
|
|
|
|
|
|
|
return Scaffold(
|
|
|
|
|
appBar: AppBar(
|
|
|
|
|
elevation: 0,
|
|
|
|
|
textTheme: TextTheme(
|
|
|
|
|
headline6:
|
|
|
|
|
TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
|
|
|
|
|
headline6: TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
|
|
|
|
|
),
|
|
|
|
|
title: Text(
|
|
|
|
|
getText(currentTab).toUpperCase(),
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
fontFamily: projectViewModel.isArabic ? 'Cairo' : 'WorkSans'),
|
|
|
|
|
style: TextStyle(fontWeight: FontWeight.bold, color: Colors.white, fontFamily: projectViewModel.isArabic ? 'Cairo' : 'WorkSans'),
|
|
|
|
|
// bold: true,
|
|
|
|
|
// color: Colors.white,
|
|
|
|
|
),
|
|
|
|
@ -379,7 +352,7 @@ class _LandingPageState extends State<LandingPage> with WidgetsBindingObserver {
|
|
|
|
|
notificationCount,
|
|
|
|
|
style: new TextStyle(
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
fontSize: projectViewModel.isArabic ? 8 : 9,
|
|
|
|
|
fontSize: projectViewModel.isArabic ? 8 : 9,
|
|
|
|
|
),
|
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
|
),
|
|
|
|
@ -462,28 +435,25 @@ class _LandingPageState extends State<LandingPage> with WidgetsBindingObserver {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void checkUserStatus(token) async {
|
|
|
|
|
authService
|
|
|
|
|
var result = await authService
|
|
|
|
|
.selectDeviceImei(token)
|
|
|
|
|
.then((SelectDeviceIMEIRES value) => setUserValues(value));
|
|
|
|
|
;
|
|
|
|
|
setUserValues(result);
|
|
|
|
|
registerGeofences();
|
|
|
|
|
if (await sharedPref.getObject(USER_PROFILE) != null) {
|
|
|
|
|
var data =
|
|
|
|
|
AuthenticatedUser.fromJson(await sharedPref.getObject(USER_PROFILE));
|
|
|
|
|
var data = AuthenticatedUser.fromJson(await sharedPref.getObject(USER_PROFILE));
|
|
|
|
|
if (data != null) {
|
|
|
|
|
authService
|
|
|
|
|
.registeredAuthenticatedUser(data, token, 0, 0)
|
|
|
|
|
.then((res) => {print(res)});
|
|
|
|
|
authService.registeredAuthenticatedUser(data, token, 0, 0).then((res) => {print(res)});
|
|
|
|
|
authService.getDashboard().then((value) => {
|
|
|
|
|
setState(() {
|
|
|
|
|
notificationCount = value['List_PatientDashboard']
|
|
|
|
|
[0]['UnreadPatientNotificationCount'].toString();
|
|
|
|
|
notificationCount = value['List_PatientDashboard'][0]['UnreadPatientNotificationCount'].toString();
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static Future<dynamic> myBackgroundMessageHandler(
|
|
|
|
|
Map<String, dynamic> message) async {
|
|
|
|
|
static Future<dynamic> myBackgroundMessageHandler(Map<String, dynamic> message) async {
|
|
|
|
|
Map<String, dynamic> myMap = new Map<String, dynamic>.from(message['data']);
|
|
|
|
|
if (message.containsKey('data')) {
|
|
|
|
|
print("myBackgroundMessageHandler Inside");
|
|
|
|
@ -499,7 +469,12 @@ class _LandingPageState extends State<LandingPage> with WidgetsBindingObserver {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setUserValues(value) async {
|
|
|
|
|
sharedPref.setObject(IMEI_USER_DATA, value);
|
|
|
|
|
if (value != null) sharedPref.setObject(IMEI_USER_DATA, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<dynamic> getUserInformation() async {
|
|
|
|
|
var userInfoJson = sharedPref.getObject(IMEI_USER_DATA);
|
|
|
|
|
return userInfoJson;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
checkValue(projectProvider) {
|
|
|
|
@ -507,4 +482,26 @@ class _LandingPageState extends State<LandingPage> with WidgetsBindingObserver {
|
|
|
|
|
_changeCurrentTab(2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
registerGeofences() async {
|
|
|
|
|
await locator<GeofencingServices>().getAllGeoZones(GeoZonesRequestModel());
|
|
|
|
|
|
|
|
|
|
void doIt() {
|
|
|
|
|
getUserInformation().then((value) {
|
|
|
|
|
if (value != null) projectViewModel.platformBridge().registerHmgGeofences();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (await Permission.location.isGranted) {
|
|
|
|
|
doIt();
|
|
|
|
|
} else {
|
|
|
|
|
[Permission.location].request().then((value) async {
|
|
|
|
|
if (await Permission.location.isGranted) {
|
|
|
|
|
doIt();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
requestPermissions().then((results) {});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|