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.

119 lines
3.4 KiB

2 years ago
  1. import 'package:date_picker_timeline/date_picker_timeline.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:get/get.dart';
  4. import 'package:intl/intl.dart';
  5. import 'package:sqflite_pust_local_notification/services/notification_service.dart';
  6. import 'package:sqflite_pust_local_notification/services/theme_service.dart';
  7. import 'package:sqflite_pust_local_notification/ui/add_task_screen.dart';
  8. import 'package:sqflite_pust_local_notification/utils/assets_string.dart';
  9. import 'package:sqflite_pust_local_notification/utils/colors.dart';
  10. import 'package:sqflite_pust_local_notification/widgets/my_button.dart';
  11. import '../utils/textStyles.dart';
  12. class MyHomeScreen extends StatefulWidget {
  13. const MyHomeScreen({Key? key}) : super(key: key);
  14. @override
  15. State<MyHomeScreen> createState() => _MyHomeScreenState();
  16. }
  17. class _MyHomeScreenState extends State<MyHomeScreen> {
  18. DateTime _selectedDate = DateTime.now();
  19. var notifyHelper;
  20. @override
  21. void initState() {
  22. // TODO: implement initState
  23. super.initState();
  24. notifyHelper = NotifyHelper();
  25. notifyHelper.initializeNotification();
  26. notifyHelper.requestIOSPermissions();
  27. }
  28. @override
  29. Widget build(BuildContext context) {
  30. return Scaffold(
  31. appBar: _appBar(),
  32. backgroundColor: context.theme.backgroundColor,
  33. body: Column(children: [_appTaskBar(), _addDateBar()]),
  34. );
  35. }
  36. _appBar() {
  37. return AppBar(
  38. elevation: 0,
  39. backgroundColor: context.theme.backgroundColor,
  40. leading: GestureDetector(
  41. onTap: () {
  42. ThemeService().switchTheme();
  43. notifyHelper.displayNotification(
  44. title: "Theme Change",
  45. body: Get.isDarkMode
  46. ? "Activated Light Mode"
  47. : "Activated Dark Mode");
  48. notifyHelper.scheduledNotification();
  49. },
  50. child: Icon(
  51. Get.isDarkMode ? Icons.wb_sunny_outlined : Icons.nightlight_round,
  52. size: 20,
  53. color: Get.isDarkMode ? Colors.white : Colors.black),
  54. ),
  55. actions: const [
  56. CircleAvatar(
  57. backgroundImage: AssetImage(profile),
  58. ),
  59. SizedBox(
  60. width: 20,
  61. ),
  62. ],
  63. );
  64. }
  65. _appTaskBar() {
  66. return Container(
  67. margin: const EdgeInsets.only(left: 20, right: 20, top: 10),
  68. child: Row(
  69. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  70. children: [
  71. Container(
  72. child: Column(
  73. crossAxisAlignment: CrossAxisAlignment.start,
  74. children: [
  75. Text(
  76. DateFormat.yMMMd().format(DateTime.now()),
  77. style: headingStyle,
  78. ),
  79. Text(
  80. "Today",
  81. style: subHeadingStyle,
  82. )
  83. ],
  84. ),
  85. ),
  86. MyButton(label: "+ Add Task", onTap: () => Get.to(AddTaskScreen()))
  87. ],
  88. ),
  89. );
  90. }
  91. _addDateBar() {
  92. return Container(
  93. margin: const EdgeInsets.only(top: 20, left: 20),
  94. child: DatePicker(
  95. DateTime.now(),
  96. height: 100,
  97. width: 80,
  98. initialSelectedDate: DateTime.now(),
  99. selectionColor: primaryClr,
  100. selectedTextColor: Colors.white,
  101. dateTextStyle: datePickerTextStyle,
  102. dayTextStyle: datePickerTextStyle,
  103. monthTextStyle: datePickerTextStyle,
  104. onDateChange: (Date) {
  105. _selectedDate = Date;
  106. },
  107. ),
  108. );
  109. }
  110. }