diff --git a/lib/consts.dart b/lib/consts.dart index 1d7aa6e4..221bcb59 100644 --- a/lib/consts.dart +++ b/lib/consts.dart @@ -450,6 +450,7 @@ const kLabelDownload = "Download"; const kLabelSaving = "Saving"; const kLabelSaved = "Saved"; const kLabelCode = "Code"; +const kLabelDashBot = "DashBot"; const kLabelDuplicate = "Duplicate"; const kLabelSelect = "Select"; const kLabelContinue = "Continue"; diff --git a/lib/dashbot/dashbot_tab.dart b/lib/dashbot/dashbot_tab.dart new file mode 100644 index 00000000..f80413f4 --- /dev/null +++ b/lib/dashbot/dashbot_tab.dart @@ -0,0 +1,72 @@ +import 'package:apidash/providers/providers.dart'; +import 'package:apidash_design_system/apidash_design_system.dart'; +import 'core/routes/dashbot_router.dart'; +import 'core/routes/dashbot_routes.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; + +class DashbotTab extends ConsumerStatefulWidget { + const DashbotTab({super.key}); + + @override + ConsumerState createState() => _DashbotTabState(); +} + +class _DashbotTabState extends ConsumerState + with AutomaticKeepAliveClientMixin { + static final GlobalKey _navKey = GlobalKey(); + + @override + bool get wantKeepAlive => true; + + @override + Widget build(BuildContext context) { + super.build(context); + final currentRequest = ref.watch(selectedRequestModelProvider); + + // If a response arrives while user is on default, navigate to home. + ref.listen( + selectedRequestModelProvider, + (prev, next) { + if (next?.responseStatus != null) { + _navKey.currentState?.pushNamed(DashbotRoutes.dashbotHome); + } + }, + ); + + return WillPopScope( + onWillPop: () async { + final canPop = _navKey.currentState?.canPop() ?? false; + if (canPop) { + _navKey.currentState?.pop(); + return false; + } + return true; + }, + child: Padding( + padding: kP10, + child: Container( + decoration: BoxDecoration( + color: Theme.of(context).colorScheme.surfaceContainerLow, + border: Border.all( + color: Theme.of(context).colorScheme.surfaceContainerHighest), + borderRadius: kBorderRadius8, + ), + child: Column( + children: [ + Expanded( + child: Navigator( + key: _navKey, + initialRoute: currentRequest?.responseStatus == null + ? DashbotRoutes.dashbotDefault + : DashbotRoutes.dashbotHome, + onGenerateRoute: generateRoute, + ), + ), + ], + ), + ), + ), + ); + } +} diff --git a/lib/dashbot/features/home/view/pages/home_page.dart b/lib/dashbot/features/home/view/pages/home_page.dart index 8d092c69..9e98cc67 100644 --- a/lib/dashbot/features/home/view/pages/home_page.dart +++ b/lib/dashbot/features/home/view/pages/home_page.dart @@ -93,17 +93,23 @@ class _DashbotHomePageState extends ConsumerState { ); }, ), - if (currentRequest?.httpResponseModel?.statusCode != null && - currentRequest?.httpResponseModel?.statusCode == 200) ...[ + ], + ), + if (currentRequest?.httpResponseModel?.statusCode != null && + currentRequest?.httpResponseModel?.statusCode == 200) ...[ + const SizedBox(height: 12), + Row( + children: const [ Expanded( child: GenerateToolButton(), ), + SizedBox(width: 8), Expanded( child: AIGenerateUIButton(), ), ], - ], - ), + ), + ], ], ), ); diff --git a/lib/screens/mobile/requests_page/request_tabs.dart b/lib/screens/mobile/requests_page/request_tabs.dart index 5189ba23..28018814 100644 --- a/lib/screens/mobile/requests_page/request_tabs.dart +++ b/lib/screens/mobile/requests_page/request_tabs.dart @@ -6,6 +6,7 @@ import '../../common_widgets/common_widgets.dart'; import '../../home_page/editor_pane/details_card/response_pane.dart'; import '../../home_page/editor_pane/editor_request.dart'; import '../../home_page/editor_pane/url_card.dart'; +import '../../../dashbot/dashbot_tab.dart'; class RequestTabs extends StatelessWidget { const RequestTabs({ @@ -30,6 +31,7 @@ class RequestTabs extends StatelessWidget { Tab(text: kLabelRequest), Tab(text: kLabelResponse), Tab(text: kLabelCode), + Tab(text: kLabelDashBot) ], ), Expanded(child: RequestTabviews(controller: controller)) @@ -53,6 +55,7 @@ class RequestTabviews extends StatelessWidget { child: ResponsePane(), ), CodePane(), + DashbotTab(), ], ); } diff --git a/lib/screens/mobile/requests_page/requests_page.dart b/lib/screens/mobile/requests_page/requests_page.dart index c335b646..6d7506ab 100644 --- a/lib/screens/mobile/requests_page/requests_page.dart +++ b/lib/screens/mobile/requests_page/requests_page.dart @@ -30,7 +30,7 @@ class _RequestResponsePageState extends ConsumerState final name = getRequestTitleFromUrl( ref.watch(selectedRequestModelProvider.select((value) => value?.name))); final TabController requestTabController = - useTabController(initialLength: 3, vsync: this); + useTabController(initialLength: 4, vsync: this); return DrawerSplitView( scaffoldKey: kHomeScaffoldKey, title: Row(