Update and Delete task
This commit is contained in:
parent
44d64951d5
commit
13fb26be6d
@ -22,5 +22,11 @@ class TaskController extends GetxController {
|
||||
|
||||
void delete(TaskModel taskModel) {
|
||||
DBHelper.delete(taskModel);
|
||||
getTask();
|
||||
}
|
||||
|
||||
void updateTaskIsComplete(int id) {
|
||||
DBHelper.update(id);
|
||||
getTask();
|
||||
}
|
||||
}
|
||||
|
@ -43,6 +43,14 @@ class DBHelper {
|
||||
|
||||
static delete(TaskModel taskModel) async {
|
||||
return await _db!
|
||||
.delete(_tableName, where: 'id?', whereArgs: [taskModel.id]);
|
||||
.delete(_tableName, where: 'id=?', whereArgs: [taskModel.id]);
|
||||
}
|
||||
|
||||
static update(int id) async {
|
||||
return await _db!.rawUpdate('''
|
||||
UPDATE tbtask
|
||||
SET isCompleted = ?
|
||||
WHERE id = ?
|
||||
''', [1, id]);
|
||||
}
|
||||
}
|
||||
|
@ -158,7 +158,8 @@ class _MyHomeScreenState extends State<MyHomeScreen> {
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
print("Tapped");
|
||||
_showBottomSheet(
|
||||
context, _taskController.taskList[index]);
|
||||
},
|
||||
child: TaskTile(_taskController.taskList[index]),
|
||||
)
|
||||
@ -169,4 +170,90 @@ class _MyHomeScreenState extends State<MyHomeScreen> {
|
||||
},
|
||||
));
|
||||
}
|
||||
|
||||
_showBottomSheet(BuildContext context, TaskModel taskModel) {
|
||||
Get.bottomSheet(Container(
|
||||
padding: const EdgeInsets.only(top: 4),
|
||||
height: taskModel.isCompleted == 1
|
||||
? MediaQuery.of(context).size.height * 0.24
|
||||
: MediaQuery.of(context).size.height * 0.32,
|
||||
color: Get.isDarkMode ? darkgratClr : Colors.white,
|
||||
child: Column(children: [
|
||||
Container(
|
||||
height: 6,
|
||||
width: 120,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
color: Get.isDarkMode ? Colors.grey[600] : Colors.grey[300]),
|
||||
),
|
||||
Spacer(),
|
||||
taskModel.isCompleted == 1
|
||||
? Container()
|
||||
: _bottomSheetButton(
|
||||
label: "Task Completed",
|
||||
onTap: () {
|
||||
_taskController.updateTaskIsComplete(taskModel.id!);
|
||||
Get.back();
|
||||
},
|
||||
clr: primaryClr,
|
||||
context: context),
|
||||
_bottomSheetButton(
|
||||
label: "Delete Task",
|
||||
onTap: () {
|
||||
_taskController.delete(taskModel);
|
||||
Get.back();
|
||||
},
|
||||
clr: Colors.red[600]!,
|
||||
context: context),
|
||||
SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
_bottomSheetButton(
|
||||
label: "Close",
|
||||
isClose: true,
|
||||
onTap: () {
|
||||
Get.back();
|
||||
},
|
||||
clr: Colors.white,
|
||||
context: context),
|
||||
SizedBox(
|
||||
height: 20,
|
||||
)
|
||||
]),
|
||||
));
|
||||
}
|
||||
|
||||
_bottomSheetButton(
|
||||
{required String label,
|
||||
required Function()? onTap,
|
||||
required Color clr,
|
||||
bool isClose = false,
|
||||
required BuildContext context}) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
margin: const EdgeInsets.symmetric(vertical: 4),
|
||||
height: 55,
|
||||
width: MediaQuery.of(context).size.width * 0.9,
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(
|
||||
width: 2,
|
||||
color: isClose == true
|
||||
? Get.isDarkMode
|
||||
? Colors.grey[600]!
|
||||
: Colors.grey[300]!
|
||||
: clr),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
color: isClose == true ? Colors.transparent : clr,
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
label,
|
||||
style:
|
||||
isClose ? titleStyle : titleStyle.copyWith(color: Colors.white),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user