1
0
mirror of https://github.com/Uttkarsh-raj/Plannerly.git synced 2024-11-24 08:02:18 +02:00

added delete feature

This commit is contained in:
Uttkarsh-raj 2023-11-02 22:23:37 +05:30
parent acf7a41b62
commit 7fa3485a3a
4 changed files with 21 additions and 4 deletions

View File

@ -123,8 +123,22 @@ class HomeBloc extends Bloc<HomeEvent, HomeState> {
}
FutureOr<void> homeTasksDeleteButtonClicked(
HomeTasksDeleteButtonClicked event, Emitter<HomeState> emit) {
print("Task deleted button clicked");
emit(HomeTaskDeletedState());
HomeTasksDeleteButtonClicked event, Emitter<HomeState> emit) async {
emit(HomeLoadingState());
var uri = Uri.parse("$baseUrl/delete/${event.taskDeleted.taskId}");
try {
var res = await http.delete(
uri,
headers: {"token": token},
);
var response = jsonDecode(res.body);
if (response["success"]) {
emit(HomeTaskDeletedState());
} else {
emit(HomeUnableTofetchTasks(message: response["error"]));
}
} catch (e) {
emit(HomeUnableTofetchTasks(message: e.toString()));
}
}
}

View File

@ -11,6 +11,8 @@ final class HomeInitial extends HomeState {}
class HomeLoadingState extends HomeState {}
class HomeRefreshState extends HomeState {}
class HomeLoadedSuccessState extends HomeState {
final List<TaskModel> regularTasks;
final List<TaskModel> urgentTasks;

View File

@ -92,6 +92,7 @@ class _TaskState extends State<Task> {
taskDeleted: widget.task,
),
);
widget.bloc.add(HomeInitialEvent());
},
icon: Icon(
Icons.delete_outline,

View File

@ -1,4 +1,4 @@
//just for testing
var baseUrl = "http://192.168.235.52:8000";
var token =
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJFbWFpbCI6ImpvaG4uZG9lQGdtYWlsLmNvbSIsIkZpcnN0X25hbWUiOiJKb2huIiwiTGFzdF9uYW1lIjoiRG9lIiwiVWlkIjoiNjUzYTJmNzFlMjMzMGFjMzY5ZTkzYzliIiwiZXhwIjoxNjk4OTM2NjgwfQ.vw266guS32CL3kfGLcNMPkdCwS6CS7Zz2vLbUXTrRL4";
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJFbWFpbCI6ImpvaG4uZG9lQGdtYWlsLmNvbSIsIkZpcnN0X25hbWUiOiJKb2huIiwiTGFzdF9uYW1lIjoiRG9lIiwiVWlkIjoiNjUzYTJmNzFlMjMzMGFjMzY5ZTkzYzliIiwiZXhwIjoxNjk5MDI4NDM4fQ.1doJ9tOyRHosZAYM3dD1rxGhbxPg3laHVzYvGeGHKGQ";