diff --git a/lib/api/api_service.dart b/lib/api/api_service.dart index b3263ad..28fd4ff 100644 --- a/lib/api/api_service.dart +++ b/lib/api/api_service.dart @@ -102,12 +102,11 @@ class ApiService { } Future deleteHabit(String habitId) async { - final body = jsonEncode({'id': habitId}); - final response = await http.delete(_habitsUrl, - headers: { - 'Content-Type': 'application/json; charset=UTF-8', - }, - body: body); + final String deleteUrl = '$_habitsUrl/$habitId'; + + final response = await http.delete(Uri.parse(deleteUrl), headers: { + 'Content-Type': 'application/json; charset=UTF-8', + }); if (response.statusCode != 200) { throw Exception('Erro na requisição: ${response.body}'); } diff --git a/lib/registered_habits.dart b/lib/registered_habits.dart index 0490736..eeb18f1 100644 --- a/lib/registered_habits.dart +++ b/lib/registered_habits.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:habit_tracker_frontend/api/api_service.dart'; +import 'package:intl/intl.dart'; class RegisteredHabits extends ChangeNotifier { List memoryHabits = []; @@ -11,9 +12,15 @@ class RegisteredHabits extends ChangeNotifier { try { memoryHabits = await apiService.getAllHabits(); memoryCompletedHabits = await apiService.getCompletedHabits(); + final today = DateTime.now(); + final brDateFormat = DateFormat('dd/MM/yyyy'); + final formatedDateToday = brDateFormat.format(today); + for (var habit in memoryHabits) { - habit.completed = memoryCompletedHabits - .any((completedHabit) => completedHabit.habitId == habit.id); + habit.completed = memoryCompletedHabits.any((completedHabit) => + completedHabit.habitId == habit.id && + brDateFormat.format(completedHabit.completedDate) == + formatedDateToday); } notifyListeners(); return memoryHabits;