mirror of
https://github.com/foss42/apidash.git
synced 2025-12-01 18:28:25 +08:00
feat: integrate dashbot tab for desktop devices
This commit is contained in:
@@ -12,7 +12,7 @@ class DashbotWindowModel {
|
||||
this.right = 50,
|
||||
this.bottom = 100,
|
||||
this.isActive = false,
|
||||
this.isPopped = false,
|
||||
this.isPopped = true,
|
||||
});
|
||||
|
||||
DashbotWindowModel copyWith({
|
||||
|
||||
@@ -27,6 +27,10 @@ class DashbotWindowNotifier extends StateNotifier<DashbotWindowModel> {
|
||||
void toggleActive() {
|
||||
state = state.copyWith(isActive: !state.isActive);
|
||||
}
|
||||
|
||||
void togglePopped() {
|
||||
state = state.copyWith(isPopped: !state.isPopped);
|
||||
}
|
||||
}
|
||||
|
||||
final dashbotWindowNotifierProvider =
|
||||
|
||||
@@ -12,14 +12,15 @@ void showDashbotWindow(
|
||||
List<Override>? overrides,
|
||||
}) {
|
||||
final isDashbotActive = ref.read(dashbotWindowNotifierProvider).isActive;
|
||||
final isDashbotPopped = ref.read(dashbotWindowNotifierProvider).isPopped;
|
||||
final windowNotifier = ref.read(dashbotWindowNotifierProvider.notifier);
|
||||
if (isDashbotActive) return;
|
||||
if (!isDashbotPopped) return;
|
||||
final overlay = Overlay.of(context);
|
||||
OverlayEntry? entry;
|
||||
|
||||
entry = OverlayEntry(
|
||||
builder:
|
||||
(context) => ProviderScope(
|
||||
builder: (context) => ProviderScope(
|
||||
overrides: overrides ?? const [],
|
||||
child: DashbotWindow(
|
||||
onClose: () {
|
||||
@@ -29,6 +30,7 @@ void showDashbotWindow(
|
||||
),
|
||||
),
|
||||
);
|
||||
// Mark active and insert overlay
|
||||
windowNotifier.toggleActive();
|
||||
overlay.insert(entry);
|
||||
}
|
||||
|
||||
@@ -25,6 +25,16 @@ class DashbotWindow extends ConsumerWidget {
|
||||
final settings = ref.watch(settingsProvider);
|
||||
final currentRequest = ref.watch(selectedRequestModelProvider);
|
||||
|
||||
// Close the overlay when the window is not popped anymore
|
||||
ref.listen(
|
||||
dashbotWindowNotifierProvider.select((s) => s.isPopped),
|
||||
(prev, next) {
|
||||
if (prev == true && next == false) {
|
||||
onClose();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
ref.listen(
|
||||
selectedRequestModelProvider,
|
||||
(current, next) {
|
||||
@@ -108,6 +118,20 @@ class DashbotWindow extends ConsumerWidget {
|
||||
),
|
||||
],
|
||||
),
|
||||
Spacer(),
|
||||
IconButton(
|
||||
icon: Icon(
|
||||
Icons.open_in_new,
|
||||
color:
|
||||
Theme.of(context).colorScheme.onPrimary,
|
||||
),
|
||||
onPressed: () {
|
||||
ref
|
||||
.read(dashbotWindowNotifierProvider
|
||||
.notifier)
|
||||
.togglePopped();
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
icon: Icon(
|
||||
Icons.close,
|
||||
|
||||
@@ -4,6 +4,8 @@ import 'core/routes/dashbot_router.dart';
|
||||
import 'core/routes/dashbot_routes.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'core/providers/dashbot_window_notifier.dart';
|
||||
import 'core/utils/show_dashbot.dart';
|
||||
|
||||
class DashbotTab extends ConsumerStatefulWidget {
|
||||
const DashbotTab({super.key});
|
||||
@@ -54,6 +56,49 @@ class _DashbotTabState extends ConsumerState<DashbotTab>
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding: kP8,
|
||||
child: Align(
|
||||
alignment: AlignmentGeometry.centerRight,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
IconButton(
|
||||
icon: Icon(
|
||||
Icons.close_fullscreen,
|
||||
),
|
||||
onPressed: () {
|
||||
ref
|
||||
.read(dashbotWindowNotifierProvider.notifier)
|
||||
.togglePopped();
|
||||
|
||||
final newState =
|
||||
ref.read(dashbotWindowNotifierProvider);
|
||||
if (newState.isPopped) {
|
||||
showDashbotWindow(context, ref);
|
||||
}
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
final isActive =
|
||||
ref.read(dashbotWindowNotifierProvider).isActive;
|
||||
|
||||
ref
|
||||
.read(dashbotWindowNotifierProvider.notifier)
|
||||
.togglePopped();
|
||||
if (isActive) {
|
||||
ref
|
||||
.read(dashbotWindowNotifierProvider.notifier)
|
||||
.toggleActive();
|
||||
}
|
||||
},
|
||||
icon: Icon(Icons.close),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Navigator(
|
||||
key: _navKey,
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'package:apidash/dashbot/core/providers/dashbot_window_notifier.dart';
|
||||
import 'package:apidash/dashbot/dashbot_tab.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:apidash/providers/providers.dart';
|
||||
@@ -12,10 +14,15 @@ class EditorPaneRequestDetailsCard extends ConsumerWidget {
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final codePaneVisible = ref.watch(codePaneVisibleStateProvider);
|
||||
final isDashbotPopped = ref.watch(dashbotWindowNotifierProvider).isPopped;
|
||||
return RequestDetailsCard(
|
||||
child: EqualSplitView(
|
||||
leftWidget: const EditRequestPane(),
|
||||
rightWidget: codePaneVisible ? const CodePane() : const ResponsePane(),
|
||||
rightWidget: !isDashbotPopped
|
||||
? DashbotTab()
|
||||
: codePaneVisible
|
||||
? const CodePane()
|
||||
: const ResponsePane(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user