Fakultas Ilmu Komputer UI
Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ppl-fasilkom-ui
PPL Sosial
bisago
bisago-fe
Commits
e7f00baf
Commit
e7f00baf
authored
May 22, 2021
by
Yoga Pratama
Browse files
[GREEN] Implement fcm bloc
parent
982883b5
Changes
2
Hide whitespace changes
Inline
Side-by-side
lib/bloc/cloud_messaging_bloc.dart
0 → 100644
View file @
e7f00baf
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
);
}
}
}
lib/repository/cloud_messaging_repository.dart
View file @
e7f00baf
...
...
@@ -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
(
_
)
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment