-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:ia-toki/bebras-pandai into feature-…
…admin-task
- Loading branch information
Showing
14 changed files
with
218 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import 'package:cloud_firestore/cloud_firestore.dart'; | ||
import 'package:firebase_messaging/firebase_messaging.dart'; | ||
|
||
import '../services/firebase_service.dart'; | ||
import '../services/router_service.dart'; | ||
|
||
class FirebaseApi { | ||
final _firebaseMessaging = FirebaseMessaging.instance; | ||
final currentUser = FirebaseService.auth().currentUser; | ||
|
||
void handleMessage(RemoteMessage? message) { | ||
if (message == null) return; | ||
|
||
router.push('/main'); | ||
} | ||
|
||
Future<dynamic> initPushNotfications() async { | ||
await FirebaseMessaging.instance | ||
.setForegroundNotificationPresentationOptions( | ||
alert: true, | ||
badge: true, | ||
sound: true, | ||
); | ||
|
||
await FirebaseMessaging.instance.getInitialMessage().then(handleMessage); | ||
FirebaseMessaging.onMessageOpenedApp.listen(handleMessage); | ||
FirebaseMessaging.onBackgroundMessage(handleBackgroundMessage); | ||
} | ||
|
||
Future<void> initNotifications() async { | ||
await _firebaseMessaging.requestPermission(); | ||
|
||
FirebaseMessaging.instance.onTokenRefresh.listen((fcmToken) { | ||
Map<String, dynamic> deviceToken = { | ||
'fcm_token': fcmToken, | ||
'fcm_timestamp': FieldValue.serverTimestamp(), | ||
}; | ||
|
||
// Reference to the Firestore collection | ||
CollectionReference<Map<String, dynamic>> fcmTokensCollection = | ||
FirebaseFirestore.instance.collection('registered_user'); | ||
|
||
// Set the device token in Firestore | ||
fcmTokensCollection.doc(currentUser!.uid).update(deviceToken); | ||
}).onError((err) { | ||
// Error getting token. | ||
}); | ||
|
||
final fCMToken = await _firebaseMessaging.getToken(); | ||
print('Token: $fCMToken'); | ||
await initPushNotfications(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import 'package:cached_network_image/cached_network_image.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_html/flutter_html.dart'; | ||
|
||
class HtmlWithCachedImages extends StatelessWidget { | ||
final String data; | ||
|
||
const HtmlWithCachedImages({ | ||
required this.data, | ||
super.key, | ||
}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Html( | ||
data: data, | ||
extensions: <HtmlExtension>[ | ||
ImageExtension( | ||
builder: (ExtensionContext extensionContext) { | ||
final element = extensionContext.styledElement!; | ||
return CachedNetworkImage( | ||
imageUrl: element.attributes['src']!, | ||
fit: BoxFit.cover, | ||
); | ||
}, | ||
), | ||
], | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.