init method
Implementation
Future<void> init({
required ValueGetter<GlobalKey<NavigatorState>> navigatorKey,
bool showNotification = true,
}) async {
_navigatorKey = navigatorKey;
_showNotification = showNotification;
if (_initialized || _initializing) return;
_initializing = true;
try {
// Start shake-to-open
_shakeDetector.startListening(_onShake);
await _plugin.initialize(
settings: const InitializationSettings(
android: AndroidInitializationSettings('@mipmap/ic_launcher'),
iOS: DarwinInitializationSettings(),
),
onDidReceiveNotificationResponse: (_) {
// Read navigatorKey at tap-time — at init-time the navigator is not
// yet mounted (DI runs before runApp).
Future<void>.delayed(Duration.zero, _openInspector);
},
);
// iOS — provisional permission: silent delivery to notification centre,
// no banner, no permission dialog shown to the user.
await _plugin
.resolvePlatformSpecificImplementation<
IOSFlutterLocalNotificationsPlugin
>()
?.requestPermissions(
alert: false,
badge: false,
sound: false,
provisional: true,
);
// Android 13+ runtime permission
await _plugin
.resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin
>()
?.requestNotificationsPermission();
_initialized = true;
HttpLogStore.instance.onEntryCompleted = _notify;
} catch (e) {
debugPrint('[HttpInspector] init failed: $e');
} finally {
_initializing = false;
}
}