diff --git a/android/app/src/main/res/drawable/ic_launcher.xml b/android/app/src/main/res/drawable/ic_launcher.xml
deleted file mode 100644
index 2c48d3f..0000000
--- a/android/app/src/main/res/drawable/ic_launcher.xml
+++ /dev/null
@@ -1,3057 +0,0 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/lib/core/constants/api.dart b/lib/core/constants/api.dart
index 1606393..8884aeb 100644
--- a/lib/core/constants/api.dart
+++ b/lib/core/constants/api.dart
@@ -1,6 +1,6 @@
-// const String baseUrl = 'https://192.168.99.64:5001/api';
-// const String imageUrl = 'https://192.168.99.64:5001';
-const String baseUrl = 'https://cargo.tpsadvertising.com/api';
-const String imageUrl = 'https://cargo.tpsadvertising.com';
+const String baseUrl = 'https://192.168.99.64:5001/api';
+const String imageUrl = 'https://192.168.99.64:5001';
+// const String baseUrl = 'https://cargo.tpsadvertising.com/api';
+// const String imageUrl = 'https://cargo.tpsadvertising.com';
const String defaultApiKey = '';
const String defaultSources = '';
diff --git a/lib/core/utils/notification_service.dart b/lib/core/utils/notification_service.dart
index 1727667..02ba519 100644
--- a/lib/core/utils/notification_service.dart
+++ b/lib/core/utils/notification_service.dart
@@ -103,7 +103,7 @@ class FCMFunctions {
/// IOS
Future iosWebPermission() async {
if (Platform.isIOS || kIsWeb) {
- NotificationSettings settings = await messaging.requestPermission();
+ /* NotificationSettings settings = */ await messaging.requestPermission();
}
}
@@ -259,7 +259,7 @@ Future initFCMFunctions() async {
FirebaseMessaging.onBackgroundMessage(onBackgroundHandler);
- await fcmFunctions.getFCMToken();
+ // final String? token = await fcmFunctions.getFCMToken();
fcmFunctions.tokenListener();
fcmFunctions.foreGroundMessageListener();
await fcmFunctions.subscribeToTopics('notifications');
diff --git a/lib/data/data_sources/local/user_local_data_source.dart b/lib/data/data_sources/local/user_local_data_source.dart
index e322a26..4be2180 100644
--- a/lib/data/data_sources/local/user_local_data_source.dart
+++ b/lib/data/data_sources/local/user_local_data_source.dart
@@ -6,10 +6,14 @@ import '../../models/models.dart';
abstract class UserLocalDataSource {
Future getToken();
+ Future getFBToken();
+
Future getUser();
Future saveToken(String token);
+ Future saveFBToken(String token);
+
Future saveUser(UserModel user);
Future clearCache();
@@ -18,6 +22,7 @@ abstract class UserLocalDataSource {
}
const cachedToken = 'TOKEN';
+const cachedFBToken = 'FB_TOKEN';
const cachedUser = 'USER';
class UserLocalDataSourceImpl implements UserLocalDataSource {
@@ -30,11 +35,22 @@ class UserLocalDataSourceImpl implements UserLocalDataSource {
return token;
}
+ @override
+ Future getFBToken() async {
+ String? token = sharedPreferences.getString(cachedFBToken) ?? '';
+ return token;
+ }
+
@override
Future saveToken(String token) async {
await sharedPreferences.setString(cachedToken, token);
}
+ @override
+ Future saveFBToken(String token) async {
+ await sharedPreferences.setString(cachedFBToken, token);
+ }
+
@override
Future getUser() async {
final jsonString = sharedPreferences.getString(cachedUser);
@@ -62,6 +78,7 @@ class UserLocalDataSourceImpl implements UserLocalDataSource {
@override
Future clearCache() async {
await sharedPreferences.remove(cachedToken);
+ await sharedPreferences.remove(cachedFBToken);
await sharedPreferences.remove(cachedUser);
}
}
diff --git a/lib/data/data_sources/remote/user_remote_data_source.dart b/lib/data/data_sources/remote/user_remote_data_source.dart
index 6191747..c122cd5 100644
--- a/lib/data/data_sources/remote/user_remote_data_source.dart
+++ b/lib/data/data_sources/remote/user_remote_data_source.dart
@@ -9,6 +9,7 @@ import '../../data.dart';
abstract class UserRemoteDataSource {
Future signIn(SignInParams params);
Future getUser(String token);
+ Future registerFBToken(String token, String fbToken);
}
class UserRemoteDataSourceImpl implements UserRemoteDataSource {
@@ -58,4 +59,20 @@ class UserRemoteDataSourceImpl implements UserRemoteDataSource {
throw ServerException();
}
}
+
+ @override
+ Future registerFBToken(String token, String fbToken) async {
+ final response = await client.post(
+ Uri.parse('$baseUrl/Client/FirebaseToken?token=$fbToken'),
+ headers: {
+ 'accept': '*/*',
+ 'Content-Type': 'application/json',
+ 'Authorization': 'Bearer $token',
+ },
+ );
+
+ if (response.statusCode != 200) {
+ throw ServerException();
+ }
+ }
}
diff --git a/lib/data/repositories/user_repository_impl.dart b/lib/data/repositories/user_repository_impl.dart
index 0eb2c4e..005fe5a 100644
--- a/lib/data/repositories/user_repository_impl.dart
+++ b/lib/data/repositories/user_repository_impl.dart
@@ -19,8 +19,16 @@ class UserRepositoryImpl implements UserRepository {
Future> signIn(params) async {
if (await networkInfo.isConnected) {
try {
+ /// login
final token = await remoteDataSource.signIn(params);
await localDataSource.saveToken(token);
+
+ /// get FB token
+ final String? fcmToken = await fcmFunctions.getFCMToken();
+ if (fcmToken != null) {
+ await remoteDataSource.registerFBToken(token, fcmToken);
+ }
+
return Right(token);
} on Failure catch (failure) {
return Left(failure);
diff --git a/lib/main.dart b/lib/main.dart
index 2650f52..3893b73 100644
--- a/lib/main.dart
+++ b/lib/main.dart
@@ -1,10 +1,6 @@
-import 'dart:developer';
import 'dart:io';
-import 'package:cargo/firebase_options.dart';
import 'package:easy_localization/easy_localization.dart';
-import 'package:firebase_core/firebase_core.dart';
-import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
@@ -17,13 +13,6 @@ import 'di/di.dart' as di;
Future _initFBInitials() async {
try {
await initFCMFunctions();
-
- // await Firebase.initializeApp(
- // options: DefaultFirebaseOptions.currentPlatform,
- // );
- // final fcmToken = await FirebaseMessaging.instance.getToken();
- // await FirebaseMessaging.instance.setAutoInitEnabled(true);
- // log('FCMToken $fcmToken');
} catch (e) {
debugPrint('FCM error: $e');
}