diff --git a/app/lib/pages/chat_page.dart b/app/lib/pages/chat_page.dart index 6d6a33c..f267b77 100644 --- a/app/lib/pages/chat_page.dart +++ b/app/lib/pages/chat_page.dart @@ -1,7 +1,6 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import '../providers/api_provider.dart'; -import '../widgets/chat_bubble.dart'; import '../widgets/button_row.dart'; // Import the ButtonRow widget import 'package:file_picker/file_picker.dart'; import 'dart:typed_data'; @@ -72,6 +71,18 @@ class _ChatBodyState extends State { return Column( children: [ + if (apiProvider.initialMessage.isNotEmpty) + Padding( + padding: const EdgeInsets.all(16.0), + child: Container( + color: Colors.white, + padding: const EdgeInsets.all(12.0), + child: Text( + apiProvider.initialMessage, + style: const TextStyle(fontSize: 16, color: Colors.black), + ), + ), + ), ButtonRow(onButtonPressed: _handleButtonPress), // Add the button row Expanded( child: Scrollbar( diff --git a/app/lib/providers/api_provider.dart b/app/lib/providers/api_provider.dart index 0f73afb..e5e7d53 100644 --- a/app/lib/providers/api_provider.dart +++ b/app/lib/providers/api_provider.dart @@ -9,9 +9,11 @@ import '../models/models.dart'; class ApiProvider with ChangeNotifier { final List _messages = []; bool _isLoading = false; + String _initialMessage = ''; List get messages => _messages; bool get isLoading => _isLoading; + String get initialMessage => _initialMessage; ApiProvider() { _fetchInitialMessage(); // Fetch the initial message when ApiProvider is created @@ -23,18 +25,14 @@ class ApiProvider with ChangeNotifier { var response = await http.get(url); if (response.statusCode == 200) { var responseBody = utf8.decode(response.bodyBytes); - _addMessage(Message( - message: responseBody, - isUserMessage: false, - )); + _initialMessage = responseBody; + notifyListeners(); } else { throw Exception('Failed to fetch initial message'); } } catch (e) { - _addMessage(Message( - message: 'Error fetching initial message: $e', - isUserMessage: false, - )); + _initialMessage = 'Error fetching initial message: $e'; + notifyListeners(); } } @@ -75,64 +73,6 @@ class ApiProvider with ChangeNotifier { } } - Future uploadDocument(Uint8List fileBytes, String fileName) async { - var url = Uri.parse('https://government-assistant-api-183025368636.us-central1.run.app/validate-document'); - try { - _setLoading(true); - _addMessage(Message( - message: 'Uploading document...', - isUserMessage: true, - )); - - // Logowanie wykrytego MIME Type - String mimeType = _detectMimeType(fileName); - print("Detected MIME Type: $mimeType"); - - var request = http.MultipartRequest('POST', url); - request.files.add(http.MultipartFile.fromBytes( - 'file', - fileBytes, - filename: fileName, - contentType: MediaType.parse(mimeType), - )); - - var streamedResponse = await request.send(); - var response = await http.Response.fromStream(streamedResponse); - - if (response.statusCode == 200) { - var responseBody = utf8.decode(response.bodyBytes); - var responseData = json.decode(responseBody); - - String resultMessage = responseData['content'] ?? 'No content available'; - _addMessage(Message( - message: resultMessage, - isUserMessage: false, - isMarkdown: true, - )); - } else if (response.statusCode == 400) { - var responseBody = utf8.decode(response.bodyBytes); - var responseData = json.decode(responseBody); - - _addMessage(Message( - message: responseData['detail'] ?? 'Unsupported file type.', - isUserMessage: false, - )); - } else { - _addMessage(Message( - message: 'Document upload failed: ${response.reasonPhrase}', - isUserMessage: false, - )); - } - } catch (e) { - _addMessage(Message( - message: 'Error occurred: $e', - isUserMessage: false, - )); - } finally { - _setLoading(false); - } - } - void _addMessage(Message message) { _messages.add(message); notifyListeners(); @@ -142,15 +82,4 @@ class ApiProvider with ChangeNotifier { _isLoading = isLoading; notifyListeners(); } - - String _detectMimeType(String fileName) { - if (fileName.endsWith('.pdf')) { - return 'application/pdf'; - } else if (fileName.endsWith('.docx')) { - return 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'; - } else { - print('Unsupported file type: $fileName'); - throw Exception('Unsupported file type. Only PDF and DOCX are allowed.'); - } - } } diff --git a/app/lib/widgets/button_row.dart b/app/lib/widgets/button_row.dart index c49662f..8d2c9cb 100644 --- a/app/lib/widgets/button_row.dart +++ b/app/lib/widgets/button_row.dart @@ -49,7 +49,7 @@ class ButtonRow extends StatelessWidget { ), const SizedBox(width: 10), ElevatedButton( - onPressed: () => onButtonPressed("Something Else"), + onPressed: () => onButtonPressed("Social Benefits"), style: ElevatedButton.styleFrom( backgroundColor: Colors.grey[800], shape: RoundedRectangleBorder( @@ -57,7 +57,7 @@ class ButtonRow extends StatelessWidget { ), minimumSize: const Size(100, 40), ), - child: const Text("Something Else", style: TextStyle(color: Colors.white)), + child: const Text("Social Benefits", style: TextStyle(color: Colors.white)), ), ], ),