diff --git a/ios/Runner/Info.plist b/ios/Runner/Info.plist
index e326d8f..e7b7e3b 100644
--- a/ios/Runner/Info.plist
+++ b/ios/Runner/Info.plist
@@ -50,6 +50,7 @@
This app requires photo library access to select image as document & upload it.
UIBackgroundModes
+ fetch
remote-notification
FirebaseAppDelegateProxyEnabled
diff --git a/lib/classes/notifications.dart b/lib/classes/notifications.dart
index b7d7988..8f5308d 100644
--- a/lib/classes/notifications.dart
+++ b/lib/classes/notifications.dart
@@ -1,12 +1,13 @@
import 'dart:convert';
import 'dart:io';
import 'package:firebase_messaging/firebase_messaging.dart';
+import 'package:flutter/foundation.dart';
+import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:mohem_flutter_app/app_state/app_state.dart';
import 'package:mohem_flutter_app/main.dart';
import 'package:permission_handler/permission_handler.dart';
-//final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
-
+final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
class AppNotifications {
static final AppNotifications _instance = AppNotifications._internal();
@@ -15,45 +16,63 @@ class AppNotifications {
factory AppNotifications() => _instance;
- // Future requestPermissions() async {
- // if (Platform.isIOS) {
- // await flutterLocalNotificationsPlugin.resolvePlatformSpecificImplementation()?.requestPermissions(alert: true, badge: true, sound: true);
- // } else if (Platform.isAndroid) {
- // AndroidFlutterLocalNotificationsPlugin? androidImplementation = flutterLocalNotificationsPlugin.resolvePlatformSpecificImplementation();
- // bool? granted = await androidImplementation?.requestPermission();
- // if (granted == false) {
- // print("-------------------- Permission Granted ------------------------");
- // print(granted);
- // await Permission.notification.request();
- // }
- // }
- // }
-
- // Future isAndroidPermGranted() async {
- // if (Platform.isAndroid) {
- // bool granted = await flutterLocalNotificationsPlugin.resolvePlatformSpecificImplementation()?.areNotificationsEnabled() ?? false;
- // }
- // }
-
- void initNotification(String? firebaseToken) async {
- // await requestPermissions();
- AppState().deviceNotificationToken = firebaseToken;
- // await Permission.notification.isDenied.then((value) {
- // if (value) {
- // Permission.notification.request();
- // }
- // });
+ Future requestPermissions() async {
+ if (Platform.isIOS) {
+ await flutterLocalNotificationsPlugin.resolvePlatformSpecificImplementation()?.requestPermissions(alert: true, badge: true, sound: true);
+ } else if (Platform.isAndroid) {
+ AndroidFlutterLocalNotificationsPlugin? androidImplementation = flutterLocalNotificationsPlugin.resolvePlatformSpecificImplementation();
+ bool? granted = await androidImplementation?.requestPermission();
+ if (granted == false) {
+ if (kDebugMode) {
+ print("-------------------- Permission Granted ------------------------");
+ print(granted);
+ }
+ await Permission.notification.request();
+ }
+ }
+ }
+
+ void init(String? firebaseToken) async {
+ await requestPermissions();
+ AppState().setDeviceToken = firebaseToken;
+ await Permission.notification.isDenied.then((bool value) {
+ if (value) {
+ Permission.notification.request();
+ }
+ });
RemoteMessage? initialMessage = await FirebaseMessaging.instance.getInitialMessage();
+
if (initialMessage != null) _handleMessage(initialMessage);
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
if (message.notification != null) _handleMessage(message);
});
+
FirebaseMessaging.onMessageOpenedApp.listen(_handleMessage);
+
+ FirebaseMessaging.onBackgroundMessage(backgroundMessageHandler);
+
+ FirebaseMessaging.instance.onTokenRefresh.listen((String token) {
+ AppState().setDeviceToken = token;
+ });
}
void _handleMessage(RemoteMessage message) {
- print("Handle Message");
+ if (kDebugMode) {
+ print("Handle Message");
+ }
logger.w(json.encode(message));
}
}
+
+AndroidNotificationChannel channel = const AndroidNotificationChannel(
+ "high_importance_channel",
+ "High Importance Notifications",
+ importance: Importance.high,
+);
+
+Future backgroundMessageHandler(RemoteMessage message) async {
+ if (kDebugMode) {
+ print("Firebase backgroundMessageHandler!!!");
+ }
+}
diff --git a/lib/classes/push-notification-handler.dart b/lib/classes/push-notification-handler.dart
deleted file mode 100644
index b95ceb2..0000000
--- a/lib/classes/push-notification-handler.dart
+++ /dev/null
@@ -1,59 +0,0 @@
-import 'dart:async';
-import 'dart:io';
-
-import 'package:firebase_messaging/firebase_messaging.dart';
-import 'package:flutter/cupertino.dart';
-import 'package:flutter/material.dart';
-import 'package:mohem_flutter_app/app_state/app_state.dart';
-
-// |--> Push Notification Background
-Future backgroundMessageHandler(message) async {
- print("Firebase backgroundMessageHandler!!!");
-}
-
-class PushNotificationHandler {
- final BuildContext context;
- static PushNotificationHandler? _instance;
-
- PushNotificationHandler(this.context) {
- PushNotificationHandler._instance = this;
- }
-
- static PushNotificationHandler getInstance() => _instance!;
-
- void init() async {
- FirebaseMessaging.onMessage.listen((RemoteMessage message) async {
- if (Platform.isIOS) {
- await Future.delayed(Duration(milliseconds: 3000)).then((value) {
- newMessage(message);
- });
- } else {
- newMessage(message);
- }
- });
-
- FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) async {
- if (Platform.isIOS) {
- await Future.delayed(Duration(milliseconds: 3000)).then((value) {
- newMessage(message);
- });
- } else {
- newMessage(message);
- }
- });
-
- FirebaseMessaging.instance.onTokenRefresh.listen((fcm_token) {
- print("Push Notification onTokenRefresh: " + fcm_token);
- AppState().setDeviceToken = fcm_token;
- });
-
- FirebaseMessaging.onBackgroundMessage(backgroundMessageHandler);
- }
-
- void newMessage(RemoteMessage remoteMessage) async {
- print("Remote Message: " + remoteMessage.data.toString());
- if (remoteMessage.data.isEmpty) {
- return;
- }
- }
-}
diff --git a/lib/ui/landing/dashboard_screen.dart b/lib/ui/landing/dashboard_screen.dart
index 5d5549d..b82cd9c 100644
--- a/lib/ui/landing/dashboard_screen.dart
+++ b/lib/ui/landing/dashboard_screen.dart
@@ -59,7 +59,7 @@ class _DashboardScreenState extends State {
marathonProvider = Provider.of(context, listen: false);
cProvider = Provider.of(context, listen: false);
_bHubCon();
- _onRefresh();
+ _onRefresh(true);
});
}
@@ -78,7 +78,17 @@ class _DashboardScreenState extends State {
});
}
- void _onRefresh() async {
+ Future checkHubCon() async {
+ print("-------------------------Again Hub Connection --------------------------------");
+ if (chatHubConnection.state == HubConnectionState.Connected) {
+ await chatHubConnection.stop();
+ await chatHubConnection.start();
+ } else if (chatHubConnection.state != HubConnectionState.Connected) {
+ await chatHubConnection.start();
+ }
+ }
+
+ void _onRefresh(bool isFromInit) async {
data.initProvider();
// data.getITGNotification().then((value) {
// print("--------------------detail_1-----------------");
@@ -93,6 +103,7 @@ class _DashboardScreenState extends State {
data.fetchMenuEntries();
data.getCategoryOffersListAPI(context);
marathonProvider.getMarathonDetailsFromApi();
+ if (!isFromInit) checkHubCon();
_refreshController.refreshCompleted();
}
@@ -192,7 +203,9 @@ class _DashboardScreenState extends State {
color: MyColors.gradiantEndColor,
),
controller: _refreshController,
- onRefresh: _onRefresh,
+ onRefresh: () {
+ _onRefresh(false);
+ },
child: SingleChildScrollView(
child: Column(
children: [
diff --git a/lib/ui/login/login_screen.dart b/lib/ui/login/login_screen.dart
index 6253002..eb9f5e0 100644
--- a/lib/ui/login/login_screen.dart
+++ b/lib/ui/login/login_screen.dart
@@ -13,7 +13,6 @@ import 'package:mohem_flutter_app/app_state/app_state.dart';
import 'package:mohem_flutter_app/classes/colors.dart';
import 'package:mohem_flutter_app/classes/consts.dart';
import 'package:mohem_flutter_app/classes/notifications.dart';
-import 'package:mohem_flutter_app/classes/push-notification-handler.dart';
import 'package:mohem_flutter_app/classes/utils.dart';
import 'package:mohem_flutter_app/config/routes.dart';
import 'package:mohem_flutter_app/extensions/int_extensions.dart';
@@ -97,7 +96,7 @@ class _LoginScreenState extends State {
await Firebase.initializeApp();
_firebaseMessaging = FirebaseMessaging.instance;
firebaseToken = await _firebaseMessaging.getToken();
- AppNotifications().initNotification(firebaseToken);
+ AppNotifications().init(firebaseToken);
loginInfo = await LoginApiClient().getMobileLoginInfoNEW(firebaseToken ?? "", Platform.isAndroid ? "android" : "ios");
if (loginInfo == null) {
await checkPrefs();
diff --git a/pubspec.yaml b/pubspec.yaml
index 189128d..d06ab8b 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -92,7 +92,7 @@ dependencies:
swipe_to: ^1.0.2
flutter_webrtc: ^0.9.16
camera: ^0.10.0+4
- #flutter_local_notifications: any
+ flutter_local_notifications: any
#Chat Voice Message Recoding & Play
audio_waveforms: ^0.1.5+1