mirror of
https://github.com/foss42/apidash.git
synced 2025-12-02 10:49:49 +08:00
feat: integrate DashbotTab into mobile requests page
This commit is contained in:
72
lib/dashbot/dashbot_tab.dart
Normal file
72
lib/dashbot/dashbot_tab.dart
Normal file
@@ -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<DashbotTab> createState() => _DashbotTabState();
|
||||
}
|
||||
|
||||
class _DashbotTabState extends ConsumerState<DashbotTab>
|
||||
with AutomaticKeepAliveClientMixin {
|
||||
static final GlobalKey<NavigatorState> _navKey = GlobalKey<NavigatorState>();
|
||||
|
||||
@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,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -93,17 +93,23 @@ class _DashbotHomePageState extends ConsumerState<DashbotHomePage> {
|
||||
);
|
||||
},
|
||||
),
|
||||
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(),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user