Skip to content

Commit

Permalink
Added the sqflite tasks list of the user
Browse files Browse the repository at this point in the history
  • Loading branch information
ZainNaqvi committed Jul 30, 2022
1 parent 0afef3a commit 9e5143a
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 3 deletions.
7 changes: 6 additions & 1 deletion lib/controllers/add_task_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'package:get/get.dart';
class TaskController extends GetxController {
@override
void onReady() {

super.onReady();
}

Expand All @@ -21,4 +20,10 @@ class TaskController extends GetxController {
List<Map<String, dynamic?>>? tasks = await DBHelper.query();
taskList.assignAll(tasks!.map((e) => UserTask.fromJson(e)).toList());
}

// deleting the task using the specific id
Future<void> delete({required UserTask task}) async {
var id = await DBHelper.delete(task: task);
print(id);
}
}
5 changes: 5 additions & 0 deletions lib/db/db_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,9 @@ class DBHelper {
print("read function is called");
return await _db?.query(_tableName);
}
// delete Method
static Future<int?> delete({required UserTask task}) async {
print("delete function is called");
return await _db?.delete(_tableName, where: 'id=?', whereArgs: [task.id]);
}
}
44 changes: 42 additions & 2 deletions lib/ui/home_page.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import 'package:date_picker_timeline/date_picker_timeline.dart';
import 'package:example_todo_sqflite/controllers/add_task_controller.dart';
import 'package:example_todo_sqflite/services/theme_services.dart';
import 'package:example_todo_sqflite/themes.dart';
import 'package:example_todo_sqflite/ui/add_task_page.dart';
import 'package:example_todo_sqflite/ui/constants.dart';
import 'package:example_todo_sqflite/ui/widgets/button_dart.dart';
import 'package:example_todo_sqflite/ui/widgets/task_tile_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_staggered_animations/flutter_staggered_animations.dart';
import 'package:get/get.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:intl/intl.dart';
Expand All @@ -20,6 +23,7 @@ class HomePage extends StatefulWidget {
}

class _HomePageState extends State<HomePage> {
TaskController _taskController = Get.put(TaskController());
var selectedDate = DateTime.now();
late NotificationServices notifyHelper;
@override
Expand All @@ -44,13 +48,48 @@ class _HomePageState extends State<HomePage> {
_appTaskBar(),
// Date Picker TimeLines
_appDateBar(),
SizedBox(height: 16.h),
// list of the object user tasks
_showUserTasks(),
],
),
),
);
}

_showUserTasks() {
return Expanded(child: Obx(
() {
return ListView.builder(
shrinkWrap: true,
itemCount: _taskController.taskList.length,
itemBuilder: (context, index) {
print(
"list view builder has ${_taskController.taskList.length} items.");
return AnimationConfiguration.staggeredList(
position: index,
child: SlideAnimation(
child: FadeInAnimation(
child: Row(
children: [
GestureDetector(
onTap: () {
_showBottomSheet();
},
child: TaskTile(_taskController.taskList[index]),
),
],
),
),
),
);
},
);
},
));
}

_showBottomSheet() {}
Container _appDateBar() {
return Container(
margin: EdgeInsets.only(left: 20.w, top: 20.h),
Expand Down Expand Up @@ -114,8 +153,9 @@ class _HomePageState extends State<HomePage> {
// add-task-button
MyButton(
lable: "+ Add Task",
ontap: () {
Get.to(AddTaskBar());
ontap: () async {
await Get.to(AddTaskBar());
_taskController.getTask();
},
),
],
Expand Down
103 changes: 103 additions & 0 deletions lib/ui/widgets/task_tile_widget.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import 'package:example_todo_sqflite/models/task_model.dart';
import 'package:example_todo_sqflite/ui/constants.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';

class TaskTile extends StatelessWidget {
final UserTask? task;
TaskTile(this.task);

@override
Widget build(BuildContext context) {
return Container(
padding: EdgeInsets.symmetric(horizontal: 20),
width: MediaQuery.of(context).size.width,
margin: EdgeInsets.only(bottom: 12),
child: Container(
padding: EdgeInsets.all(16),
// width: SizeConfig.screenWidth * 0.78,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(16),
color: _getBGClr(task?.color ?? 0),
),
child: Row(children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
task?.title ?? "",
style: GoogleFonts.lato(
textStyle: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: Colors.white),
),
),
SizedBox(
height: 12,
),
Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Icon(
Icons.access_time_rounded,
color: Colors.grey[200],
size: 18,
),
SizedBox(width: 4),
Text(
"${task!.startTime} - ${task!.endTime}",
style: GoogleFonts.lato(
textStyle:
TextStyle(fontSize: 13, color: Colors.grey[100]),
),
),
],
),
SizedBox(height: 12),
Text(
task?.note ?? "",
style: GoogleFonts.lato(
textStyle: TextStyle(fontSize: 15, color: Colors.grey[100]),
),
),
],
),
),
Container(
margin: EdgeInsets.symmetric(horizontal: 10),
height: 60,
width: 0.5,
color: Colors.grey[200]!.withOpacity(0.7),
),
RotatedBox(
quarterTurns: 3,
child: Text(
task!.isCompleted == 1 ? "COMPLETED" : "TODO",
style: GoogleFonts.lato(
textStyle: TextStyle(
fontSize: 10,
fontWeight: FontWeight.bold,
color: Colors.white),
),
),
),
]),
),
);
}

_getBGClr(int no) {
switch (no) {
case 0:
return bluishClr;
case 1:
return pickClr;
case 2:
return yellowClr;
default:
return bluishClr;
}
}
}
7 changes: 7 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "5.5.3+2"
flutter_staggered_animations:
dependency: "direct main"
description:
name: flutter_staggered_animations
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
flutter_test:
dependency: "direct dev"
description: flutter
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ dependencies:
flutter_local_notifications: ^9.7.0
flutter_screenutil: ^5.5.3+2
date_picker_timeline: ^1.2.3
flutter_staggered_animations: ^1.0.0

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit 9e5143a

Please sign in to comment.