Files
apidash/lib/dashbot/core/utils/show_dashbot.dart
2025-09-02 11:57:31 +05:30

35 lines
1.0 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../dashbot_dashboard.dart';
import '../providers/dashbot_window_notifier.dart';
/// Optionally pass provider overrides (e.g., dashbotRequestContextProvider)
/// so the host app can feed live context into Dashbot.
void showDashbotWindow(
BuildContext context,
WidgetRef ref, {
List<Override>? overrides,
}) {
final isDashbotActive = ref.read(dashbotWindowNotifierProvider).isActive;
final windowNotifier = ref.read(dashbotWindowNotifierProvider.notifier);
if (isDashbotActive) return;
final overlay = Overlay.of(context);
OverlayEntry? entry;
entry = OverlayEntry(
builder:
(context) => ProviderScope(
overrides: overrides ?? const [],
child: DashbotWindow(
onClose: () {
entry?.remove();
windowNotifier.toggleActive();
},
),
),
);
windowNotifier.toggleActive();
overlay.insert(entry);
}