-
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.
feat: Add flutterfire_messenger package
- Loading branch information
Showing
9 changed files
with
183 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Miscellaneous | ||
*.class | ||
*.log | ||
*.pyc | ||
*.swp | ||
.DS_Store | ||
.atom/ | ||
.buildlog/ | ||
.history | ||
.svn/ | ||
migrate_working_dir/ | ||
|
||
# IntelliJ related | ||
*.iml | ||
*.ipr | ||
*.iws | ||
.idea/ | ||
|
||
# The .vscode folder contains launch configuration and tasks you configure in | ||
# VS Code which you may wish to be included in version control, so this line | ||
# is commented out by default. | ||
#.vscode/ | ||
|
||
# Flutter/Dart/Pub related | ||
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. | ||
/pubspec.lock | ||
**/doc/api/ | ||
.dart_tool/ | ||
.packages | ||
build/ |
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,10 @@ | ||
# This file tracks properties of this Flutter project. | ||
# Used by Flutter tool to assess capabilities and perform upgrades etc. | ||
# | ||
# This file should be version controlled and should not be manually edited. | ||
|
||
version: | ||
revision: "db7ef5bf9f59442b0e200a90587e8fa5e0c6336a" | ||
channel: "stable" | ||
|
||
project_type: package |
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,3 @@ | ||
## 0.1.0 | ||
|
||
* initial release. |
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,39 @@ | ||
<!-- | ||
This README describes the package. If you publish this package to pub.dev, | ||
this README's contents appear on the landing page for your package. | ||
For information about how to write a good package README, see the guide for | ||
[writing package pages](https://dart.dev/guides/libraries/writing-package-pages). | ||
For general information about developing packages, see the Dart guide for | ||
[creating packages](https://dart.dev/guides/libraries/create-library-packages) | ||
and the Flutter guide for | ||
[developing packages and plugins](https://flutter.dev/developing-packages). | ||
--> | ||
|
||
TODO: Put a short description of the package here that helps potential users | ||
know whether this package might be useful for them. | ||
|
||
## Features | ||
|
||
TODO: List what your package can do. Maybe include images, gifs, or videos. | ||
|
||
## Getting started | ||
|
||
TODO: List prerequisites and provide or point to information on how to | ||
start using the package. | ||
|
||
## Usage | ||
|
||
TODO: Include short and useful examples for package users. Add longer examples | ||
to `/example` folder. | ||
|
||
```dart | ||
const like = 'sample'; | ||
``` | ||
|
||
## Additional information | ||
|
||
TODO: Tell users more about the package: where to find more information, how to | ||
contribute to the package, how to file issues, what response they can expect | ||
from the package authors, and more. |
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 @@ | ||
include: package:altive_lints/altive_lints.yaml |
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,5 @@ | ||
/// flutterfire_messenger with FlutterFire Messaging, Local Notifications, | ||
/// In-App Messaging, and Firebase Installation ID. | ||
library flutterfire_messenger; | ||
|
||
export 'src/messenger.dart'; |
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,33 @@ | ||
import 'package:firebase_messaging/firebase_messaging.dart'; | ||
|
||
/// A class that wraps package for sending messages. | ||
/// Its role is to "send necessary messages." | ||
/// | ||
/// It exposes methods for sending messages and for configuration. | ||
class Messenger { | ||
Messenger({ | ||
FirebaseMessaging? messaging, | ||
}) : _messaging = messaging ?? FirebaseMessaging.instance; | ||
|
||
final FirebaseMessaging _messaging; | ||
|
||
/// Requests messaging permissions. | ||
/// | ||
/// On iOS, sets the foreground messaging presentation options using | ||
/// [alert], [badge], and [sound], determining how messages appear | ||
/// when the app is in the foreground. | ||
Future<NotificationSettings> requestPermission({ | ||
bool alert = false, | ||
bool badge = false, | ||
bool sound = false, | ||
}) async { | ||
// Foreground messaging presentation options for iOS. | ||
await _messaging.setForegroundNotificationPresentationOptions( | ||
alert: alert, | ||
badge: badge, | ||
sound: sound, | ||
); | ||
final settings = await _messaging.requestPermission(); | ||
return settings; | ||
} | ||
} |
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,17 @@ | ||
name: flutterfire_messenger | ||
description: flutterfire_messenger with FlutterFire Messaging, Local Notifications and In-App Messaging, and Firebase Instance ID. | ||
version: 0.1.0 | ||
|
||
environment: | ||
sdk: ^3.0.0 | ||
|
||
dependencies: | ||
firebase_messaging: ^14.7.6 | ||
flutter: | ||
sdk: flutter | ||
|
||
dev_dependencies: | ||
altive_lints: ^1.8.1 | ||
flutter_test: | ||
sdk: flutter | ||
mocktail: ^1.0.1 |
45 changes: 45 additions & 0 deletions
45
packages/flutterfire_messenger/test/src/messenger_test.dart
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,45 @@ | ||
import 'package:firebase_messaging/firebase_messaging.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:flutterfire_messenger/messenger.dart'; | ||
import 'package:mocktail/mocktail.dart'; | ||
|
||
class MockFirebaseMessaging extends Mock implements FirebaseMessaging {} | ||
|
||
class MockNotificationSettings extends Mock implements NotificationSettings {} | ||
|
||
void main() { | ||
group('Messenger', () { | ||
test( | ||
'requestPermission should call ' | ||
'setForegroundNotificationPresentationOptions and ' | ||
'requestPermission on messaging', () async { | ||
final messaging = MockFirebaseMessaging(); | ||
final messenger = Messenger(messaging: messaging); | ||
final settings = MockNotificationSettings(); | ||
|
||
when( | ||
() => messaging.setForegroundNotificationPresentationOptions( | ||
alert: any(named: 'alert'), | ||
badge: any(named: 'badge'), | ||
sound: any(named: 'sound'), | ||
), | ||
).thenAnswer((_) async {}); | ||
when(messaging.requestPermission).thenAnswer((_) async => settings); | ||
|
||
final got = await messenger.requestPermission(); | ||
|
||
expect(got, settings); | ||
|
||
verify( | ||
() => messaging.setForegroundNotificationPresentationOptions( | ||
alert: any(named: 'alert'), | ||
badge: any(named: 'badge'), | ||
sound: any(named: 'sound'), | ||
), | ||
).called(1); | ||
verify(messaging.requestPermission).called(1); | ||
|
||
verifyNoMoreInteractions(messaging); | ||
}); | ||
}); | ||
} |