diff --git a/lib/controllers/task_controller.dart b/lib/controllers/task_controller.dart index 89debf2..0eaaa51 100644 --- a/lib/controllers/task_controller.dart +++ b/lib/controllers/task_controller.dart @@ -5,6 +5,7 @@ import 'package:sqflite_pust_local_notification/db/db_helper.dart'; import 'package:sqflite_pust_local_notification/models/task_model.dart'; class TaskController extends GetxController { + var taskList = [].obs; @override void onReady() { super.onReady(); @@ -13,4 +14,13 @@ class TaskController extends GetxController { Future addtask({TaskModel? task}) async { return await DBHelper.insert(task); } + + void getTask() async { + List> tasks = await DBHelper.query(); + taskList.assignAll(tasks.map((data) => TaskModel.fromJson(data)).toList()); + } + + void delete(TaskModel taskModel) { + DBHelper.delete(taskModel); + } } diff --git a/lib/db/db_helper.dart b/lib/db/db_helper.dart index 349a54c..7a417cd 100644 --- a/lib/db/db_helper.dart +++ b/lib/db/db_helper.dart @@ -36,4 +36,13 @@ class DBHelper { static Future insert(TaskModel? task) async { return await _db?.insert(_tableName, task!.toJson()) ?? 1; } + + static Future>> query() async { + return await _db!.query(_tableName); + } + + static delete(TaskModel taskModel) async { + return await _db! + .delete(_tableName, where: 'id?', whereArgs: [taskModel.id]); + } } diff --git a/lib/ui/add_task_screen.dart b/lib/ui/add_task_screen.dart index 52ebaf7..b6b1e05 100644 --- a/lib/ui/add_task_screen.dart +++ b/lib/ui/add_task_screen.dart @@ -205,6 +205,8 @@ class _AddTaskScreenState extends State { repeat: _selectedRepeat, color: _selectedColor, isCompleted: 0)); + + print("Task Added :" + value.toString()); } _colorPallete() { diff --git a/lib/ui/my_home_screen.dart b/lib/ui/my_home_screen.dart index 3d52e49..492d9b5 100644 --- a/lib/ui/my_home_screen.dart +++ b/lib/ui/my_home_screen.dart @@ -1,14 +1,18 @@ import 'package:date_picker_timeline/date_picker_timeline.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_staggered_animations/flutter_staggered_animations.dart'; import 'package:get/get.dart'; import 'package:intl/intl.dart'; +import 'package:sqflite_pust_local_notification/models/task_model.dart'; import 'package:sqflite_pust_local_notification/services/notification_service.dart'; import 'package:sqflite_pust_local_notification/services/theme_service.dart'; import 'package:sqflite_pust_local_notification/ui/add_task_screen.dart'; import 'package:sqflite_pust_local_notification/utils/assets_string.dart'; import 'package:sqflite_pust_local_notification/utils/colors.dart'; import 'package:sqflite_pust_local_notification/widgets/my_button.dart'; +import 'package:sqflite_pust_local_notification/widgets/task_tile.dart'; +import '../controllers/task_controller.dart'; import '../utils/textStyles.dart'; class MyHomeScreen extends StatefulWidget { @@ -19,6 +23,8 @@ class MyHomeScreen extends StatefulWidget { } class _MyHomeScreenState extends State { + final TaskController _taskController = Get.put(TaskController()); + var taskList = [].obs; DateTime _selectedDate = DateTime.now(); var notifyHelper; @override @@ -28,6 +34,7 @@ class _MyHomeScreenState extends State { notifyHelper = NotifyHelper(); notifyHelper.initializeNotification(); notifyHelper.requestIOSPermissions(); + //_getTask(); } @override @@ -35,10 +42,22 @@ class _MyHomeScreenState extends State { return Scaffold( appBar: _appBar(), backgroundColor: context.theme.backgroundColor, - body: Column(children: [_appTaskBar(), _addDateBar()]), + body: Column(children: [ + _appTaskBar(), + _addDateBar(), + SizedBox( + height: 20, + ), + _showTsks() + ]), ); } + // _getTask() async { + // var tasks = await _taskController.getTask(); + // taskList.assignAll(tasks.map((data) => TaskModel.fromJson(data)).toList()); + // } + _appBar() { return AppBar( elevation: 0, @@ -91,7 +110,13 @@ class _MyHomeScreenState extends State { ], ), ), - MyButton(label: "+ Add Task", onTap: () => Get.to(AddTaskScreen())) + MyButton( + label: "+ Add Task", + onTap: () async { + await Get.to(AddTaskScreen()); + _taskController.getTask(); + }, + ) ], ), ); @@ -116,4 +141,32 @@ class _MyHomeScreenState extends State { ), ); } + + _showTsks() { + return Expanded(child: Obx( + () { + return ListView.builder( + itemCount: _taskController.taskList.length, + itemBuilder: (_, index) { + print( + "Task Count :" + _taskController.taskList.length.toString()); + return AnimationConfiguration.staggeredList( + position: index, + child: SlideAnimation( + child: FadeInAnimation( + child: Row( + children: [ + GestureDetector( + onTap: () { + print("Tapped"); + }, + child: TaskTile(_taskController.taskList[index]), + ) + ], + )), + )); + }); + }, + )); + } } diff --git a/lib/utils/textStyles.dart b/lib/utils/textStyles.dart index 7c47614..cab7c7e 100644 --- a/lib/utils/textStyles.dart +++ b/lib/utils/textStyles.dart @@ -37,3 +37,27 @@ TextStyle get subTitleStyle { fontWeight: FontWeight.w600, color: Get.isDarkMode ? Colors.grey[100] : Colors.grey[400])); } + +TextStyle get taskTitle { + return GoogleFonts.lato( + textStyle: TextStyle( + fontSize: 16, fontWeight: FontWeight.bold, color: Colors.white)); +} + +TextStyle get taskTime { + return GoogleFonts.lato( + textStyle: TextStyle(fontSize: 13, color: Colors.grey[100]), + ); +} + +TextStyle get taskNote { + return GoogleFonts.lato( + textStyle: TextStyle(fontSize: 15, color: Colors.grey[100]), + ); +} + +TextStyle get taskIsComplete { + return GoogleFonts.lato( + textStyle: TextStyle( + fontSize: 10, fontWeight: FontWeight.bold, color: Colors.white)); +} diff --git a/lib/widgets/task_tile.dart b/lib/widgets/task_tile.dart new file mode 100644 index 0000000..4774917 --- /dev/null +++ b/lib/widgets/task_tile.dart @@ -0,0 +1,92 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/src/foundation/key.dart'; +import 'package:flutter/src/widgets/framework.dart'; +import 'package:google_fonts/google_fonts.dart'; +import 'package:sqflite_pust_local_notification/models/task_model.dart'; +import 'package:sqflite_pust_local_notification/utils/textStyles.dart'; + +import '../utils/colors.dart'; + +class TaskTile extends StatelessWidget { + final TaskModel? 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), + 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: taskTitle, + ), + 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: taskTime, + ) + ], + ), + SizedBox( + height: 12, + ), + Text( + task?.note ?? "", + style: taskNote, + ) + ], + ), + ), + 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: taskIsComplete, + ), + ) + ]), + ), + ); + } + + _getBGClr(int no) { + switch (no) { + case 0: + return bluishClr; + case 1: + return pinkClr; + case 2: + return yellowClr; + default: + return bluishClr; + } + } +} diff --git a/pubspec.lock b/pubspec.lock index c2ad5a3..022e5fa 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -139,6 +139,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.0.0" + 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 diff --git a/pubspec.yaml b/pubspec.yaml index 45caa1e..7304ca1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -42,6 +42,7 @@ dependencies: google_fonts: ^3.0.1 date_picker_timeline: ^1.2.3 sqflite: ^2.0.2+1 + flutter_staggered_animations: ^1.0.0 dev_dependencies: flutter_test: