-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add code for message handling and storing device token
- Loading branch information
1 parent
a8ab0c9
commit 73ad66c
Showing
4 changed files
with
68 additions
and
37 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import 'package:farmassist/data/user/repositories/user_repository.dart'; | ||
import 'package:firebase_messaging/firebase_messaging.dart'; | ||
|
||
class MessageHandler { | ||
MessageHandler(UserRepository userRepository) { | ||
_messaging = FirebaseMessaging.instance; | ||
_userRepository = userRepository; | ||
} | ||
|
||
FirebaseMessaging _messaging; | ||
UserRepository _userRepository; | ||
|
||
Future<void> generateToken() async { | ||
String token = await _messaging.getToken(); | ||
await _userRepository.saveToken(token); | ||
_messaging.onTokenRefresh.listen(_userRepository.saveToken); | ||
} | ||
} |