dartway_push_firebase 0.1.1
dartway_push_firebase: ^0.1.1 copied to clipboard
Firebase Cloud Messaging transport for DartWay push: tokens, permissions and notification taps on Android, iOS and web, behind the dw.plugins.push contract.
dartway_push_firebase #
Firebase Cloud Messaging as a transport for dartway_push_flutter —
Android, iOS and web.
DwPush(
config: DwPushConfig(
providers: [DwFirebasePush(webVapidKey: kWebVapidKey)],
// ...
),
)
Everything else — when to ask for permission, when the token goes to the server, what happens between a tap and a screen — belongs to the core plugin. This package answers five questions about FCM and nothing more.
What the app still owns #
Firebase.initializeAppinmain(), with your ownfirebase_options.dart. This transport refuses to guess your project: with no Firebase app initialized it stands aside and says so.DwFirebasePush.registerBackgroundHandler()right after that, beforerunApp. FCM wants the handler registered before the app starts.android/app/google-services.jsonandios/Runner/GoogleService-Info.plist, plus the Google Services Gradle plugin. Standard FlutterFire setup.- Web: copy
web/firebase-messaging-sw.template.jsfrom this package to your app'sweb/firebase-messaging-sw.jsand fill in the config. Without it a closed tab shows nothing. Copy it as it stands — the handler is registered beforefirebase.messaging()and callsstopImmediatePropagation()on purpose: the SDK installs its ownnotificationclicklistener in that call and stops propagation itself, so a handler placed after it never runs. Without the template a tap still reaches the right screen, throughwebpush.fcm_options.link, but in a new tab instead of the one already open. PasswebVapidKey— the browser issues no token without one.
Notes that cost an afternoon each #
- On iOS an FCM token exists only after APNs has registered the install. Before that
requestToken()answers null, which is a "not yet": the core plugin picks the token up when the platform refreshes it. - In the foreground, iOS shows nothing unless asked; this transport asks. Android draws its own.
- On Android 13+ the notification permission is a runtime prompt, and
requestPermission()raises it.
Part of DartWay #
DartWay is a fullstack Dart framework (Flutter + Serverpod). The framework lives in one repository.