mirror of
https://github.com/nisrulz/flutter-examples.git
synced 2025-11-09 13:09:03 +00:00
taskplanning_app
This commit is contained in:
47
Plan_Tasks/Taskplanning_app/lib/Delete.dart
Normal file
47
Plan_Tasks/Taskplanning_app/lib/Delete.dart
Normal file
@@ -0,0 +1,47 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class Delete extends StatelessWidget {
|
||||
final String taskId;
|
||||
|
||||
const Delete({required this.taskId, Key? key}) : super(key: key);
|
||||
|
||||
void _deleteTask() {
|
||||
final CollectionReference tasks =
|
||||
FirebaseFirestore.instance.collection('todos');
|
||||
|
||||
tasks.doc(taskId).delete().then((value) {
|
||||
Get.back();
|
||||
Get.snackbar(
|
||||
'Success',
|
||||
'Task updated successfully',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
backgroundColor: Colors.green,
|
||||
colorText: Colors.white,
|
||||
);
|
||||
}).catchError((error) {
|
||||
print('Error deleting task in Firestore: $error');
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: Text('Delete Task'),
|
||||
content: Text('Are you sure you want to delete this task?'),
|
||||
actions: <Widget>[
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
Get.back();
|
||||
},
|
||||
child: Text('Cancel'),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: _deleteTask,
|
||||
child: Text('Delete'),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user