Camara e chat IA

This commit is contained in:
2026-05-17 17:05:01 +01:00
parent e8fa39c594
commit 5158d140ca
9 changed files with 196 additions and 121 deletions

View File

@@ -22,10 +22,10 @@ class _AddItemScreenState extends State<AddItemScreen> {
bool _isLoading = false;
Future<void> _pickImage() async {
Future<void> _pickImage(ImageSource source) async {
final picker = ImagePicker();
final image = await picker.pickImage(
source: ImageSource.gallery,
source: source,
maxWidth: 1024,
imageQuality: 80,
);
@@ -34,6 +34,46 @@ class _AddItemScreenState extends State<AddItemScreen> {
}
}
Future<void> _showImageSourcePicker() async {
final source = await showModalBottomSheet<ImageSource>(
context: context,
backgroundColor: Colors.white,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(top: Radius.circular(20)),
),
builder: (context) => SafeArea(
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 12),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
ListTile(
leading: const Icon(
Icons.photo_camera,
color: Color(0xFF0066CC),
),
title: const Text('Tirar foto'),
onTap: () => Navigator.pop(context, ImageSource.camera),
),
ListTile(
leading: const Icon(
Icons.photo_library,
color: Color(0xFF0066CC),
),
title: const Text('Escolher da galeria'),
onTap: () => Navigator.pop(context, ImageSource.gallery),
),
],
),
),
),
);
if (source != null) {
await _pickImage(source);
}
}
@override
void dispose() {
_nameController.dispose();
@@ -185,7 +225,7 @@ class _AddItemScreenState extends State<AddItemScreen> {
// Image picker
Center(
child: GestureDetector(
onTap: _pickImage,
onTap: _showImageSourcePicker,
child: Container(
width: 140,
height: 140,
@@ -297,7 +337,7 @@ class _AddItemScreenState extends State<AddItemScreen> {
value: _selectedCategory,
hint: const Text('Selecione uma categoria'),
isExpanded: true,
items: ITEM_CATEGORIES.map((category) {
items: itemCategories.map((category) {
return DropdownMenuItem<ItemCategory>(
value: category,
child: Row(
@@ -407,13 +447,13 @@ class _AddItemScreenState extends State<AddItemScreen> {
Wrap(
spacing: 8,
runSpacing: 8,
children: CONTEXT_TAGS.map((tag) {
children: contextTags.map((tag) {
final isSelected = _selectedTags.contains(tag.id);
return FilterChip(
label: Text(tag.name),
selected: isSelected,
onSelected: (selected) => _toggleTag(tag.id),
selectedColor: const Color(0xFF0066CC).withOpacity(0.2),
selectedColor: const Color(0xFF0066CC).withValues(alpha: 0.2),
checkmarkColor: const Color(0xFF0066CC),
backgroundColor: Colors.white,
labelStyle: TextStyle(

View File

@@ -1,9 +1,10 @@
import 'package:flutter/material.dart';
import 'package:flutter/material.dart';
import 'package:supabase_flutter/supabase_flutter.dart';
import 'perfil_screen.dart';
import 'add_item_screen.dart';
import 'item_screen.dart';
import 'week_screen.dart';
import 'ai_chat_screen.dart';
import '../constants/item_categories.dart';
class HomeScreen extends StatefulWidget {
@@ -20,6 +21,7 @@ class _HomeScreenState extends State<HomeScreen> {
const _HomeContent(),
const _ItemsScreen(),
const _WeekScreen(),
const _AiScreen(),
const _ProfileScreen(),
];
@@ -36,7 +38,10 @@ class _HomeScreenState extends State<HomeScreen> {
backgroundColor: Colors.white,
type: BottomNavigationBarType.fixed,
items: const [
BottomNavigationBarItem(icon: Icon(Icons.home), label: 'Início'),
BottomNavigationBarItem(
icon: Icon(Icons.home),
label: 'Início',
),
BottomNavigationBarItem(
icon: Icon(Icons.inventory_2_outlined),
label: 'Itens',
@@ -45,6 +50,10 @@ class _HomeScreenState extends State<HomeScreen> {
icon: Icon(Icons.calendar_today_outlined),
label: 'Semana',
),
BottomNavigationBarItem(
icon: Icon(Icons.auto_awesome_outlined),
label: 'IA',
),
BottomNavigationBarItem(
icon: Icon(Icons.person_outline),
label: 'Perfil',
@@ -136,7 +145,7 @@ class _HomeContentState extends State<_HomeContent> {
_isLoading = false;
});
} catch (e) {
print('Error loading home: $e');
debugPrint('Error loading home: $e');
setState(() => _isLoading = false);
}
}
@@ -315,9 +324,9 @@ class _HomeContentState extends State<_HomeContent> {
final imageUrl = (images != null && images.isNotEmpty)
? images.first['image_url']
: null;
final category = ITEM_CATEGORIES.firstWhere(
final category = itemCategories.firstWhere(
(c) => c.id == item['categoria'],
orElse: () => ITEM_CATEGORIES.last,
orElse: () => itemCategories.last,
);
return Container(
width: 80,
@@ -332,7 +341,8 @@ class _HomeContentState extends State<_HomeContent> {
width: 60,
height: 60,
fit: BoxFit.cover,
errorBuilder: (_, __, ___) => _placeholder(category.icon),
errorBuilder: (context, error, stackTrace) =>
_placeholder(category.icon),
)
: _placeholder(category.icon),
),
@@ -352,7 +362,7 @@ class _HomeContentState extends State<_HomeContent> {
return Container(
width: 60,
height: 60,
color: const Color(0xFF0066CC).withOpacity(0.1),
color: const Color(0xFF0066CC).withValues(alpha: 0.1),
alignment: Alignment.center,
child: Text(icon, style: const TextStyle(fontSize: 26)),
);
@@ -391,9 +401,9 @@ class _HomeContentState extends State<_HomeContent> {
final imageUrl = (images != null && images.isNotEmpty)
? images.first['image_url']
: null;
final category = ITEM_CATEGORIES.firstWhere(
final category = itemCategories.firstWhere(
(c) => c.id == item['categoria'],
orElse: () => ITEM_CATEGORIES.last,
orElse: () => itemCategories.last,
);
return Container(
width: 110,
@@ -414,13 +424,13 @@ class _HomeContentState extends State<_HomeContent> {
width: double.infinity,
height: 70,
fit: BoxFit.cover,
errorBuilder: (_, __, ___) =>
errorBuilder: (context, error, stackTrace) =>
_placeholder(category.icon),
)
: Container(
width: double.infinity,
height: 70,
color: const Color(0xFF0066CC).withOpacity(0.1),
color: const Color(0xFF0066CC).withValues(alpha: 0.1),
alignment: Alignment.center,
child: Text(
category.icon,
@@ -468,6 +478,13 @@ class _WeekScreen extends StatelessWidget {
Widget build(BuildContext context) => const WeekScreen();
}
class _AiScreen extends StatelessWidget {
const _AiScreen();
@override
Widget build(BuildContext context) => const AiChatScreen();
}
class _ProfileScreen extends StatelessWidget {
const _ProfileScreen();

View File

@@ -56,7 +56,7 @@ class _ItemScreenState extends State<ItemScreen> {
_isLoading = false;
});
} catch (e) {
print('Error loading items: $e');
debugPrint('Error loading items: $e');
setState(() => _isLoading = false);
}
}
@@ -71,15 +71,15 @@ class _ItemScreenState extends State<ItemScreen> {
String _categoryName(String? id) {
if (id == null) return 'Outros';
return ITEM_CATEGORIES
.firstWhere((c) => c.id == id, orElse: () => ITEM_CATEGORIES.last)
return itemCategories
.firstWhere((c) => c.id == id, orElse: () => itemCategories.last)
.name;
}
String _categoryIcon(String? id) {
if (id == null) return '📦';
return ITEM_CATEGORIES
.firstWhere((c) => c.id == id, orElse: () => ITEM_CATEGORIES.last)
return itemCategories
.firstWhere((c) => c.id == id, orElse: () => itemCategories.last)
.icon;
}
@@ -231,7 +231,7 @@ class _ItemScreenState extends State<ItemScreen> {
scrollDirection: Axis.horizontal,
children: [
_categoryChip(null, 'Todos', '🗂'),
...ITEM_CATEGORIES.map(
...itemCategories.map(
(c) => _categoryChip(c.id, c.name, c.icon),
),
],
@@ -324,7 +324,7 @@ class _ItemScreenState extends State<ItemScreen> {
width: 72,
height: 72,
fit: BoxFit.cover,
errorBuilder: (_, __, ___) =>
errorBuilder: (context, error, stackTrace) =>
_iconPlaceholder(categoryIcon),
)
: _iconPlaceholder(categoryIcon),
@@ -362,7 +362,9 @@ class _ItemScreenState extends State<ItemScreen> {
vertical: 2,
),
decoration: BoxDecoration(
color: const Color(0xFF0066CC).withOpacity(0.1),
color: const Color(
0xFF0066CC,
).withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(6),
),
child: Text(
@@ -430,7 +432,7 @@ class _ItemScreenState extends State<ItemScreen> {
return Container(
width: 72,
height: 72,
color: const Color(0xFF0066CC).withOpacity(0.1),
color: const Color(0xFF0066CC).withValues(alpha: 0.1),
alignment: Alignment.center,
child: Text(icon, style: const TextStyle(fontSize: 32)),
);
@@ -451,10 +453,10 @@ class ItemDetailScreen extends StatelessWidget {
final categoryId = item['categoria'] as String?;
final categoryName = categoryId == null
? 'Outros'
: ITEM_CATEGORIES
: itemCategories
.firstWhere(
(c) => c.id == categoryId,
orElse: () => ITEM_CATEGORIES.last,
orElse: () => itemCategories.last,
)
.name;
final tags = List<String>.from(item['tags'] ?? []);
@@ -482,7 +484,8 @@ class ItemDetailScreen extends StatelessWidget {
width: double.infinity,
height: 250,
fit: BoxFit.cover,
errorBuilder: (_, __, ___) => const SizedBox.shrink(),
errorBuilder: (context, error, stackTrace) =>
const SizedBox.shrink(),
),
),
const SizedBox(height: 20),
@@ -504,7 +507,7 @@ class ItemDetailScreen extends StatelessWidget {
label: Text(t),
backgroundColor: const Color(
0xFF0066CC,
).withOpacity(0.1),
).withValues(alpha: 0.1),
labelStyle: const TextStyle(color: Color(0xFF0066CC)),
),
)
@@ -561,9 +564,9 @@ class _EditItemScreenState extends State<EditItemScreen> {
_nameController = TextEditingController(text: widget.item['nome'] ?? '');
final catId = widget.item['categoria'] as String?;
if (catId != null) {
_selectedCategory = ITEM_CATEGORIES.firstWhere(
_selectedCategory = itemCategories.firstWhere(
(c) => c.id == catId,
orElse: () => ITEM_CATEGORIES.last,
orElse: () => itemCategories.last,
);
}
final tags = List<String>.from(widget.item['tags'] ?? []);
@@ -653,7 +656,7 @@ class _EditItemScreenState extends State<EditItemScreen> {
child: DropdownButton<ItemCategory>(
value: _selectedCategory,
isExpanded: true,
items: ITEM_CATEGORIES
items: itemCategories
.map(
(c) => DropdownMenuItem(
value: c,
@@ -674,7 +677,7 @@ class _EditItemScreenState extends State<EditItemScreen> {
Wrap(
spacing: 8,
runSpacing: 8,
children: CONTEXT_TAGS.map((tag) {
children: contextTags.map((tag) {
final selected = _selectedTags.contains(tag.id);
return FilterChip(
label: Text(tag.name),
@@ -688,7 +691,7 @@ class _EditItemScreenState extends State<EditItemScreen> {
}
});
},
selectedColor: const Color(0xFF0066CC).withOpacity(0.2),
selectedColor: const Color(0xFF0066CC).withValues(alpha: 0.2),
checkmarkColor: const Color(0xFF0066CC),
backgroundColor: Colors.white,
);

View File

@@ -45,7 +45,7 @@ class _PerfilScreenState extends State<PerfilScreen> {
});
}
} catch (e) {
print('Error loading user data: $e');
debugPrint('Error loading user data: $e');
} finally {
setState(() => _isLoading = false);
}

View File

@@ -42,8 +42,11 @@ class _WeekScreenState extends State<WeekScreen> {
DateTime get _startOfWeek {
final now = DateTime.now();
return DateTime(now.year, now.month, now.day)
.subtract(Duration(days: now.weekday - 1));
return DateTime(
now.year,
now.month,
now.day,
).subtract(Duration(days: now.weekday - 1));
}
String _dateKey(DateTime d) =>
@@ -107,7 +110,7 @@ class _WeekScreenState extends State<WeekScreen> {
_isLoading = false;
});
} catch (e) {
print('Error loading day items: $e');
debugPrint('Error loading day items: $e');
setState(() => _isLoading = false);
}
}
@@ -123,8 +126,9 @@ class _WeekScreenState extends State<WeekScreen> {
final available = List<Map<String, dynamic>>.from(allItems);
final existingIds = _dayItems.map((i) => i['id']).toSet();
final toShow =
available.where((i) => !existingIds.contains(i['id'])).toList();
final toShow = available
.where((i) => !existingIds.contains(i['id']))
.toList();
if (!mounted) return;
final selected = await showModalBottomSheet<List<int>>(
@@ -193,10 +197,12 @@ class _WeekScreenState extends State<WeekScreen> {
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 8),
child: Row(
children: days.map((day) {
final isSelected = day.year == _selectedDay.year &&
final isSelected =
day.year == _selectedDay.year &&
day.month == _selectedDay.month &&
day.day == _selectedDay.day;
final isToday = day.year == DateTime.now().year &&
final isToday =
day.year == DateTime.now().year &&
day.month == DateTime.now().month &&
day.day == DateTime.now().day;
return Expanded(
@@ -280,39 +286,39 @@ class _WeekScreenState extends State<WeekScreen> {
child: _isLoading
? const Center(child: CircularProgressIndicator())
: _dayItems.isEmpty
? Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.calendar_today_outlined,
size: 56,
color: Colors.grey[400],
),
const SizedBox(height: 12),
const Text(
'Nenhum item para este dia',
style: TextStyle(
color: Color(0xFF666666),
fontSize: 16,
),
),
const SizedBox(height: 4),
const Text(
'Toque em + para adicionar',
style: TextStyle(
color: Color(0xFF999999),
fontSize: 13,
),
),
],
? Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.calendar_today_outlined,
size: 56,
color: Colors.grey[400],
),
)
: ListView.builder(
padding: const EdgeInsets.symmetric(horizontal: 16),
itemCount: _dayItems.length,
itemBuilder: (_, i) => _buildItemTile(_dayItems[i]),
),
const SizedBox(height: 12),
const Text(
'Nenhum item para este dia',
style: TextStyle(
color: Color(0xFF666666),
fontSize: 16,
),
),
const SizedBox(height: 4),
const Text(
'Toque em + para adicionar',
style: TextStyle(
color: Color(0xFF999999),
fontSize: 13,
),
),
],
),
)
: ListView.builder(
padding: const EdgeInsets.symmetric(horizontal: 16),
itemCount: _dayItems.length,
itemBuilder: (_, i) => _buildItemTile(_dayItems[i]),
),
),
],
),
@@ -326,11 +332,12 @@ class _WeekScreenState extends State<WeekScreen> {
Widget _buildItemTile(Map<String, dynamic> item) {
final images = item['item_images'] as List?;
final imageUrl =
(images != null && images.isNotEmpty) ? images.first['image_url'] : null;
final category = ITEM_CATEGORIES.firstWhere(
final imageUrl = (images != null && images.isNotEmpty)
? images.first['image_url']
: null;
final category = itemCategories.firstWhere(
(c) => c.id == item['categoria'],
orElse: () => ITEM_CATEGORIES.last,
orElse: () => itemCategories.last,
);
return Card(
@@ -346,7 +353,8 @@ class _WeekScreenState extends State<WeekScreen> {
width: 56,
height: 56,
fit: BoxFit.cover,
errorBuilder: (_, __, ___) => _icon(category.icon),
errorBuilder: (context, error, stackTrace) =>
_icon(category.icon),
)
: _icon(category.icon),
),
@@ -367,7 +375,7 @@ class _WeekScreenState extends State<WeekScreen> {
return Container(
width: 56,
height: 56,
color: const Color(0xFF0066CC).withOpacity(0.1),
color: const Color(0xFF0066CC).withValues(alpha: 0.1),
alignment: Alignment.center,
child: Text(icon, style: const TextStyle(fontSize: 26)),
);
@@ -393,10 +401,9 @@ class _ItemPickerSheetState extends State<_ItemPickerSheet> {
Widget build(BuildContext context) {
final filtered = widget.items
.where(
(i) => (i['nome'] ?? '')
.toString()
.toLowerCase()
.contains(_query.toLowerCase()),
(i) => (i['nome'] ?? '').toString().toLowerCase().contains(
_query.toLowerCase(),
),
)
.toList();
@@ -457,13 +464,12 @@ class _ItemPickerSheetState extends State<_ItemPickerSheet> {
final id = item['id'] as int;
final selected = _selected.contains(id);
final images = item['item_images'] as List?;
final imageUrl =
(images != null && images.isNotEmpty)
? images.first['image_url']
: null;
final category = ITEM_CATEGORIES.firstWhere(
final imageUrl = (images != null && images.isNotEmpty)
? images.first['image_url']
: null;
final category = itemCategories.firstWhere(
(c) => c.id == item['categoria'],
orElse: () => ITEM_CATEGORIES.last,
orElse: () => itemCategories.last,
);
return CheckboxListTile(
value: selected,
@@ -487,20 +493,24 @@ class _ItemPickerSheetState extends State<_ItemPickerSheet> {
width: 48,
height: 48,
fit: BoxFit.cover,
errorBuilder: (_, __, ___) => Container(
width: 48,
height: 48,
color: const Color(0xFF0066CC)
.withOpacity(0.1),
alignment: Alignment.center,
child: Text(category.icon),
),
errorBuilder:
(context, error, stackTrace) =>
Container(
width: 48,
height: 48,
color: const Color(
0xFF0066CC,
).withValues(alpha: 0.1),
alignment: Alignment.center,
child: Text(category.icon),
),
)
: Container(
width: 48,
height: 48,
color: const Color(0xFF0066CC)
.withOpacity(0.1),
color: const Color(
0xFF0066CC,
).withValues(alpha: 0.1),
alignment: Alignment.center,
child: Text(category.icon),
),
@@ -527,10 +537,7 @@ class _ItemPickerSheetState extends State<_ItemPickerSheet> {
),
child: Text(
'Adicionar (${_selected.length})',
style: const TextStyle(
color: Colors.white,
fontSize: 16,
),
style: const TextStyle(color: Colors.white, fontSize: 16),
),
),
),

View File

@@ -37,11 +37,11 @@ class ContextTag {
}
// Categorias principais
final List<ItemCategory> ITEM_CATEGORIES = [
final List<ItemCategory> itemCategories = [
ItemCategory(
id: 'clothing',
name: 'Roupa',
icon: '',
icon: '👕',
description: 'Peças de vestuário',
subcategories: [
Subcategory(
@@ -79,7 +79,7 @@ final List<ItemCategory> ITEM_CATEGORIES = [
ItemCategory(
id: 'electronics',
name: 'Eletrónica',
icon: '',
icon: '💻',
description: 'Dispositivos e acessórios tecnológicos',
subcategories: [
Subcategory(
@@ -117,7 +117,7 @@ final List<ItemCategory> ITEM_CATEGORIES = [
ItemCategory(
id: 'footwear',
name: 'Calçado',
icon: '',
icon: '👟',
description: 'Sapatos, botas, sandálias',
subcategories: [
Subcategory(
@@ -145,7 +145,7 @@ final List<ItemCategory> ITEM_CATEGORIES = [
ItemCategory(
id: 'accessories',
name: 'Acessórios',
icon: '',
icon: '🎒',
description: 'Bolsas, relógios, óculos, bijuteria',
subcategories: [
Subcategory(
@@ -175,7 +175,7 @@ final List<ItemCategory> ITEM_CATEGORIES = [
ItemCategory(
id: 'documents',
name: 'Documentos',
icon: '',
icon: '📄',
description: 'Passaporte, cartões, papéis importantes',
subcategories: [
Subcategory(
@@ -203,14 +203,14 @@ final List<ItemCategory> ITEM_CATEGORIES = [
ItemCategory(
id: 'other',
name: 'Outros',
icon: '',
icon: '📦',
description: 'Tudo o resto',
subcategories: [],
),
];
// Tags de contexto
final List<ContextTag> CONTEXT_TAGS = [
final List<ContextTag> contextTags = [
ContextTag(
id: 'travel',
name: 'Viagem',