Update send FCM Token to Server
This commit is contained in:
@@ -4,6 +4,7 @@ import 'package:firebase_core/firebase_core.dart';
|
|||||||
import 'package:firebase_messaging/firebase_messaging.dart';
|
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||||
|
import 'package:sfm_app/product/services/api_services.dart';
|
||||||
import 'product/services/notification_services.dart';
|
import 'product/services/notification_services.dart';
|
||||||
import 'product/services/theme_services.dart';
|
import 'product/services/theme_services.dart';
|
||||||
import 'product/services/language_services.dart';
|
import 'product/services/language_services.dart';
|
||||||
@@ -58,7 +59,7 @@ class _MyAppState extends State<MyApp> {
|
|||||||
LanguageServices languageServices = LanguageServices();
|
LanguageServices languageServices = LanguageServices();
|
||||||
ThemeServices themeServices = ThemeServices();
|
ThemeServices themeServices = ThemeServices();
|
||||||
final NotificationServices notificationServices = NotificationServices();
|
final NotificationServices notificationServices = NotificationServices();
|
||||||
|
APIServices apiServices = APIServices();
|
||||||
setLocale(Locale locale) {
|
setLocale(Locale locale) {
|
||||||
_locale = locale;
|
_locale = locale;
|
||||||
mainBloc.sinkLanguage.add(_locale);
|
mainBloc.sinkLanguage.add(_locale);
|
||||||
@@ -77,9 +78,15 @@ class _MyAppState extends State<MyApp> {
|
|||||||
// notificationServices.setupInteractMessage();
|
// notificationServices.setupInteractMessage();
|
||||||
notificationServices.getDeviceToken().then((token){
|
notificationServices.getDeviceToken().then((token){
|
||||||
print("Firebase Token: $token");
|
print("Firebase Token: $token");
|
||||||
|
sendNotificationToken(token);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sendNotificationToken (String token) async {
|
||||||
|
int statusCode = await apiServices.sendNotificationToken(token);
|
||||||
|
log("Notification Send StatusCode : $statusCode");
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void didChangeDependencies() {
|
void didChangeDependencies() {
|
||||||
languageServices.getLocale().then((locale) => {setLocale(locale)});
|
languageServices.getLocale().then((locale) => {setLocale(locale)});
|
||||||
|
|||||||
@@ -21,4 +21,5 @@ class APIPathConstants {
|
|||||||
static const JOIN_GROUP_PATH = "/api/groups/join";
|
static const JOIN_GROUP_PATH = "/api/groups/join";
|
||||||
static const APPROVE_GROUP_PATH = "/api/groups/approve";
|
static const APPROVE_GROUP_PATH = "/api/groups/approve";
|
||||||
static const DEVICE_LOGS_PATH = "/api/device-logs";
|
static const DEVICE_LOGS_PATH = "/api/device-logs";
|
||||||
|
static const NOTIFICATION_TOKEN_PATH = "/api/users/app-token";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,6 +49,17 @@ class APIServices {
|
|||||||
return response.body;
|
return response.body;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<int> sendNotificationToken(String token) async{
|
||||||
|
String uid = await getUID();
|
||||||
|
Map<String,dynamic> body = {
|
||||||
|
"user_id": uid,
|
||||||
|
"app_token": token
|
||||||
|
};
|
||||||
|
int statusCode = await NetworkManager.instance!.updateDataInServer(
|
||||||
|
APIPathConstants.NOTIFICATION_TOKEN_PATH, body);
|
||||||
|
return statusCode;
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> logOut(BuildContext context) async {
|
Future<void> logOut(BuildContext context) async {
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ class NotificationServices {
|
|||||||
importance: androidNotificationChannel.importance,
|
importance: androidNotificationChannel.importance,
|
||||||
priority: Priority.high,
|
priority: Priority.high,
|
||||||
ticker: 'ticker',
|
ticker: 'ticker',
|
||||||
actions: type == "warn1"
|
actions: type == "smoke_warning"
|
||||||
? [
|
? [
|
||||||
const AndroidNotificationAction(
|
const AndroidNotificationAction(
|
||||||
"id1",
|
"id1",
|
||||||
@@ -117,9 +117,9 @@ class NotificationServices {
|
|||||||
return const RawResourceAndroidNotificationSound("welcome");
|
return const RawResourceAndroidNotificationSound("welcome");
|
||||||
} else if (type == "success") {
|
} else if (type == "success") {
|
||||||
return const RawResourceAndroidNotificationSound("success_alert");
|
return const RawResourceAndroidNotificationSound("success_alert");
|
||||||
} else if (type == "warn1") {
|
} else if (type == "smoke_warning") {
|
||||||
return const RawResourceAndroidNotificationSound("warning_alarm");
|
return const RawResourceAndroidNotificationSound("warning_alarm");
|
||||||
} else if (type == "warn2") {
|
} else if (type == "battery_warning") {
|
||||||
return const RawResourceAndroidNotificationSound("new_alarm");
|
return const RawResourceAndroidNotificationSound("new_alarm");
|
||||||
} else {
|
} else {
|
||||||
return const RawResourceAndroidNotificationSound("normal");
|
return const RawResourceAndroidNotificationSound("normal");
|
||||||
|
|||||||
Reference in New Issue
Block a user