developed
This commit is contained in:
parent
8007dd5928
commit
d515c5143e
File diff suppressed because it is too large
Load Diff
|
|
@ -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 = '';
|
||||
|
|
|
|||
|
|
@ -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<void> initFCMFunctions() async {
|
|||
|
||||
FirebaseMessaging.onBackgroundMessage(onBackgroundHandler);
|
||||
|
||||
await fcmFunctions.getFCMToken();
|
||||
// final String? token = await fcmFunctions.getFCMToken();
|
||||
fcmFunctions.tokenListener();
|
||||
fcmFunctions.foreGroundMessageListener();
|
||||
await fcmFunctions.subscribeToTopics('notifications');
|
||||
|
|
|
|||
|
|
@ -6,10 +6,14 @@ import '../../models/models.dart';
|
|||
abstract class UserLocalDataSource {
|
||||
Future<String> getToken();
|
||||
|
||||
Future<String> getFBToken();
|
||||
|
||||
Future<UserModel> getUser();
|
||||
|
||||
Future<void> saveToken(String token);
|
||||
|
||||
Future<void> saveFBToken(String token);
|
||||
|
||||
Future<void> saveUser(UserModel user);
|
||||
|
||||
Future<void> 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<String> getFBToken() async {
|
||||
String? token = sharedPreferences.getString(cachedFBToken) ?? '';
|
||||
return token;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> saveToken(String token) async {
|
||||
await sharedPreferences.setString(cachedToken, token);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> saveFBToken(String token) async {
|
||||
await sharedPreferences.setString(cachedFBToken, token);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<UserModel> getUser() async {
|
||||
final jsonString = sharedPreferences.getString(cachedUser);
|
||||
|
|
@ -62,6 +78,7 @@ class UserLocalDataSourceImpl implements UserLocalDataSource {
|
|||
@override
|
||||
Future<void> clearCache() async {
|
||||
await sharedPreferences.remove(cachedToken);
|
||||
await sharedPreferences.remove(cachedFBToken);
|
||||
await sharedPreferences.remove(cachedUser);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import '../../data.dart';
|
|||
abstract class UserRemoteDataSource {
|
||||
Future<String> signIn(SignInParams params);
|
||||
Future<User> getUser(String token);
|
||||
Future<void> registerFBToken(String token, String fbToken);
|
||||
}
|
||||
|
||||
class UserRemoteDataSourceImpl implements UserRemoteDataSource {
|
||||
|
|
@ -58,4 +59,20 @@ class UserRemoteDataSourceImpl implements UserRemoteDataSource {
|
|||
throw ServerException();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,8 +19,16 @@ class UserRepositoryImpl implements UserRepository {
|
|||
Future<Either<Failure, String>> 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);
|
||||
|
|
|
|||
|
|
@ -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<void> _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');
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue