initialize method
Implementation
Future<void> initialize(RelevaClient client) async {
if (_initialized && !identical(_client, client)) {
// A different client is re-initialising (multi-tenant / hot reload /
// test reuse). Tear down the old wiring before re-arming so the
// observer and stream don't keep firing against a stale reference.
dispose();
}
_client = client;
if (_initialized) return;
_initialized = true;
WidgetsBinding.instance.addObserver(this);
_tokenRefreshSub = FirebaseMessaging.instance.onTokenRefresh.listen(
(newToken) {
// ignore: discarded_futures
_maybeReregister(newToken);
},
);
// Cold-start refresh — covers the case where FCM rotated the token while
// the app was uninstalled / not running.
await refresh(client);
}