From 162b2fd22a7830fbbe20b53d7bd246ad4e0974a1 Mon Sep 17 00:00:00 2001 From: haroon amjad Date: Mon, 12 Feb 2024 09:43:29 +0300 Subject: [PATCH] updates --- lib/config/config.dart | 4 +- lib/main.dart | 4 -- lib/pages/landing/landing_page.dart | 3 ++ lib/splashPage.dart | 3 ++ lib/uitl/LocalNotification.dart | 71 +++++++++++++++++------------ 5 files changed, 50 insertions(+), 35 deletions(-) diff --git a/lib/config/config.dart b/lib/config/config.dart index 4386f96f..8e5bdc7b 100644 --- a/lib/config/config.dart +++ b/lib/config/config.dart @@ -21,8 +21,8 @@ var PACKAGES_ORDERS = '/api/orders'; var PACKAGES_ORDER_HISTORY = '/api/orders/items'; var PACKAGES_TAMARA_OPT = '/api/orders/paymentoptions/tamara'; // var BASE_URL = 'http://10.50.100.198:4422/'; -// var BASE_URL = 'https://uat.hmgwebservices.com/'; -var BASE_URL = 'https://hmgwebservices.com/'; +var BASE_URL = 'https://uat.hmgwebservices.com/'; +// var BASE_URL = 'https://hmgwebservices.com/'; // var BASE_URL = 'http://10.20.200.111:1010/'; // var BASE_URL = 'https://uat.hmgwebservices.com/'; // var BASE_URL = 'https://hmgwebservices.com/'; diff --git a/lib/main.dart b/lib/main.dart index 4be8957b..b740b661 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -81,10 +81,6 @@ class _MyApp extends State { Widget build(BuildContext context) { PlatformBridge.init(context); - LocalNotification.init(onNotificationClick: (payload) { - LocalNotification.getInstance().showNow(title: "Payload", subtitle: payload, payload: payload); - }); - // SystemChrome.setPreferredOrientations([ // DeviceOrientation.portraitUp, // DeviceOrientation.portraitDown, diff --git a/lib/pages/landing/landing_page.dart b/lib/pages/landing/landing_page.dart index d0e4f526..683ddc6d 100644 --- a/lib/pages/landing/landing_page.dart +++ b/lib/pages/landing/landing_page.dart @@ -303,6 +303,9 @@ class _LandingPageState extends State with WidgetsBindingObserver { int languageID = Provider.of(context, listen: false).isArabic ? 1 : 2; familyFileProvider.getSharedRecordByStatus(languageID); } + // Future.delayed(Duration(seconds: 3)).then((result) async { + // LocalNotification.getInstance().showNow(title: "Payload Update", subtitle: "Payload Update", payload: "Payload Update"); + // }); }); PayfortViewModel payfortViewModel = context.read(); diff --git a/lib/splashPage.dart b/lib/splashPage.dart index 778ab6ff..68580dc9 100644 --- a/lib/splashPage.dart +++ b/lib/splashPage.dart @@ -6,6 +6,7 @@ import 'package:diplomaticquarterapp/config/shared_pref_kay.dart'; import 'package:diplomaticquarterapp/pages/landing/landing_page.dart'; import 'package:diplomaticquarterapp/theme/theme_notifier.dart'; import 'package:diplomaticquarterapp/theme/theme_value.dart'; +import 'package:diplomaticquarterapp/uitl/LocalNotification.dart'; import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart'; import 'package:diplomaticquarterapp/uitl/push-notification-handler.dart'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; @@ -37,6 +38,8 @@ class _SplashScreenState extends State { Duration(seconds: 1, milliseconds: 500), () async { await loadPrivilege().then((value) { + LocalNotification.init(onNotificationClick: (payload) {}); + // LocalNotification.getInstance().showNow(title: "Payload", subtitle: "Subtitle", payload: "Payload"); if(!_privilegeService.hasError) { Navigator.of(context).pushReplacement( MaterialPageRoute( diff --git a/lib/uitl/LocalNotification.dart b/lib/uitl/LocalNotification.dart index 9e0cd11b..1a3f2bea 100644 --- a/lib/uitl/LocalNotification.dart +++ b/lib/uitl/LocalNotification.dart @@ -31,25 +31,27 @@ class LocalNotification { _initialize() async { try { var initializationSettingsAndroid = new AndroidInitializationSettings('app_icon'); - // var initializationSettingsIOS = DarwinInitializationSettings(onDidReceiveLocalNotification: null); - // var initializationSettings = InitializationSettings(android: initializationSettingsAndroid, iOS: initializationSettingsIOS); - // await flutterLocalNotificationsPlugin.initialize( - // initializationSettings, - // onDidReceiveNotificationResponse: (NotificationResponse notificationResponse) { - // switch (notificationResponse.notificationResponseType) { - // case NotificationResponseType.selectedNotification: - // // selectNotificationStream.add(notificationResponse.payload); - // break; - // case NotificationResponseType.selectedNotificationAction: - // // if (notificationResponse.actionId == navigationActionId) { - // // selectNotificationStream.add(notificationResponse.payload); - // // } - // break; - // } - // }, - // onDidReceiveBackgroundNotificationResponse: notificationTapBackground, - // ); - } catch (ex) {} + var initializationSettingsIOS = DarwinInitializationSettings(onDidReceiveLocalNotification: null); + var initializationSettings = InitializationSettings(android: initializationSettingsAndroid, iOS: initializationSettingsIOS); + await flutterLocalNotificationsPlugin.initialize( + initializationSettings, + onDidReceiveNotificationResponse: (NotificationResponse notificationResponse) { + switch (notificationResponse.notificationResponseType) { + case NotificationResponseType.selectedNotification: + // selectNotificationStream.add(notificationResponse.payload); + break; + case NotificationResponseType.selectedNotificationAction: + // if (notificationResponse.actionId == navigationActionId) { + // selectNotificationStream.add(notificationResponse.payload); + // } + break; + } + }, + // onDidReceiveBackgroundNotificationResponse: notificationTapBackground, + ); + } catch (ex) { + print(ex.toString()); + } // flutterLocalNotificationsPlugin.initialize(initializationSettings, onDidReceiveNotificationResponse: (NotificationResponse notificationResponse) // { // switch (notificationResponse.notificationResponseType) { @@ -96,15 +98,26 @@ class LocalNotification { } Future showNow({@required String title, @required String subtitle, String payload}) { - // Future.delayed(Duration(seconds: 1)).then((result) async { - // var androidPlatformChannelSpecifics = AndroidNotificationDetails('com.hmg.local_notification', 'HMG', - // channelDescription: 'HMG', importance: Importance.max, priority: Priority.high, ticker: 'ticker', vibrationPattern: _vibrationPattern()); - // var iOSPlatformChannelSpecifics = DarwinNotificationDetails(); - // var platformChannelSpecifics = NotificationDetails(android: androidPlatformChannelSpecifics, iOS: iOSPlatformChannelSpecifics); - // await flutterLocalNotificationsPlugin.show(_randomNumber(), title, subtitle, platformChannelSpecifics, payload: payload).catchError((err) { - // print(err); - // }); - // }); + Future.delayed(Duration(seconds: 1)).then((result) async { + var androidPlatformChannelSpecifics = AndroidNotificationDetails( + 'com.hmg.local_notification', + 'HMG', + channelDescription: 'HMG', + importance: Importance.max, + priority: Priority.high, + ticker: 'ticker', + vibrationPattern: _vibrationPattern(), + ongoing: true, + autoCancel: false, + usesChronometer: true, + when: DateTime.now().millisecondsSinceEpoch - 120 * 1000, + ); + var iOSPlatformChannelSpecifics = DarwinNotificationDetails(); + var platformChannelSpecifics = NotificationDetails(android: androidPlatformChannelSpecifics, iOS: iOSPlatformChannelSpecifics); + await flutterLocalNotificationsPlugin.show(25613, title, subtitle, platformChannelSpecifics, payload: payload).catchError((err) { + print(err); + }); + }); } Future scheduleNotification({@required DateTime scheduledNotificationDateTime, @required String title, @required String description}) async { @@ -115,7 +128,7 @@ class LocalNotification { vibrationPattern[2] = 5000; vibrationPattern[3] = 2000; - // var androidPlatformChannelSpecifics = AndroidNotificationDetails('active-prescriptions', 'ActivePrescriptions', + // var androidPlatformChannelSpecifics = AndroidNotificationDetails('active-prescriptions', 'ActivePrescriptions', // channelDescription: 'ActivePrescriptionsDescription', // // icon: 'secondary_icon', // sound: RawResourceAndroidNotificationSound('slow_spring_board'),