IA Funcinonal
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../services/ai_recommendation_service.dart';
|
||||
import '../theme/app_theme.dart';
|
||||
|
||||
class AiChatScreen extends StatefulWidget {
|
||||
const AiChatScreen({super.key});
|
||||
@@ -21,19 +22,25 @@ class _AiChatScreenState extends State<AiChatScreen> {
|
||||
];
|
||||
bool _isLoading = false;
|
||||
|
||||
Future<void> _sendMessage([String? suggestion]) async {
|
||||
Future<void> _sendMessage({
|
||||
String? suggestion,
|
||||
bool silent = false,
|
||||
bool hideUserMessage = false,
|
||||
}) async {
|
||||
final text = (suggestion ?? _controller.text).trim();
|
||||
if (text.isEmpty || _isLoading) return;
|
||||
|
||||
setState(() {
|
||||
_messages.add(_ChatMessage(text: text, isUser: true));
|
||||
if (!hideUserMessage) {
|
||||
_messages.add(_ChatMessage(text: text, isUser: true));
|
||||
}
|
||||
_isLoading = true;
|
||||
});
|
||||
_controller.clear();
|
||||
_scrollToBottom();
|
||||
|
||||
try {
|
||||
final response = await _service.recommendForOccasion(text);
|
||||
final response = await _service.sendMessage(text, silent: silent);
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_messages.add(_ChatMessage(text: response, isUser: false));
|
||||
@@ -43,7 +50,7 @@ class _AiChatScreenState extends State<AiChatScreen> {
|
||||
setState(() {
|
||||
_messages.add(
|
||||
_ChatMessage(
|
||||
text: 'Não consegui gerar uma recomendação agora. Tenta novamente.',
|
||||
text: 'Nao consegui gerar uma recomendacao agora. Tenta novamente.',
|
||||
isUser: false,
|
||||
),
|
||||
);
|
||||
@@ -77,24 +84,16 @@ class _AiChatScreenState extends State<AiChatScreen> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: const Color(0xFFFFE5CC),
|
||||
appBar: AppBar(
|
||||
backgroundColor: const Color(0xFF0066CC),
|
||||
elevation: 0,
|
||||
title: const Text(
|
||||
'DayMaker IA',
|
||||
style: TextStyle(color: Colors.white, fontSize: 20),
|
||||
),
|
||||
centerTitle: true,
|
||||
),
|
||||
backgroundColor: AppColors.background,
|
||||
body: SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
_buildHeader(),
|
||||
_buildSuggestions(),
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
controller: _scrollController,
|
||||
padding: const EdgeInsets.all(16),
|
||||
padding: const EdgeInsets.fromLTRB(16, 8, 16, 16),
|
||||
itemCount: _messages.length + (_isLoading ? 1 : 0),
|
||||
itemBuilder: (context, index) {
|
||||
if (_isLoading && index == _messages.length) {
|
||||
@@ -111,6 +110,54 @@ class _AiChatScreenState extends State<AiChatScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildHeader() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.fromLTRB(20, 16, 20, 16),
|
||||
decoration: BoxDecoration(
|
||||
gradient: AppColors.brandGradient,
|
||||
boxShadow: AppShadows.brand,
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 44,
|
||||
height: 44,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withValues(alpha: 0.22),
|
||||
borderRadius: BorderRadius.circular(AppRadius.md),
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.auto_awesome_rounded,
|
||||
color: Colors.white,
|
||||
size: 24,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
const Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'DayMaker IA',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
SizedBox(height: 2),
|
||||
Text(
|
||||
'Pergunta-me sobre o teu dia ou viagem',
|
||||
style: TextStyle(color: Colors.white70, fontSize: 12),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSuggestions() {
|
||||
final suggestions = [
|
||||
'Viagem para Itália',
|
||||
@@ -120,19 +167,18 @@ class _AiChatScreenState extends State<AiChatScreen> {
|
||||
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.fromLTRB(16, 12, 16, 8),
|
||||
color: const Color(0xFFFFE5CC),
|
||||
padding: const EdgeInsets.fromLTRB(16, 14, 16, 8),
|
||||
color: AppColors.background,
|
||||
child: SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Row(
|
||||
children: suggestions.map((suggestion) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(right: 8),
|
||||
child: ActionChip(
|
||||
backgroundColor: Colors.white,
|
||||
side: const BorderSide(color: Color(0xFFE0E0E0)),
|
||||
label: Text(suggestion),
|
||||
onPressed: () => _sendMessage(suggestion),
|
||||
child: AppChip(
|
||||
label: suggestion,
|
||||
icon: Icons.bolt_rounded,
|
||||
onTap: () => _sendMessage(suggestion: suggestion),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
@@ -143,15 +189,25 @@ class _AiChatScreenState extends State<AiChatScreen> {
|
||||
|
||||
Widget _buildInput() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.fromLTRB(12, 8, 12, 12),
|
||||
decoration: const BoxDecoration(color: Colors.white),
|
||||
padding: const EdgeInsets.fromLTRB(12, 10, 12, 14),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surface,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withValues(alpha: 0.04),
|
||||
blurRadius: 16,
|
||||
offset: const Offset(0, -4),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFF5F5F5),
|
||||
borderRadius: BorderRadius.circular(24),
|
||||
color: AppColors.surfaceAlt,
|
||||
borderRadius: BorderRadius.circular(AppRadius.pill),
|
||||
border: Border.all(color: AppColors.border),
|
||||
),
|
||||
child: TextField(
|
||||
controller: _controller,
|
||||
@@ -159,8 +215,10 @@ class _AiChatScreenState extends State<AiChatScreen> {
|
||||
maxLines: 4,
|
||||
textInputAction: TextInputAction.send,
|
||||
onSubmitted: (_) => _sendMessage(),
|
||||
style: AppText.body,
|
||||
decoration: const InputDecoration(
|
||||
hintText: 'Ex: viagem para Itália de 5 dias...',
|
||||
hintText: 'Escreve uma mensagem...',
|
||||
hintStyle: TextStyle(color: AppColors.textTertiary),
|
||||
border: InputBorder.none,
|
||||
contentPadding: EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
@@ -170,18 +228,27 @@ class _AiChatScreenState extends State<AiChatScreen> {
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
SizedBox(
|
||||
const SizedBox(width: 10),
|
||||
Container(
|
||||
width: 48,
|
||||
height: 48,
|
||||
child: ElevatedButton(
|
||||
onPressed: _isLoading ? null : () => _sendMessage(),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: const Color(0xFF0066CC),
|
||||
shape: const CircleBorder(),
|
||||
padding: EdgeInsets.zero,
|
||||
decoration: BoxDecoration(
|
||||
gradient: AppColors.brandGradient,
|
||||
shape: BoxShape.circle,
|
||||
boxShadow: AppShadows.brand,
|
||||
),
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
shape: const CircleBorder(),
|
||||
child: InkWell(
|
||||
customBorder: const CircleBorder(),
|
||||
onTap: _isLoading ? null : () => _sendMessage(),
|
||||
child: const Icon(
|
||||
Icons.send_rounded,
|
||||
color: Colors.white,
|
||||
size: 22,
|
||||
),
|
||||
),
|
||||
child: const Icon(Icons.send, color: Colors.white),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -204,13 +271,8 @@ class _MessageBubble extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final alignment = message.isUser
|
||||
? Alignment.centerRight
|
||||
: Alignment.centerLeft;
|
||||
final backgroundColor = message.isUser
|
||||
? const Color(0xFF0066CC)
|
||||
: Colors.white;
|
||||
final textColor = message.isUser ? Colors.white : const Color(0xFF333333);
|
||||
final isUser = message.isUser;
|
||||
final alignment = isUser ? Alignment.centerRight : Alignment.centerLeft;
|
||||
|
||||
return Align(
|
||||
alignment: alignment,
|
||||
@@ -219,14 +281,25 @@ class _MessageBubble extends StatelessWidget {
|
||||
maxWidth: MediaQuery.of(context).size.width * 0.78,
|
||||
),
|
||||
margin: const EdgeInsets.only(bottom: 10),
|
||||
padding: const EdgeInsets.all(14),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: backgroundColor,
|
||||
borderRadius: BorderRadius.circular(18),
|
||||
gradient: isUser ? AppColors.brandGradient : null,
|
||||
color: isUser ? null : AppColors.surface,
|
||||
borderRadius: BorderRadius.only(
|
||||
topLeft: const Radius.circular(AppRadius.lg),
|
||||
topRight: const Radius.circular(AppRadius.lg),
|
||||
bottomLeft: Radius.circular(isUser ? AppRadius.lg : 4),
|
||||
bottomRight: Radius.circular(isUser ? 4 : AppRadius.lg),
|
||||
),
|
||||
boxShadow: isUser ? AppShadows.brand : AppShadows.soft,
|
||||
),
|
||||
child: Text(
|
||||
message.text,
|
||||
style: TextStyle(color: textColor, fontSize: 15, height: 1.35),
|
||||
style: TextStyle(
|
||||
color: isUser ? Colors.white : AppColors.textPrimary,
|
||||
fontSize: 15,
|
||||
height: 1.4,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -242,15 +315,24 @@ class _TypingBubble extends StatelessWidget {
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Container(
|
||||
margin: const EdgeInsets.only(bottom: 10),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 12),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 14),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(18),
|
||||
color: AppColors.surface,
|
||||
borderRadius: const BorderRadius.only(
|
||||
topLeft: Radius.circular(AppRadius.lg),
|
||||
topRight: Radius.circular(AppRadius.lg),
|
||||
bottomLeft: Radius.circular(4),
|
||||
bottomRight: Radius.circular(AppRadius.lg),
|
||||
),
|
||||
boxShadow: AppShadows.soft,
|
||||
),
|
||||
child: const SizedBox(
|
||||
width: 18,
|
||||
height: 18,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
width: 20,
|
||||
height: 20,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2.2,
|
||||
valueColor: AlwaysStoppedAnimation<Color>(AppColors.primary),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user