This is flutter sqlite local notification project. User can add task.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

259 lines
7.6 KiB

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 {
const MyHomeScreen({Key? key}) : super(key: key);
@override
State<MyHomeScreen> createState() => _MyHomeScreenState();
}
class _MyHomeScreenState extends State<MyHomeScreen> {
final TaskController _taskController = Get.put(TaskController());
var taskList = <TaskModel>[].obs;
DateTime _selectedDate = DateTime.now();
var notifyHelper;
@override
void initState() {
// TODO: implement initState
super.initState();
notifyHelper = NotifyHelper();
notifyHelper.initializeNotification();
notifyHelper.requestIOSPermissions();
//_getTask();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: _appBar(),
backgroundColor: context.theme.backgroundColor,
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,
backgroundColor: context.theme.backgroundColor,
leading: GestureDetector(
onTap: () {
ThemeService().switchTheme();
notifyHelper.displayNotification(
title: "Theme Change",
body: Get.isDarkMode
? "Activated Light Mode"
: "Activated Dark Mode");
notifyHelper.scheduledNotification();
},
child: Icon(
Get.isDarkMode ? Icons.wb_sunny_outlined : Icons.nightlight_round,
size: 20,
color: Get.isDarkMode ? Colors.white : Colors.black),
),
actions: const [
CircleAvatar(
backgroundImage: AssetImage(profile),
),
SizedBox(
width: 20,
),
],
);
}
_appTaskBar() {
return Container(
margin: const EdgeInsets.only(left: 20, right: 20, top: 10),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
DateFormat.yMMMd().format(DateTime.now()),
style: headingStyle,
),
Text(
"Today",
style: subHeadingStyle,
)
],
),
),
MyButton(
label: "+ Add Task",
onTap: () async {
await Get.to(AddTaskScreen());
_taskController.getTask();
},
)
],
),
);
}
_addDateBar() {
return Container(
margin: const EdgeInsets.only(top: 20, left: 20),
child: DatePicker(
DateTime.now(),
height: 100,
width: 80,
initialSelectedDate: DateTime.now(),
selectionColor: primaryClr,
selectedTextColor: Colors.white,
dateTextStyle: datePickerTextStyle,
dayTextStyle: datePickerTextStyle,
monthTextStyle: datePickerTextStyle,
onDateChange: (Date) {
_selectedDate = Date;
},
),
);
}
_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: () {
_showBottomSheet(
context, _taskController.taskList[index]);
},
child: TaskTile(_taskController.taskList[index]),
)
],
)),
));
});
},
));
}
_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),
),
),
),
);
}
}