|
|
- 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: () {
- print("Tapped");
- },
- child: TaskTile(_taskController.taskList[index]),
- )
- ],
- )),
- ));
- });
- },
- ));
- }
- }
|