Added ListView in Home Screen
This commit is contained in:
parent
68f6022e93
commit
44d64951d5
@ -5,6 +5,7 @@ import 'package:sqflite_pust_local_notification/db/db_helper.dart';
|
|||||||
import 'package:sqflite_pust_local_notification/models/task_model.dart';
|
import 'package:sqflite_pust_local_notification/models/task_model.dart';
|
||||||
|
|
||||||
class TaskController extends GetxController {
|
class TaskController extends GetxController {
|
||||||
|
var taskList = <TaskModel>[].obs;
|
||||||
@override
|
@override
|
||||||
void onReady() {
|
void onReady() {
|
||||||
super.onReady();
|
super.onReady();
|
||||||
@ -13,4 +14,13 @@ class TaskController extends GetxController {
|
|||||||
Future<int> addtask({TaskModel? task}) async {
|
Future<int> addtask({TaskModel? task}) async {
|
||||||
return await DBHelper.insert(task);
|
return await DBHelper.insert(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void getTask() async {
|
||||||
|
List<Map<String, dynamic>> tasks = await DBHelper.query();
|
||||||
|
taskList.assignAll(tasks.map((data) => TaskModel.fromJson(data)).toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
void delete(TaskModel taskModel) {
|
||||||
|
DBHelper.delete(taskModel);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,4 +36,13 @@ class DBHelper {
|
|||||||
static Future<int> insert(TaskModel? task) async {
|
static Future<int> insert(TaskModel? task) async {
|
||||||
return await _db?.insert(_tableName, task!.toJson()) ?? 1;
|
return await _db?.insert(_tableName, task!.toJson()) ?? 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Future<List<Map<String, dynamic>>> query() async {
|
||||||
|
return await _db!.query(_tableName);
|
||||||
|
}
|
||||||
|
|
||||||
|
static delete(TaskModel taskModel) async {
|
||||||
|
return await _db!
|
||||||
|
.delete(_tableName, where: 'id?', whereArgs: [taskModel.id]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -205,6 +205,8 @@ class _AddTaskScreenState extends State<AddTaskScreen> {
|
|||||||
repeat: _selectedRepeat,
|
repeat: _selectedRepeat,
|
||||||
color: _selectedColor,
|
color: _selectedColor,
|
||||||
isCompleted: 0));
|
isCompleted: 0));
|
||||||
|
|
||||||
|
print("Task Added :" + value.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
_colorPallete() {
|
_colorPallete() {
|
||||||
|
@ -1,14 +1,18 @@
|
|||||||
import 'package:date_picker_timeline/date_picker_timeline.dart';
|
import 'package:date_picker_timeline/date_picker_timeline.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_staggered_animations/flutter_staggered_animations.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:intl/intl.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/notification_service.dart';
|
||||||
import 'package:sqflite_pust_local_notification/services/theme_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/ui/add_task_screen.dart';
|
||||||
import 'package:sqflite_pust_local_notification/utils/assets_string.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/utils/colors.dart';
|
||||||
import 'package:sqflite_pust_local_notification/widgets/my_button.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';
|
import '../utils/textStyles.dart';
|
||||||
|
|
||||||
class MyHomeScreen extends StatefulWidget {
|
class MyHomeScreen extends StatefulWidget {
|
||||||
@ -19,6 +23,8 @@ class MyHomeScreen extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _MyHomeScreenState extends State<MyHomeScreen> {
|
class _MyHomeScreenState extends State<MyHomeScreen> {
|
||||||
|
final TaskController _taskController = Get.put(TaskController());
|
||||||
|
var taskList = <TaskModel>[].obs;
|
||||||
DateTime _selectedDate = DateTime.now();
|
DateTime _selectedDate = DateTime.now();
|
||||||
var notifyHelper;
|
var notifyHelper;
|
||||||
@override
|
@override
|
||||||
@ -28,6 +34,7 @@ class _MyHomeScreenState extends State<MyHomeScreen> {
|
|||||||
notifyHelper = NotifyHelper();
|
notifyHelper = NotifyHelper();
|
||||||
notifyHelper.initializeNotification();
|
notifyHelper.initializeNotification();
|
||||||
notifyHelper.requestIOSPermissions();
|
notifyHelper.requestIOSPermissions();
|
||||||
|
//_getTask();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -35,10 +42,22 @@ class _MyHomeScreenState extends State<MyHomeScreen> {
|
|||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: _appBar(),
|
appBar: _appBar(),
|
||||||
backgroundColor: context.theme.backgroundColor,
|
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() {
|
_appBar() {
|
||||||
return AppBar(
|
return AppBar(
|
||||||
elevation: 0,
|
elevation: 0,
|
||||||
@ -91,7 +110,13 @@ class _MyHomeScreenState extends State<MyHomeScreen> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
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<MyHomeScreen> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_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]),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
)),
|
||||||
|
));
|
||||||
|
});
|
||||||
|
},
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,3 +37,27 @@ TextStyle get subTitleStyle {
|
|||||||
fontWeight: FontWeight.w600,
|
fontWeight: FontWeight.w600,
|
||||||
color: Get.isDarkMode ? Colors.grey[100] : Colors.grey[400]));
|
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));
|
||||||
|
}
|
||||||
|
92
lib/widgets/task_tile.dart
Normal file
92
lib/widgets/task_tile.dart
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -139,6 +139,13 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.0.0"
|
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:
|
flutter_test:
|
||||||
dependency: "direct dev"
|
dependency: "direct dev"
|
||||||
description: flutter
|
description: flutter
|
||||||
|
@ -42,6 +42,7 @@ dependencies:
|
|||||||
google_fonts: ^3.0.1
|
google_fonts: ^3.0.1
|
||||||
date_picker_timeline: ^1.2.3
|
date_picker_timeline: ^1.2.3
|
||||||
sqflite: ^2.0.2+1
|
sqflite: ^2.0.2+1
|
||||||
|
flutter_staggered_animations: ^1.0.0
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user