Fakultas Ilmu Komputer UI

Commit e7f00baf authored by Yoga Pratama's avatar Yoga Pratama
Browse files

[GREEN] Implement fcm bloc

parent 982883b5
import 'package:bisaGo/repository/cloud_messaging_repository.dart';
import 'package:get_it/get_it.dart';
import 'package:http/http.dart';
class CloudMessagingBloc {
CloudMessagingRepository _cloudMessagingRepository;
CloudMessagingBloc() {
_cloudMessagingRepository =
GetIt.instance.get<BaseCloudMessagingRepository>();
}
Future<dynamic> sendFCMToken(
String fcmToken,
String token,
) async {
try {
return await _cloudMessagingRepository.sendFCMToken(
fcmToken,
token,
);
} catch (e) {
return Response('Failed to add komentar', 400);
}
}
}
......@@ -12,9 +12,15 @@ class CloudMessagingRepository implements BaseCloudMessagingRepository {
Future<bool> sendFCMToken(String fcmToken, String token) async {
try {
await http.post(
'${ApiFlavor.getBaseUrl()}/',
headers: {'Authorization': token, 'content-type': 'application/json'},
body: json.encode({'token': fcmToken}),
'${ApiFlavor.getBaseUrl()}/notification/',
headers: {
'Authorization': 'token $token',
'content-type': 'application/json'
},
body: json.encode({
'token': fcmToken,
'type': 'android',
}),
);
return true;
} catch (_) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment