mirror of
https://github.com/foss42/apidash.git
synced 2025-12-02 02:39:19 +08:00
feat: integrate dashbot tab for desktop devices
This commit is contained in:
@@ -12,7 +12,7 @@ class DashbotWindowModel {
|
|||||||
this.right = 50,
|
this.right = 50,
|
||||||
this.bottom = 100,
|
this.bottom = 100,
|
||||||
this.isActive = false,
|
this.isActive = false,
|
||||||
this.isPopped = false,
|
this.isPopped = true,
|
||||||
});
|
});
|
||||||
|
|
||||||
DashbotWindowModel copyWith({
|
DashbotWindowModel copyWith({
|
||||||
|
|||||||
@@ -27,6 +27,10 @@ class DashbotWindowNotifier extends StateNotifier<DashbotWindowModel> {
|
|||||||
void toggleActive() {
|
void toggleActive() {
|
||||||
state = state.copyWith(isActive: !state.isActive);
|
state = state.copyWith(isActive: !state.isActive);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void togglePopped() {
|
||||||
|
state = state.copyWith(isPopped: !state.isPopped);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final dashbotWindowNotifierProvider =
|
final dashbotWindowNotifierProvider =
|
||||||
|
|||||||
@@ -12,14 +12,15 @@ void showDashbotWindow(
|
|||||||
List<Override>? overrides,
|
List<Override>? overrides,
|
||||||
}) {
|
}) {
|
||||||
final isDashbotActive = ref.read(dashbotWindowNotifierProvider).isActive;
|
final isDashbotActive = ref.read(dashbotWindowNotifierProvider).isActive;
|
||||||
|
final isDashbotPopped = ref.read(dashbotWindowNotifierProvider).isPopped;
|
||||||
final windowNotifier = ref.read(dashbotWindowNotifierProvider.notifier);
|
final windowNotifier = ref.read(dashbotWindowNotifierProvider.notifier);
|
||||||
if (isDashbotActive) return;
|
if (isDashbotActive) return;
|
||||||
|
if (!isDashbotPopped) return;
|
||||||
final overlay = Overlay.of(context);
|
final overlay = Overlay.of(context);
|
||||||
OverlayEntry? entry;
|
OverlayEntry? entry;
|
||||||
|
|
||||||
entry = OverlayEntry(
|
entry = OverlayEntry(
|
||||||
builder:
|
builder: (context) => ProviderScope(
|
||||||
(context) => ProviderScope(
|
|
||||||
overrides: overrides ?? const [],
|
overrides: overrides ?? const [],
|
||||||
child: DashbotWindow(
|
child: DashbotWindow(
|
||||||
onClose: () {
|
onClose: () {
|
||||||
@@ -29,6 +30,7 @@ void showDashbotWindow(
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
// Mark active and insert overlay
|
||||||
windowNotifier.toggleActive();
|
windowNotifier.toggleActive();
|
||||||
overlay.insert(entry);
|
overlay.insert(entry);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,16 @@ class DashbotWindow extends ConsumerWidget {
|
|||||||
final settings = ref.watch(settingsProvider);
|
final settings = ref.watch(settingsProvider);
|
||||||
final currentRequest = ref.watch(selectedRequestModelProvider);
|
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(
|
ref.listen(
|
||||||
selectedRequestModelProvider,
|
selectedRequestModelProvider,
|
||||||
(current, next) {
|
(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(
|
IconButton(
|
||||||
icon: Icon(
|
icon: Icon(
|
||||||
Icons.close,
|
Icons.close,
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import 'core/routes/dashbot_router.dart';
|
|||||||
import 'core/routes/dashbot_routes.dart';
|
import 'core/routes/dashbot_routes.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.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 {
|
class DashbotTab extends ConsumerStatefulWidget {
|
||||||
const DashbotTab({super.key});
|
const DashbotTab({super.key});
|
||||||
@@ -54,6 +56,49 @@ class _DashbotTabState extends ConsumerState<DashbotTab>
|
|||||||
),
|
),
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
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(
|
Expanded(
|
||||||
child: Navigator(
|
child: Navigator(
|
||||||
key: _navKey,
|
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/material.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:apidash/providers/providers.dart';
|
import 'package:apidash/providers/providers.dart';
|
||||||
@@ -12,10 +14,15 @@ class EditorPaneRequestDetailsCard extends ConsumerWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
final codePaneVisible = ref.watch(codePaneVisibleStateProvider);
|
final codePaneVisible = ref.watch(codePaneVisibleStateProvider);
|
||||||
|
final isDashbotPopped = ref.watch(dashbotWindowNotifierProvider).isPopped;
|
||||||
return RequestDetailsCard(
|
return RequestDetailsCard(
|
||||||
child: EqualSplitView(
|
child: EqualSplitView(
|
||||||
leftWidget: const EditRequestPane(),
|
leftWidget: const EditRequestPane(),
|
||||||
rightWidget: codePaneVisible ? const CodePane() : const ResponsePane(),
|
rightWidget: !isDashbotPopped
|
||||||
|
? DashbotTab()
|
||||||
|
: codePaneVisible
|
||||||
|
? const CodePane()
|
||||||
|
: const ResponsePane(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user