IA Funcinonal
This commit is contained in:
@@ -15,7 +15,15 @@ class _WeekScreenState extends State<WeekScreen> {
|
||||
List<Map<String, dynamic>> _dayItems = [];
|
||||
bool _isLoading = false;
|
||||
|
||||
static const _weekdayShort = ['Seg', 'Ter', 'Qua', 'Qui', 'Sex', 'Sáb', 'Dom'];
|
||||
static const _weekdayShort = [
|
||||
'Seg',
|
||||
'Ter',
|
||||
'Qua',
|
||||
'Qui',
|
||||
'Sex',
|
||||
'Sáb',
|
||||
'Dom',
|
||||
];
|
||||
static const _weekdayLong = [
|
||||
'Segunda',
|
||||
'Terça',
|
||||
@@ -34,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) =>
|
||||
@@ -108,8 +119,9 @@ class _WeekScreenState extends State<WeekScreen> {
|
||||
.eq('user_id', user.id);
|
||||
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>>(
|
||||
@@ -122,8 +134,9 @@ class _WeekScreenState extends State<WeekScreen> {
|
||||
|
||||
try {
|
||||
final planId = await _getOrCreatePlanId(_selectedDay);
|
||||
final rows =
|
||||
selected.map((id) => {'plan_id': planId, 'item_id': id}).toList();
|
||||
final rows = selected
|
||||
.map((id) => {'plan_id': planId, 'item_id': id})
|
||||
.toList();
|
||||
await Supabase.instance.client.from('plan_items').insert(rows);
|
||||
_loadDayItems();
|
||||
} catch (e) {
|
||||
@@ -163,15 +176,12 @@ class _WeekScreenState extends State<WeekScreen> {
|
||||
child: _isLoading
|
||||
? const Center(child: CircularProgressIndicator())
|
||||
: _dayItems.isEmpty
|
||||
? _buildEmpty()
|
||||
: ListView.builder(
|
||||
padding: const EdgeInsets.fromLTRB(
|
||||
20, 0, 20, 120,
|
||||
),
|
||||
itemCount: _dayItems.length,
|
||||
itemBuilder: (_, i) =>
|
||||
_buildItemTile(_dayItems[i]),
|
||||
),
|
||||
? _buildEmpty()
|
||||
: ListView.builder(
|
||||
padding: const EdgeInsets.fromLTRB(20, 0, 20, 120),
|
||||
itemCount: _dayItems.length,
|
||||
itemBuilder: (_, i) => _buildItemTile(_dayItems[i]),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -188,10 +198,7 @@ class _WeekScreenState extends State<WeekScreen> {
|
||||
children: [
|
||||
Text('Minha Semana', style: AppText.h2),
|
||||
SizedBox(height: 2),
|
||||
Text(
|
||||
'Planeie o que precisa para cada dia',
|
||||
style: AppText.caption,
|
||||
),
|
||||
Text('Planeie o que precisa para cada dia', style: AppText.caption),
|
||||
],
|
||||
),
|
||||
);
|
||||
@@ -202,11 +209,13 @@ class _WeekScreenState extends State<WeekScreen> {
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
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 today = DateTime.now();
|
||||
final isToday = day.year == today.year &&
|
||||
final isToday =
|
||||
day.year == today.year &&
|
||||
day.month == today.month &&
|
||||
day.day == today.day;
|
||||
return Expanded(
|
||||
@@ -322,10 +331,7 @@ class _WeekScreenState extends State<WeekScreen> {
|
||||
const SizedBox(height: 16),
|
||||
const Text('Nada planeado', style: AppText.h3),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'Toque em + para adicionar itens',
|
||||
style: AppText.caption,
|
||||
),
|
||||
Text('Toque em + para adicionar itens', style: AppText.caption),
|
||||
],
|
||||
),
|
||||
);
|
||||
@@ -369,7 +375,7 @@ class _WeekScreenState extends State<WeekScreen> {
|
||||
? Image.network(
|
||||
imageUrl,
|
||||
fit: BoxFit.cover,
|
||||
errorBuilder: (_, __, ___) =>
|
||||
errorBuilder: (_, _, _) =>
|
||||
Icon(cat.icon, color: cat.color, size: 24),
|
||||
)
|
||||
: Icon(cat.icon, color: cat.color, size: 24),
|
||||
@@ -476,10 +482,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();
|
||||
|
||||
@@ -541,8 +546,7 @@ class _ItemPickerSheetState extends State<_ItemPickerSheet> {
|
||||
controller: scrollController,
|
||||
padding: const EdgeInsets.fromLTRB(20, 4, 20, 12),
|
||||
itemCount: filtered.length,
|
||||
itemBuilder: (_, i) =>
|
||||
_buildPickerTile(filtered[i]),
|
||||
itemBuilder: (_, i) => _buildPickerTile(filtered[i]),
|
||||
),
|
||||
),
|
||||
SafeArea(
|
||||
@@ -556,8 +560,7 @@ class _ItemPickerSheetState extends State<_ItemPickerSheet> {
|
||||
icon: Icons.check_rounded,
|
||||
onPressed: _selected.isEmpty
|
||||
? null
|
||||
: () =>
|
||||
Navigator.pop(context, _selected.toList()),
|
||||
: () => Navigator.pop(context, _selected.toList()),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -612,7 +615,7 @@ class _ItemPickerSheetState extends State<_ItemPickerSheet> {
|
||||
? Image.network(
|
||||
imageUrl,
|
||||
fit: BoxFit.cover,
|
||||
errorBuilder: (_, __, ___) =>
|
||||
errorBuilder: (_, _, _) =>
|
||||
Icon(cat.icon, color: cat.color, size: 22),
|
||||
)
|
||||
: Icon(cat.icon, color: cat.color, size: 22),
|
||||
@@ -649,14 +652,10 @@ class _ItemPickerSheetState extends State<_ItemPickerSheet> {
|
||||
width: 24,
|
||||
height: 24,
|
||||
decoration: BoxDecoration(
|
||||
color: selected
|
||||
? AppColors.primary
|
||||
: Colors.transparent,
|
||||
color: selected ? AppColors.primary : Colors.transparent,
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(
|
||||
color: selected
|
||||
? AppColors.primary
|
||||
: AppColors.border,
|
||||
color: selected ? AppColors.primary : AppColors.border,
|
||||
width: 2,
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user