Skip to content

Commit c583070

Browse files
committed
* Updated dependencies
* Fixed linter warnings * Added handleInitialMessage attribute * Exported firebase_messaging package * Updated version * Updated example app name * Updated README.md
1 parent 5a779cf commit c583070

File tree

11 files changed

+97
-65
lines changed

11 files changed

+97
-65
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## [1.0.8] - 07/06/2022
2+
3+
* Updated dependencies
4+
* Fixed linter warnings
5+
* Added handleInitialMessage attribute
6+
* Exported firebase_messaging package
7+
* Updated README.md
8+
19
## [1.0.7] - 02/05/2022
210

311
* Updated example app to a fully functional app...

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ FirebaseNotificationsHandler(
171171
},
172172
channelId: 'ChannelId',
173173
enableLogs: true,
174+
175+
// ... and a lot more
174176
),
175177
```
176178

example/android/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<uses-permission android:name="android.permission.INTERNET" />
55

66
<application
7-
android:label="notifications_handler_demo"
7+
android:label="FirebaseNotificationsHandler Demo"
88
android:name="${applicationName}"
99
android:icon="@mipmap/ic_launcher">
1010

example/ios/Runner/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<key>CFBundleInfoDictionaryVersion</key>
1414
<string>6.0</string>
1515
<key>CFBundleName</key>
16-
<string>notifications_handler_demo</string>
16+
<string>FirebaseNotificationsHandler Demo</string>
1717
<key>CFBundlePackageType</key>
1818
<string>APPL</string>
1919
<key>CFBundleShortVersionString</key>

example/lib/screens/home_screen.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ class _HomeScreenState extends State<HomeScreen> with WidgetsBindingObserver {
5555
onChanged: (value) {
5656
setState(() => showNotificationsOnLifecycleChange = value);
5757
if (showNotificationsOnLifecycleChange) {
58-
WidgetsBinding.instance?.addObserver(this);
58+
WidgetsBinding.instance.addObserver(this);
5959
} else {
60-
WidgetsBinding.instance?.removeObserver(this);
60+
WidgetsBinding.instance.removeObserver(this);
6161
}
6262
},
6363
value: showNotificationsOnLifecycleChange,

example/pubspec.lock

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ packages:
4949
name: collection
5050
url: "https://pub.dartlang.org"
5151
source: hosted
52-
version: "1.15.0"
52+
version: "1.16.0"
5353
dbus:
5454
dependency: transitive
5555
description:
@@ -70,7 +70,7 @@ packages:
7070
name: fake_async
7171
url: "https://pub.dartlang.org"
7272
source: hosted
73-
version: "1.2.0"
73+
version: "1.3.0"
7474
ffi:
7575
dependency: transitive
7676
description:
@@ -98,42 +98,42 @@ packages:
9898
name: firebase_core_platform_interface
9999
url: "https://pub.dartlang.org"
100100
source: hosted
101-
version: "4.2.5"
101+
version: "4.4.0"
102102
firebase_core_web:
103103
dependency: transitive
104104
description:
105105
name: firebase_core_web
106106
url: "https://pub.dartlang.org"
107107
source: hosted
108-
version: "1.6.2"
108+
version: "1.6.4"
109109
firebase_messaging:
110110
dependency: transitive
111111
description:
112112
name: firebase_messaging
113113
url: "https://pub.dartlang.org"
114114
source: hosted
115-
version: "11.2.15"
115+
version: "11.4.1"
116116
firebase_messaging_platform_interface:
117117
dependency: transitive
118118
description:
119119
name: firebase_messaging_platform_interface
120120
url: "https://pub.dartlang.org"
121121
source: hosted
122-
version: "3.3.1"
122+
version: "3.5.1"
123123
firebase_messaging_web:
124124
dependency: transitive
125125
description:
126126
name: firebase_messaging_web
127127
url: "https://pub.dartlang.org"
128128
source: hosted
129-
version: "2.2.13"
129+
version: "2.4.1"
130130
firebase_notifications_handler:
131131
dependency: "direct main"
132132
description:
133133
path: ".."
134134
relative: true
135135
source: path
136-
version: "1.0.7"
136+
version: "1.0.8"
137137
flutter:
138138
dependency: "direct main"
139139
description: flutter
@@ -152,14 +152,14 @@ packages:
152152
name: flutter_local_notifications
153153
url: "https://pub.dartlang.org"
154154
source: hosted
155-
version: "9.4.1"
155+
version: "9.6.0"
156156
flutter_local_notifications_linux:
157157
dependency: transitive
158158
description:
159159
name: flutter_local_notifications_linux
160160
url: "https://pub.dartlang.org"
161161
source: hosted
162-
version: "0.4.2"
162+
version: "0.5.0+1"
163163
flutter_local_notifications_platform_interface:
164164
dependency: transitive
165165
description:
@@ -197,7 +197,7 @@ packages:
197197
name: js
198198
url: "https://pub.dartlang.org"
199199
source: hosted
200-
version: "0.6.3"
200+
version: "0.6.4"
201201
lints:
202202
dependency: transitive
203203
description:
@@ -218,7 +218,7 @@ packages:
218218
name: material_color_utilities
219219
url: "https://pub.dartlang.org"
220220
source: hosted
221-
version: "0.1.3"
221+
version: "0.1.4"
222222
meta:
223223
dependency: transitive
224224
description:
@@ -232,14 +232,14 @@ packages:
232232
name: path
233233
url: "https://pub.dartlang.org"
234234
source: hosted
235-
version: "1.8.0"
235+
version: "1.8.1"
236236
path_provider:
237237
dependency: transitive
238238
description:
239239
name: path_provider
240240
url: "https://pub.dartlang.org"
241241
source: hosted
242-
version: "2.0.9"
242+
version: "2.0.11"
243243
path_provider_android:
244244
dependency: transitive
245245
description:
@@ -321,7 +321,7 @@ packages:
321321
name: source_span
322322
url: "https://pub.dartlang.org"
323323
source: hosted
324-
version: "1.8.1"
324+
version: "1.8.2"
325325
stack_trace:
326326
dependency: transitive
327327
description:
@@ -356,7 +356,7 @@ packages:
356356
name: test_api
357357
url: "https://pub.dartlang.org"
358358
source: hosted
359-
version: "0.4.8"
359+
version: "0.4.9"
360360
timezone:
361361
dependency: transitive
362362
description:
@@ -377,7 +377,7 @@ packages:
377377
name: vector_math
378378
url: "https://pub.dartlang.org"
379379
source: hosted
380-
version: "2.1.1"
380+
version: "2.1.2"
381381
win32:
382382
dependency: transitive
383383
description:
@@ -400,5 +400,5 @@ packages:
400400
source: hosted
401401
version: "5.3.1"
402402
sdks:
403-
dart: ">=2.16.1 <3.0.0"
403+
dart: ">=2.17.0-0 <3.0.0"
404404
flutter: ">=2.8.1"
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
library firebase_notifications_handler;
22

3-
export 'src/widget.dart';
3+
export 'package:firebase_messaging/firebase_messaging.dart';
4+
45
export 'src/app_state.dart';
6+
export 'src/widget.dart';

lib/src/service.dart

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class PushNotificationService {
8282
onTap,
8383
GlobalKey<NavigatorState>? navigatorKey,
8484
String? customSound,
85+
required bool handleInitialMessage,
8586
required String channelId,
8687
required String channelName,
8788
required String channelDescription,
@@ -111,10 +112,12 @@ class PushNotificationService {
111112

112113
_fcmToken = await initializeFCMToken(vapidKey: vapidKey);
113114

114-
final _bgMessage = await _fcm.getInitialMessage();
115-
if (_bgMessage != null) {
116-
_openedAppFromNotification = true;
117-
_onBackgroundMessage(_bgMessage);
115+
if (handleInitialMessage) {
116+
final bgMessage = await _fcm.getInitialMessage();
117+
if (bgMessage != null) {
118+
_openedAppFromNotification = true;
119+
_onBackgroundMessage(bgMessage);
120+
}
118121
}
119122

120123
/// Registering the listeners
@@ -157,14 +160,14 @@ class PushNotificationService {
157160
/// notifications to show a notification when the app is in foreground.
158161
static Future<FlutterLocalNotificationsPlugin>
159162
_initializeLocalNotifications() async {
160-
final _flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
163+
final flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
161164
const initializationSettings = InitializationSettings(
162165
android: AndroidInitializationSettings('@mipmap/ic_launcher'),
163166
// iOS: IOSInitializationSettings(
164167
// onDidReceiveLocalNotification: (id, title, body, payload) async {},
165168
// ),
166169
);
167-
await _flutterLocalNotificationsPlugin.initialize(
170+
await flutterLocalNotificationsPlugin.initialize(
168171
initializationSettings,
169172
onSelectNotification: (String? payload) async {
170173
if (_onTap != null) {
@@ -176,7 +179,7 @@ class PushNotificationService {
176179
}
177180
},
178181
);
179-
return _flutterLocalNotificationsPlugin;
182+
return flutterLocalNotificationsPlugin;
180183
}
181184

182185
/// [_notificationHandler] implementation
@@ -225,7 +228,7 @@ class PushNotificationService {
225228
}
226229
}
227230

228-
final _androidSpecifics = AndroidNotificationDetails(
231+
final androidSpecifics = AndroidNotificationDetails(
229232
message.notification?.android?.channelId ?? _channelId!,
230233
_channelName!,
231234
channelDescription: _channelDescription!,
@@ -241,19 +244,19 @@ class PushNotificationService {
241244
enableVibration: true,
242245
);
243246

244-
final _iOsSpecifics = IOSNotificationDetails(sound: _customSound);
247+
final iOsSpecifics = IOSNotificationDetails(sound: _customSound);
245248

246249
final notificationPlatformSpecifics = NotificationDetails(
247-
android: _androidSpecifics,
248-
iOS: _iOsSpecifics,
250+
android: androidSpecifics,
251+
iOS: iOsSpecifics,
249252
);
250253

251-
final _localNotifications = await _initializeLocalNotifications();
254+
final localNotifications = await _initializeLocalNotifications();
252255

253256
_notificationIdCallback ??= (_) => DateTime.now().hashCode;
254257

255258
if (appState == AppState.open) {
256-
await _localNotifications.show(
259+
await localNotifications.show(
257260
_notificationIdCallback!(message),
258261
message.notification?.title,
259262
message.notification?.body,

lib/src/widget.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,19 @@ class FirebaseNotificationsHandler extends StatefulWidget {
6262
/// {@endtemplate}
6363
final String? customSound;
6464

65+
/// {@template handleInitialMessage}
66+
///
67+
/// Whether to check if the application has been opened
68+
/// from a terminated state via a [RemoteMessage].
69+
///
70+
/// If false, then [openedAppFromNotification] will always be false.
71+
///
72+
/// If true, then checks for the initial message, and
73+
/// if it exists, [onTap] is called with [AppState.closed].
74+
///
75+
/// {@endtemplate}
76+
final bool handleInitialMessage;
77+
6578
/// {@template channelId}
6679
/// If message.notification?.android?.channelId exists in the map,
6780
/// then it is used, if not then the default value is used, else the value
@@ -172,6 +185,7 @@ class FirebaseNotificationsHandler extends StatefulWidget {
172185
this.defaultNavigatorKey,
173186
this.customSound,
174187
this.notificationIdCallback,
188+
this.handleInitialMessage = true,
175189
this.channelId = Constants.channelId,
176190
this.channelName = Constants.channelName,
177191
this.channelDescription = Constants.channelDescription,
@@ -239,6 +253,7 @@ class FirebaseNotificationsHandler extends StatefulWidget {
239253
}
240254

241255
@override
256+
// ignore: library_private_types_in_public_api
242257
_FirebaseNotificationsHandlerState createState() =>
243258
_FirebaseNotificationsHandlerState();
244259
}
@@ -254,6 +269,7 @@ class _FirebaseNotificationsHandlerState
254269
onTap: widget.onTap,
255270
navigatorKey: widget.defaultNavigatorKey,
256271
customSound: widget.customSound,
272+
handleInitialMessage: widget.handleInitialMessage,
257273
channelId: widget.channelId,
258274
channelName: widget.channelName,
259275
channelDescription: widget.channelDescription,
@@ -262,6 +278,7 @@ class _FirebaseNotificationsHandlerState
262278
notificationIdCallback: widget.notificationIdCallback,
263279
);
264280

281+
if (!mounted) return;
265282
widget.onFCMTokenInitialize?.call(context, token);
266283

267284
PushNotificationService.onTokenRefresh.listen((token) {

0 commit comments

Comments
 (0)