fix formatting and imports

This commit is contained in:
Ashita Prasad
2025-05-17 23:03:43 +05:30
parent 962bf0f230
commit 2863bdd951
9 changed files with 128 additions and 62 deletions

View File

@@ -7,7 +7,11 @@ class ChatBubble extends StatelessWidget {
final String message;
final bool isUser;
const ChatBubble({super.key, required this.message, this.isUser = false});
const ChatBubble({
super.key,
required this.message,
this.isUser = false,
});
@override
Widget build(BuildContext context) {

View File

@@ -5,12 +5,18 @@ import 'package:flutter_highlighter/flutter_highlighter.dart';
import 'package:flutter_highlighter/themes/monokai-sublime.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
Widget renderContent(BuildContext context, String text) {
Widget renderContent(
BuildContext context,
String text,
) {
if (text.isEmpty) {
return const Text("No content to display.");
}
final codeBlockPattern = RegExp(r'```(\w+)?\n([\s\S]*?)```', multiLine: true);
final codeBlockPattern = RegExp(
r'```(\w+)?\n([\s\S]*?)```',
multiLine: true,
);
final matches = codeBlockPattern.allMatches(text);
if (matches.isEmpty) {
@@ -22,8 +28,10 @@ Widget renderContent(BuildContext context, String text) {
for (var match in matches) {
if (match.start > lastEnd) {
children
.add(_renderMarkdown(context, text.substring(lastEnd, match.start)));
children.add(_renderMarkdown(
context,
text.substring(lastEnd, match.start),
));
}
final language = match.group(1) ?? 'text';
@@ -43,7 +51,10 @@ Widget renderContent(BuildContext context, String text) {
);
}
Widget _renderMarkdown(BuildContext context, String markdown) {
Widget _renderMarkdown(
BuildContext context,
String markdown,
) {
return MarkdownBody(
data: markdown,
selectable: true,
@@ -53,7 +64,11 @@ Widget _renderMarkdown(BuildContext context, String markdown) {
);
}
Widget _renderCodeBlock(BuildContext context, String language, String code) {
Widget _renderCodeBlock(
BuildContext context,
String language,
String code,
) {
if (language == 'json') {
try {
final prettyJson =
@@ -63,7 +78,10 @@ Widget _renderCodeBlock(BuildContext context, String language, String code) {
color: Theme.of(context).colorScheme.surfaceContainerLow,
child: SelectableText(
prettyJson,
style: const TextStyle(fontFamily: 'monospace', fontSize: 12),
style: const TextStyle(
fontFamily: 'monospace',
fontSize: 12,
),
),
);
} catch (e) {
@@ -78,7 +96,10 @@ Widget _renderCodeBlock(BuildContext context, String language, String code) {
code,
language: language,
theme: monokaiSublimeTheme,
textStyle: const TextStyle(fontFamily: 'monospace', fontSize: 12),
textStyle: const TextStyle(
fontFamily: 'monospace',
fontSize: 12,
),
),
);
} catch (e) {
@@ -87,14 +108,20 @@ Widget _renderCodeBlock(BuildContext context, String language, String code) {
}
}
Widget _renderFallbackCode(BuildContext context, String code) {
Widget _renderFallbackCode(
BuildContext context,
String code,
) {
return Container(
padding: const EdgeInsets.all(8),
color: Theme.of(context).colorScheme.surfaceContainerLow,
child: SelectableText(
code,
style: const TextStyle(
fontFamily: 'monospace', fontSize: 12, color: Colors.red),
fontFamily: 'monospace',
fontSize: 12,
color: Colors.red,
),
),
);
}

View File

@@ -53,7 +53,8 @@ class _DashBotWidgetState extends ConsumerState<DashBotWidget> {
final testCases = response.replaceFirst("TEST_CASES_HIDDEN\n", "");
ref.read(chatMessagesProvider.notifier).addMessage({
'role': 'bot',
'message': "Test cases generated successfully. Click the button below to run them.",
'message':
"Test cases generated successfully. Click the button below to run them.",
'testCases': testCases,
'showTestButton': true,
});
@@ -113,18 +114,18 @@ class _DashBotWidgetState extends ConsumerState<DashBotWidget> {
child: isMinimized
? _buildMinimizedView(context)
: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_buildHeader(context),
const SizedBox(height: 12),
_buildQuickActions(showDebugButton),
const SizedBox(height: 12),
Expanded(child: _buildChatArea(messages)),
if (_isLoading) _buildLoadingIndicator(),
const SizedBox(height: 10),
_buildInputArea(context),
],
),
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_buildHeader(context),
const SizedBox(height: 12),
_buildQuickActions(showDebugButton),
const SizedBox(height: 12),
Expanded(child: _buildChatArea(messages)),
if (_isLoading) _buildLoadingIndicator(),
const SizedBox(height: 10),
_buildInputArea(context),
],
),
);
}
@@ -150,7 +151,8 @@ class _DashBotWidgetState extends ConsumerState<DashBotWidget> {
),
tooltip: isMinimized ? 'Maximize' : 'Minimize',
onPressed: () {
ref.read(dashBotMinimizedProvider.notifier).state = !isMinimized;
ref.read(dashBotMinimizedProvider.notifier).state =
!isMinimized;
},
),
IconButton(
@@ -214,7 +216,8 @@ class _DashBotWidgetState extends ConsumerState<DashBotWidget> {
icon: const Icon(Icons.bug_report_outlined, size: 16),
label: const Text("Debug"),
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
padding:
const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
visualDensity: VisualDensity.compact,
),
),

View File

@@ -8,7 +8,10 @@ import 'content_renderer.dart';
class TestRunnerWidget extends ConsumerStatefulWidget {
final String testCases;
const TestRunnerWidget({Key? key, required this.testCases}) : super(key: key);
const TestRunnerWidget({
Key? key,
required this.testCases,
}) : super(key: key);
@override
ConsumerState<TestRunnerWidget> createState() => _TestRunnerWidgetState();
@@ -78,7 +81,8 @@ class _TestRunnerWidgetState extends ConsumerState<TestRunnerWidget> {
String method = "GET";
if (command.contains("-X POST") || command.contains("--request POST")) {
method = "POST";
} else if (command.contains("-X PUT") || command.contains("--request PUT")) {
} else if (command.contains("-X PUT") ||
command.contains("--request PUT")) {
method = "PUT";
}
@@ -139,9 +143,9 @@ class _TestRunnerWidgetState extends ConsumerState<TestRunnerWidget> {
title: const Text('API Test Runner'),
content: const Text(
'Run generated API tests:\n\n'
'• "Run All" executes all tests\n'
'• "Run" executes a single test\n'
'• "Copy" copies the curl command',
'• "Run All" executes all tests\n'
'• "Run" executes a single test\n'
'• "Copy" copies the curl command',
),
actions: [
TextButton(
@@ -189,9 +193,8 @@ class _TestRunnerWidgetState extends ConsumerState<TestRunnerWidget> {
test['description'] ?? "Test case ${index + 1}",
style: TextStyle(
fontWeight: FontWeight.bold,
color: hasResult
? (isSuccess ? Colors.green : Colors.red)
: null,
color:
hasResult ? (isSuccess ? Colors.green : Colors.red) : null,
),
),
subtitle: Text('Test ${index + 1} of ${_parsedTests.length}'),
@@ -241,7 +244,8 @@ class _TestRunnerWidgetState extends ConsumerState<TestRunnerWidget> {
padding: const EdgeInsets.all(8),
margin: const EdgeInsets.only(top: 4, bottom: 16),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surfaceContainerLow,
color:
Theme.of(context).colorScheme.surfaceContainerLow,
borderRadius: BorderRadius.circular(4),
),
width: double.infinity,