532 lines
18 KiB
Dart
532 lines
18 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:supabase_flutter/supabase_flutter.dart';
|
|
import 'perfil_screen.dart';
|
|
import 'add_item_screen.dart';
|
|
import '../constants/item_categories.dart';
|
|
|
|
class HomeScreen extends StatefulWidget {
|
|
const HomeScreen({super.key});
|
|
|
|
@override
|
|
State<HomeScreen> createState() => _HomeScreenState();
|
|
}
|
|
|
|
class _HomeScreenState extends State<HomeScreen> {
|
|
int _selectedIndex = 0;
|
|
|
|
final List<Widget> _screens = [
|
|
const _HomeContent(),
|
|
const _ItemsScreen(),
|
|
const _WeekScreen(),
|
|
const _ProfileScreen(),
|
|
];
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: const Color(0xFFFFE5CC),
|
|
body: _screens[_selectedIndex],
|
|
bottomNavigationBar: BottomNavigationBar(
|
|
currentIndex: _selectedIndex,
|
|
onTap: (index) => setState(() => _selectedIndex = index),
|
|
selectedItemColor: const Color(0xFF0066CC),
|
|
unselectedItemColor: const Color(0xFF666666),
|
|
backgroundColor: Colors.white,
|
|
type: BottomNavigationBarType.fixed,
|
|
items: const [
|
|
BottomNavigationBarItem(icon: Icon(Icons.home), label: 'Início'),
|
|
BottomNavigationBarItem(
|
|
icon: Icon(Icons.inventory_2_outlined),
|
|
label: 'Itens',
|
|
),
|
|
BottomNavigationBarItem(
|
|
icon: Icon(Icons.calendar_today_outlined),
|
|
label: 'Semana',
|
|
),
|
|
BottomNavigationBarItem(
|
|
icon: Icon(Icons.person_outline),
|
|
label: 'Perfil',
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _HomeContent extends StatefulWidget {
|
|
const _HomeContent();
|
|
|
|
@override
|
|
State<_HomeContent> createState() => _HomeContentState();
|
|
}
|
|
|
|
class _HomeContentState extends State<_HomeContent> {
|
|
int _itemCount = 0;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_loadItemCount();
|
|
}
|
|
|
|
Future<void> _loadItemCount() async {
|
|
try {
|
|
final user = Supabase.instance.client.auth.currentUser;
|
|
if (user != null) {
|
|
final response = await Supabase.instance.client
|
|
.from('items')
|
|
.select('id')
|
|
.eq('user_id', user.id);
|
|
|
|
setState(() {
|
|
_itemCount = response.length;
|
|
});
|
|
}
|
|
} catch (e) {
|
|
print('Error loading item count: $e');
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return SafeArea(
|
|
child: Stack(
|
|
children: [
|
|
Column(
|
|
children: [
|
|
// App Bar
|
|
Container(
|
|
color: const Color(0xFF0066CC),
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal: 20,
|
|
vertical: 16,
|
|
),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
const Text(
|
|
'DayMaker',
|
|
style: TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 24,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
const SizedBox(height: 4),
|
|
Text(
|
|
'$_itemCount itens',
|
|
style: const TextStyle(
|
|
color: Colors.white70,
|
|
fontSize: 14,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
IconButton(
|
|
icon: const Icon(
|
|
Icons.notifications_outlined,
|
|
color: Colors.white,
|
|
),
|
|
onPressed: () {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
const SnackBar(
|
|
content: Text('Notificações'),
|
|
backgroundColor: Color(0xFF0066CC),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
],
|
|
),
|
|
),
|
|
|
|
Expanded(
|
|
child: SingleChildScrollView(
|
|
padding: const EdgeInsets.all(20),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
// Today Section
|
|
Container(
|
|
padding: const EdgeInsets.all(16),
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
const Text(
|
|
'Hoje - Sexta',
|
|
style: TextStyle(
|
|
fontSize: 18,
|
|
fontWeight: FontWeight.bold,
|
|
color: Color(0xFF0066CC),
|
|
),
|
|
),
|
|
const SizedBox(height: 8),
|
|
const Text(
|
|
'2 itens planejados',
|
|
style: TextStyle(
|
|
fontSize: 14,
|
|
color: Color(0xFF666666),
|
|
),
|
|
),
|
|
const SizedBox(height: 16),
|
|
// Placeholder for planned items
|
|
Container(
|
|
height: 80,
|
|
decoration: BoxDecoration(
|
|
color: const Color(0xFFF5F5F5),
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
child: const Center(
|
|
child: Text(
|
|
'Itens planejados aparecerão aqui',
|
|
style: TextStyle(color: Color(0xFF999999)),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
|
|
const SizedBox(height: 24),
|
|
|
|
// AI Recommendations Button
|
|
Container(
|
|
width: double.infinity,
|
|
padding: const EdgeInsets.all(20),
|
|
decoration: BoxDecoration(
|
|
color: const Color(0xFF0066CC),
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
const Text(
|
|
'Recomendações IA',
|
|
style: TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 20,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
const SizedBox(height: 4),
|
|
const Text(
|
|
'Descubra o que levar',
|
|
style: TextStyle(
|
|
color: Colors.white70,
|
|
fontSize: 14,
|
|
),
|
|
),
|
|
const SizedBox(height: 12),
|
|
Row(
|
|
children: [
|
|
const Icon(
|
|
Icons.auto_awesome,
|
|
color: Colors.white,
|
|
size: 20,
|
|
),
|
|
const SizedBox(width: 8),
|
|
Expanded(
|
|
child: Container(
|
|
height: 4,
|
|
decoration: BoxDecoration(
|
|
color: Colors.white30,
|
|
borderRadius: BorderRadius.circular(2),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
|
|
const SizedBox(height: 24),
|
|
|
|
// Recent Items Section
|
|
const Text(
|
|
'Itens Recentes',
|
|
style: TextStyle(
|
|
fontSize: 18,
|
|
fontWeight: FontWeight.bold,
|
|
color: Color(0xFF333333),
|
|
),
|
|
),
|
|
const SizedBox(height: 16),
|
|
|
|
// Placeholder for recent items
|
|
Container(
|
|
height: 100,
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
borderRadius: BorderRadius.circular(12),
|
|
border: Border.all(color: const Color(0xFFE0E0E0)),
|
|
),
|
|
child: const Center(
|
|
child: Text(
|
|
'Itens recentes aparecerão aqui',
|
|
style: TextStyle(color: Color(0xFF999999)),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
|
|
// Floating Action Button
|
|
Positioned(
|
|
bottom: 80,
|
|
right: 20,
|
|
child: FloatingActionButton(
|
|
onPressed: () {
|
|
Navigator.of(context).push(
|
|
MaterialPageRoute(builder: (_) => const AddItemScreen()),
|
|
);
|
|
},
|
|
backgroundColor: const Color(0xFF0066CC),
|
|
child: const Icon(Icons.add, color: Colors.white),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _ItemsScreen extends StatefulWidget {
|
|
const _ItemsScreen();
|
|
|
|
@override
|
|
State<_ItemsScreen> createState() => _ItemsScreenState();
|
|
}
|
|
|
|
class _ItemsScreenState extends State<_ItemsScreen> {
|
|
List<Map<String, dynamic>> _items = [];
|
|
bool _isLoading = true;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_loadItems();
|
|
}
|
|
|
|
Future<void> _loadItems() async {
|
|
try {
|
|
final user = Supabase.instance.client.auth.currentUser;
|
|
if (user != null) {
|
|
final response = await Supabase.instance.client
|
|
.from('items')
|
|
.select()
|
|
.eq('user_id', user.id)
|
|
.order('created_at', ascending: false);
|
|
|
|
setState(() {
|
|
_items = List<Map<String, dynamic>>.from(response);
|
|
_isLoading = false;
|
|
});
|
|
}
|
|
} catch (e) {
|
|
print('Error loading items: $e');
|
|
setState(() => _isLoading = false);
|
|
}
|
|
}
|
|
|
|
String _getCategoryName(String categoryId) {
|
|
final category = ITEM_CATEGORIES.firstWhere(
|
|
(cat) => cat.id == categoryId,
|
|
orElse: () => ITEM_CATEGORIES.last,
|
|
);
|
|
return category.name;
|
|
}
|
|
|
|
String _getCategoryIcon(String categoryId) {
|
|
final category = ITEM_CATEGORIES.firstWhere(
|
|
(cat) => cat.id == categoryId,
|
|
orElse: () => ITEM_CATEGORIES.last,
|
|
);
|
|
return category.icon;
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: const Color(0xFFFFE5CC),
|
|
appBar: AppBar(
|
|
backgroundColor: const Color(0xFF0066CC),
|
|
elevation: 0,
|
|
title: const Text(
|
|
'Meus Itens',
|
|
style: TextStyle(color: Colors.white, fontSize: 20),
|
|
),
|
|
centerTitle: true,
|
|
),
|
|
body: _isLoading
|
|
? const Center(child: CircularProgressIndicator())
|
|
: _items.isEmpty
|
|
? Center(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Icon(
|
|
Icons.inventory_2_outlined,
|
|
size: 64,
|
|
color: Colors.grey[400],
|
|
),
|
|
const SizedBox(height: 16),
|
|
const Text(
|
|
'Nenhum item ainda',
|
|
style: TextStyle(fontSize: 18, color: Color(0xFF666666)),
|
|
),
|
|
const SizedBox(height: 8),
|
|
const Text(
|
|
'Toque no + para adicionar',
|
|
style: TextStyle(fontSize: 14, color: Color(0xFF999999)),
|
|
),
|
|
],
|
|
),
|
|
)
|
|
: ListView.builder(
|
|
padding: const EdgeInsets.all(16),
|
|
itemCount: _items.length,
|
|
itemBuilder: (context, index) {
|
|
final item = _items[index];
|
|
final categoryName = _getCategoryName(item['category_id']);
|
|
final categoryIcon = _getCategoryIcon(item['category_id']);
|
|
final tags = List<String>.from(item['context_tags'] ?? []);
|
|
|
|
return Card(
|
|
margin: const EdgeInsets.only(bottom: 12),
|
|
elevation: 2,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(16),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Container(
|
|
width: 48,
|
|
height: 48,
|
|
decoration: BoxDecoration(
|
|
color: const Color(0xFF0066CC).withOpacity(0.1),
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
child: Center(
|
|
child: Text(
|
|
categoryIcon,
|
|
style: const TextStyle(fontSize: 24),
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(width: 12),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
item['name'] ?? 'Sem nome',
|
|
style: const TextStyle(
|
|
fontSize: 18,
|
|
fontWeight: FontWeight.bold,
|
|
color: Color(0xFF333333),
|
|
),
|
|
),
|
|
const SizedBox(height: 4),
|
|
Text(
|
|
categoryName,
|
|
style: const TextStyle(
|
|
fontSize: 14,
|
|
color: Color(0xFF666666),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
if (item['description'] != null &&
|
|
item['description'].toString().isNotEmpty) ...[
|
|
const SizedBox(height: 12),
|
|
Text(
|
|
item['description'],
|
|
style: const TextStyle(
|
|
fontSize: 14,
|
|
color: Color(0xFF666666),
|
|
),
|
|
),
|
|
],
|
|
if (tags.isNotEmpty) ...[
|
|
const SizedBox(height: 12),
|
|
Wrap(
|
|
spacing: 8,
|
|
runSpacing: 8,
|
|
children: tags.map((tag) {
|
|
final contextTag = CONTEXT_TAGS.firstWhere(
|
|
(t) => t.id == tag,
|
|
orElse: () => CONTEXT_TAGS.first,
|
|
);
|
|
return Chip(
|
|
label: Text(contextTag.name),
|
|
backgroundColor: const Color(
|
|
0xFF0066CC,
|
|
).withOpacity(0.1),
|
|
labelStyle: const TextStyle(
|
|
color: Color(0xFF0066CC),
|
|
fontSize: 12,
|
|
),
|
|
padding: EdgeInsets.zero,
|
|
materialTapTargetSize:
|
|
MaterialTapTargetSize.shrinkWrap,
|
|
);
|
|
}).toList(),
|
|
),
|
|
],
|
|
],
|
|
),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
floatingActionButton: FloatingActionButton(
|
|
onPressed: () {
|
|
Navigator.of(context)
|
|
.push(MaterialPageRoute(builder: (_) => const AddItemScreen()))
|
|
.then((_) => _loadItems());
|
|
},
|
|
backgroundColor: const Color(0xFF0066CC),
|
|
child: const Icon(Icons.add, color: Colors.white),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _WeekScreen extends StatelessWidget {
|
|
const _WeekScreen();
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return const Center(child: Text('Semana'));
|
|
}
|
|
}
|
|
|
|
class _ProfileScreen extends StatelessWidget {
|
|
const _ProfileScreen();
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return const PerfilScreen();
|
|
}
|
|
}
|