Browse Source

Added ListView in Home Screen

master
Sumit Mandal 2 years ago
parent
commit
44d64951d5
8 changed files with 200 additions and 2 deletions
  1. +10
    -0
      lib/controllers/task_controller.dart
  2. +9
    -0
      lib/db/db_helper.dart
  3. +2
    -0
      lib/ui/add_task_screen.dart
  4. +55
    -2
      lib/ui/my_home_screen.dart
  5. +24
    -0
      lib/utils/textStyles.dart
  6. +92
    -0
      lib/widgets/task_tile.dart
  7. +7
    -0
      pubspec.lock
  8. +1
    -0
      pubspec.yaml

+ 10
- 0
lib/controllers/task_controller.dart View File

@ -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 = <TaskModel>[].obs;
@override
void onReady() {
super.onReady();
@ -13,4 +14,13 @@ class TaskController extends GetxController {
Future<int> addtask({TaskModel? task}) async {
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);
}
}

+ 9
- 0
lib/db/db_helper.dart View File

@ -36,4 +36,13 @@ class DBHelper {
static Future<int> insert(TaskModel? task) async {
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]);
}
}

+ 2
- 0
lib/ui/add_task_screen.dart View File

@ -205,6 +205,8 @@ class _AddTaskScreenState extends State<AddTaskScreen> {
repeat: _selectedRepeat,
color: _selectedColor,
isCompleted: 0));
print("Task Added :" + value.toString());
}
_colorPallete() {


+ 55
- 2
lib/ui/my_home_screen.dart View File

@ -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<MyHomeScreen> {
final TaskController _taskController = Get.put(TaskController());
var taskList = <TaskModel>[].obs;
DateTime _selectedDate = DateTime.now();
var notifyHelper;
@override
@ -28,6 +34,7 @@ class _MyHomeScreenState extends State<MyHomeScreen> {
notifyHelper = NotifyHelper();
notifyHelper.initializeNotification();
notifyHelper.requestIOSPermissions();
//_getTask();
}
@override
@ -35,10 +42,22 @@ class _MyHomeScreenState extends State<MyHomeScreen> {
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<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]),
)
],
)),
));
});
},
));
}
}

+ 24
- 0
lib/utils/textStyles.dart View File

@ -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));
}

+ 92
- 0
lib/widgets/task_tile.dart View 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;
}
}
}

+ 7
- 0
pubspec.lock View File

@ -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


+ 1
- 0
pubspec.yaml View File

@ -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:


Loading…
Cancel
Save