Integrated AI Chatbot Widget

This commit is contained in:
siddu015
2025-02-22 16:10:38 +05:30
parent 40e019f12c
commit 1270a8f53f
7 changed files with 322 additions and 128 deletions

View File

@@ -4,6 +4,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:apidash/providers/providers.dart';
import 'package:apidash/widgets/widgets.dart';
import 'package:apidash/consts.dart';
import '../widgets/chatbot_widget.dart';
import 'common_widgets/common_widgets.dart';
import 'envvar/environment_page.dart';
import 'home_page/home_page.dart';
@@ -124,6 +125,19 @@ class Dashboard extends ConsumerWidget {
],
),
),
// Add this to your DashboardScreen's build method:
floatingActionButton: FloatingActionButton(
onPressed: () => showModalBottomSheet(
context: context,
isScrollControlled: true,
builder: (context) => const Padding(
padding: EdgeInsets.all(16.0),
child: ChatbotWidget(),
),
),
child: const Icon(Icons.help_outline),
),
);
}
}

View File

@@ -54,6 +54,8 @@ class ResponseDetails extends ConsumerWidget {
.watch(selectedRequestModelProvider.select((value) => value?.message));
final responseModel = ref.watch(selectedRequestModelProvider
.select((value) => value?.httpResponseModel));
final ollamaService = ref.watch(ollamaServiceProvider);
return Column(
children: [
ResponsePaneHeader(
@@ -67,6 +69,25 @@ class ResponseDetails extends ConsumerWidget {
const Expanded(
child: ResponseTabs(),
),
if (responseModel?.body != null) // Show button only if a response exists
Padding(
padding: const EdgeInsets.all(8.0),
child: ElevatedButton(
onPressed: () async {
final explanation = await ollamaService.explainApiResponse(
responseModel!.body as Map<String, dynamic>, // Pass the actual response data
);
showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Text('Explanation'),
content: Text(explanation),
),
);
},
child: const Text('Explain Response'),
),
),
],
);
}