IA Funcinonal

This commit is contained in:
Carlos Correia
2026-05-21 11:53:35 +01:00
parent 9999011cfd
commit 967584f083
10 changed files with 482 additions and 382 deletions

View File

@@ -21,12 +21,15 @@ class _ItemScreenState extends State<ItemScreen> {
List<Map<String, dynamic>> get _filteredItems {
return _items.where((item) {
final name = (item['nome'] ?? '').toString().toLowerCase();
final tags =
List<String>.from(item['tags'] ?? []).join(' ').toLowerCase();
final matchesSearch = _searchQuery.isEmpty ||
final tags = List<String>.from(
item['tags'] ?? [],
).join(' ').toLowerCase();
final matchesSearch =
_searchQuery.isEmpty ||
name.contains(_searchQuery.toLowerCase()) ||
tags.contains(_searchQuery.toLowerCase());
final matchesCategory = _selectedCategoryFilter == null ||
final matchesCategory =
_selectedCategoryFilter == null ||
item['categoria'] == _selectedCategoryFilter;
return matchesSearch && matchesCategory;
}).toList();
@@ -110,8 +113,7 @@ class _ItemScreenState extends State<ItemScreen> {
Navigator.push(
context,
MaterialPageRoute(
builder: (_) =>
ItemDetailScreen(item: item, imageUrl: _imageUrl(item)),
builder: (_) => ItemDetailScreen(item: item, imageUrl: _imageUrl(item)),
),
).then((_) => _loadItems());
}
@@ -140,16 +142,14 @@ class _ItemScreenState extends State<ItemScreen> {
child: _isLoading
? const Center(child: CircularProgressIndicator())
: _items.isEmpty
? _buildEmpty()
: _filteredItems.isEmpty
? _buildNoResults()
: RefreshIndicator(
onRefresh: _loadItems,
color: AppColors.primary,
child: _gridView
? _buildGrid()
: _buildList(),
),
? _buildEmpty()
: _filteredItems.isEmpty
? _buildNoResults()
: RefreshIndicator(
onRefresh: _loadItems,
color: AppColors.primary,
child: _gridView ? _buildGrid() : _buildList(),
),
),
],
),
@@ -211,8 +211,7 @@ class _ItemScreenState extends State<ItemScreen> {
child: Icon(
icon,
size: 18,
color:
selected ? AppColors.primary : AppColors.textSecondary,
color: selected ? AppColors.primary : AppColors.textSecondary,
),
),
),
@@ -266,8 +265,7 @@ class _ItemScreenState extends State<ItemScreen> {
icon: c.icon,
color: c.color,
selected: _selectedCategoryFilter == c.id,
onTap: () =>
setState(() => _selectedCategoryFilter = c.id),
onTap: () => setState(() => _selectedCategoryFilter = c.id),
),
),
),
@@ -327,7 +325,7 @@ class _ItemScreenState extends State<ItemScreen> {
crossAxisCount: 2,
mainAxisSpacing: 12,
crossAxisSpacing: 12,
childAspectRatio: 0.78,
childAspectRatio: 0.50,
),
itemCount: _filteredItems.length,
itemBuilder: (_, i) => _buildGridCard(_filteredItems[i]),
@@ -368,18 +366,13 @@ class _ItemScreenState extends State<ItemScreen> {
Image.network(
imageUrl,
fit: BoxFit.cover,
errorBuilder: (_, __, ___) =>
Center(child: Icon(cat.icon, color: cat.color, size: 40)),
errorBuilder: (_, __, ___) => Center(
child: Icon(cat.icon, color: cat.color, size: 40),
),
)
else
Center(
child: Icon(cat.icon, color: cat.color, size: 40),
),
Positioned(
top: 8,
right: 8,
child: _moreButton(item),
),
Center(child: Icon(cat.icon, color: cat.color, size: 40)),
Positioned(top: 8, right: 8, child: _moreButton(item)),
],
),
),
@@ -463,11 +456,8 @@ class _ItemScreenState extends State<ItemScreen> {
? Image.network(
imageUrl,
fit: BoxFit.cover,
errorBuilder: (_, __, ___) => Icon(
cat.icon,
color: cat.color,
size: 28,
),
errorBuilder: (_, __, ___) =>
Icon(cat.icon, color: cat.color, size: 28),
)
: Icon(cat.icon, color: cat.color, size: 28),
),
@@ -525,7 +515,7 @@ class _ItemScreenState extends State<ItemScreen> {
Widget _moreButton(Map<String, dynamic> item) {
return Material(
color: Colors.white.withValues(alpha: 0.85),
color: Colors.white.withValues(alpha: 0.75),
shape: const CircleBorder(),
child: InkWell(
customBorder: const CircleBorder(),
@@ -575,15 +565,10 @@ class _ItemScreenState extends State<ItemScreen> {
_openItem(item);
},
),
_actionTile(
Icons.edit_outlined,
'Editar',
AppColors.primary,
() {
Navigator.pop(ctx);
_editItem(item);
},
),
_actionTile(Icons.edit_outlined, 'Editar', AppColors.primary, () {
Navigator.pop(ctx);
_editItem(item);
}),
_actionTile(
Icons.delete_outline_rounded,
'Apagar',
@@ -619,10 +604,7 @@ class _ItemScreenState extends State<ItemScreen> {
),
title: Text(
label,
style: TextStyle(
color: color,
fontWeight: FontWeight.w600,
),
style: TextStyle(color: color, fontWeight: FontWeight.w600),
),
onTap: onTap,
);
@@ -714,13 +696,12 @@ class ItemDetailScreen extends StatelessWidget {
Image.network(
imageUrl!,
fit: BoxFit.cover,
errorBuilder: (_, __, ___) =>
Center(child: Icon(cat.icon, color: cat.color, size: 80)),
errorBuilder: (_, __, ___) => Center(
child: Icon(cat.icon, color: cat.color, size: 80),
),
)
else
Center(
child: Icon(cat.icon, color: cat.color, size: 80),
),
Center(child: Icon(cat.icon, color: cat.color, size: 80)),
Container(
decoration: BoxDecoration(
gradient: LinearGradient(
@@ -786,8 +767,9 @@ class ItemDetailScreen extends StatelessWidget {
),
decoration: BoxDecoration(
color: AppColors.surface,
borderRadius:
BorderRadius.circular(AppRadius.pill),
borderRadius: BorderRadius.circular(
AppRadius.pill,
),
border: Border.all(color: AppColors.border),
),
child: Text(
@@ -853,11 +835,14 @@ class _EditItemScreenState extends State<EditItemScreen> {
}
setState(() => _isLoading = true);
try {
await Supabase.instance.client.from('items').update({
'nome': _nameController.text.trim(),
'categoria': _selectedCategory?.id,
'tags': _selectedTags.toList(),
}).eq('id', widget.item['id']);
await Supabase.instance.client
.from('items')
.update({
'nome': _nameController.text.trim(),
'categoria': _selectedCategory?.id,
'tags': _selectedTags.toList(),
})
.eq('id', widget.item['id']);
if (mounted) {
AppSnack.success(context, 'Item atualizado!');
Navigator.pop(context);