init static method

Future<void> init({
  1. required String apiKey,
  2. required BuildContext context,
})

Connects to https://api.flushkit.dev/v1/listen and starts displaying remote Flushbar notifications.

Call this once, after the root MaterialApp has been mounted and a valid BuildContext is available. The safest place is inside a WidgetsBinding.instance.addPostFrameCallback in initState:

@override
void initState() {
  super.initState();
  WidgetsBinding.instance.addPostFrameCallback((_) {
    FlushbarRemote.init(apiKey: 'YOUR_KEY', context: context);
  });
}
  • apiKey — Your FlushKit API key.
  • context — A BuildContext that remains valid for the lifetime of the app (the root widget's context is ideal).

Implementation

static Future<void> init({
  required String apiKey,
  required BuildContext context,
}) async {
  _apiKey = apiKey;
  _context = context;
  _disposed = false;

  _prefs = await SharedPreferences.getInstance();
  _lastSeen = _prefs!.getInt('fk_last_seen') ?? 0;
  _seenIds = _prefs!.getStringList('fk_seen_ids') ?? [];

  WidgetsBinding.instance.addObserver(_instance);
  _connect();
}