From 2562aa8dea3154b57834fc60a406aa53caf414a1 Mon Sep 17 00:00:00 2001 From: Apalak Dutta Date: Thu, 30 Jun 2022 21:52:00 +0530 Subject: [PATCH] Notifiend task screen added --- android/app/src/main/AndroidManifest.xml | 2 +- ios/Runner/Info.plist | 2 +- lib/services/notification_service.dart | 36 +++++++++++++--- lib/ui/add_task_screen.dart | 13 ++++++ lib/ui/my_home_screen.dart | 40 ++++++++++++------ lib/ui/notified_screen.dart | 53 ++++++++++++++++++++++++ lib/utils/colors.dart | 4 +- lib/utils/textStyles.dart | 16 +++++++ 8 files changed, 144 insertions(+), 22 deletions(-) create mode 100644 lib/ui/notified_screen.dart diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 94930ba..e0bd7b1 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -8,7 +8,7 @@ CFBundleInfoDictionaryVersion 6.0 CFBundleName - sqflite_pust_local_notification + My Task CFBundlePackageType APPL CFBundleShortVersionString diff --git a/lib/services/notification_service.dart b/lib/services/notification_service.dart index 5954c0a..49ceffd 100644 --- a/lib/services/notification_service.dart +++ b/lib/services/notification_service.dart @@ -3,9 +3,12 @@ import 'package:flutter_local_notifications/flutter_local_notifications.dart'; import 'package:flutter_native_timezone/flutter_native_timezone.dart'; import 'package:get/get.dart'; import 'package:sqflite_pust_local_notification/models/task_model.dart'; +import 'package:sqflite_pust_local_notification/ui/notified_screen.dart'; import 'package:timezone/data/latest.dart' as tz; import 'package:timezone/timezone.dart' as tz; +import '../utils/assets_string.dart'; + class NotifyHelper { FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin(); // @@ -43,6 +46,27 @@ class NotifyHelper { ); } + // displayNotification( + // {required int id, required String title, required String body}) async { + // print("doing test"); + // var androidPlatformChannelSpecifics = new AndroidNotificationDetails( + // 'your channel id', + // 'your channel name', + // channelDescription: '', + // importance: Importance.max, + // priority: Priority.high, + // ); + + // var iOSPlatformChannelSpecifics = new IOSNotificationDetails(); + // var platformChannelSpecifics = new NotificationDetails( + // android: androidPlatformChannelSpecifics, + // iOS: iOSPlatformChannelSpecifics); + + // await flutterLocalNotificationsPlugin.show( + // id, title, body, platformChannelSpecifics, + // payload: "${title}|" + "${body}|"); + // } + displayNotification({required String title, required String body}) async { print("doing test"); var androidPlatformChannelSpecifics = new AndroidNotificationDetails( @@ -61,7 +85,7 @@ class NotifyHelper { title, body, platformChannelSpecifics, - payload: 'Default_Sound', + payload: title, ); } @@ -80,7 +104,8 @@ class NotifyHelper { androidAllowWhileIdle: true, uiLocalNotificationDateInterpretation: UILocalNotificationDateInterpretation.absoluteTime, - matchDateTimeComponents: DateTimeComponents.time); + matchDateTimeComponents: DateTimeComponents.time, + payload: "${taskModel.title}|" + "${taskModel.note}|"); } tz.TZDateTime _convertTimeDeration(int hours, int minutes) { @@ -113,8 +138,9 @@ class NotifyHelper { } else { print("Notification Done"); } - Get.to(() => Container( - color: Colors.white, - )); + if (payload == "Theme Change" || payload == "Add Task") { + } else { + Get.to(() => NotifiedScreen(lable: payload)); + } } } diff --git a/lib/ui/add_task_screen.dart b/lib/ui/add_task_screen.dart index b6b1e05..6e9d509 100644 --- a/lib/ui/add_task_screen.dart +++ b/lib/ui/add_task_screen.dart @@ -6,6 +6,7 @@ import 'package:sqflite_pust_local_notification/models/task_model.dart'; import 'package:sqflite_pust_local_notification/utils/colors.dart'; import 'package:sqflite_pust_local_notification/utils/textStyles.dart'; import 'package:sqflite_pust_local_notification/widgets/my_button.dart'; +import '../services/notification_service.dart'; import '../utils/assets_string.dart'; import '../widgets/my_input_field.dart'; @@ -40,6 +41,16 @@ class _AddTaskScreenState extends State { ]; int _selectedColor = 0; + var notifyHelper; + + @override + void initState() { + // TODO: implement initState + super.initState(); + notifyHelper = NotifyHelper(); + notifyHelper.initializeNotification(); + notifyHelper.requestIOSPermissions(); + } @override Widget build(BuildContext context) { @@ -177,6 +188,8 @@ class _AddTaskScreenState extends State { _validateDate() { if (_titleController.text.isNotEmpty && _noteController.text.isNotEmpty) { _addTaskToDb(); + notifyHelper.displayNotification( + title: "Add Task", body: "A new task is added"); Get.back(); } else if (_titleController.text.isEmpty || _noteController.text.isEmpty) { Get.snackbar( diff --git a/lib/ui/my_home_screen.dart b/lib/ui/my_home_screen.dart index 9dfc2a3..4edb50b 100644 --- a/lib/ui/my_home_screen.dart +++ b/lib/ui/my_home_screen.dart @@ -26,6 +26,7 @@ class _MyHomeScreenState extends State { final TaskController _taskController = Get.put(TaskController()); var taskList = [].obs; DateTime _selectedDate = DateTime.now(); + DateTime _today = DateTime.now(); var notifyHelper; @override void initState() { @@ -34,6 +35,7 @@ class _MyHomeScreenState extends State { notifyHelper = NotifyHelper(); notifyHelper.initializeNotification(); notifyHelper.requestIOSPermissions(); + _taskController.getTask(); //_getTask(); } @@ -159,10 +161,21 @@ class _MyHomeScreenState extends State { int.parse(myTime.toString().split(":")[0]), int.parse(myTime.toString().split(":")[1]), taskModel); - return _setTAskView(index, taskModel); + return _setTaskView(index, taskModel); } + // else if (taskModel.repeat == "None" && + // taskModel.date == DateFormat.yMd().format(_today)) { + // print("Show task notification " + + // isShowTaskNotification.toString()); + // if (isShowTaskNotification) { + // notifyHelper.displayNotification( + // id: taskModel.id, + // title: taskModel.title, + // body: taskModel.note); + // } + // } if (taskModel.date == DateFormat.yMd().format(_selectedDate)) { - return _setTAskView(index, taskModel); + return _setTaskView(index, taskModel); } else { return Container(); } @@ -171,21 +184,22 @@ class _MyHomeScreenState extends State { )); } - _setTAskView(int index, TaskModel taskModel) { + _setTaskView(int index, TaskModel taskModel) { return AnimationConfiguration.staggeredList( position: index, child: SlideAnimation( - child: FadeInAnimation( + child: FlipAnimation( + delay: Duration(milliseconds: 200), child: Row( - children: [ - GestureDetector( - onTap: () { - _showBottomSheet(context, taskModel); - }, - child: TaskTile(taskModel), - ) - ], - )), + children: [ + GestureDetector( + onTap: () { + _showBottomSheet(context, taskModel); + }, + child: TaskTile(taskModel), + ) + ], + )), )); } diff --git a/lib/ui/notified_screen.dart b/lib/ui/notified_screen.dart new file mode 100644 index 0000000..b34aea2 --- /dev/null +++ b/lib/ui/notified_screen.dart @@ -0,0 +1,53 @@ +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:get/get.dart'; + +import '../utils/textStyles.dart'; + +class NotifiedScreen extends StatelessWidget { + final String? lable; + const NotifiedScreen({Key? key, required this.lable}) : super(key: key); + + @override + Widget build(BuildContext context) { + var title = lable.toString().split("|")[0]; + var note = lable.toString().split("|")[1]; + return Scaffold( + appBar: _appBar(context, title), + body: Center( + child: Container( + height: 400, + width: 300, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(20), + color: Get.isDarkMode ? Colors.white : Colors.grey[600]), + child: Center( + child: Text( + note, + style: bodyTextStyle, + ), + ), + )), + ); + } + + _appBar(BuildContext context, String title) { + return AppBar( + elevation: 0, + title: Text( + title, + style: toolbarTextStyle, + ), + backgroundColor: context.theme.backgroundColor, + leading: GestureDetector( + onTap: () { + Get.back(); + }, + child: Icon(Icons.arrow_back_ios, + size: 20, color: Get.isDarkMode ? Colors.white : Colors.black), + ), + ); + } +} diff --git a/lib/utils/colors.dart b/lib/utils/colors.dart index 2437b39..6a788a6 100644 --- a/lib/utils/colors.dart +++ b/lib/utils/colors.dart @@ -1,9 +1,9 @@ import 'package:flutter/material.dart'; const Color bluishClr = Color(0xFF00bfff); -const Color yellowClr = Color(0xFFf8de7e); +const Color yellowClr = Color(0xFFf4c430); const Color whiteClr = Color(0xFFffffff); -const Color pinkClr = Color(0xFFffc0cb); +const Color pinkClr = Color(0xFFff1493); const Color darkgratClr = Color(0xFFdcdcdc); const Color blackClr = Color(0xFF000000); diff --git a/lib/utils/textStyles.dart b/lib/utils/textStyles.dart index cab7c7e..ed5be2b 100644 --- a/lib/utils/textStyles.dart +++ b/lib/utils/textStyles.dart @@ -61,3 +61,19 @@ TextStyle get taskIsComplete { textStyle: TextStyle( fontSize: 10, fontWeight: FontWeight.bold, color: Colors.white)); } + +TextStyle get toolbarTextStyle { + return GoogleFonts.lato( + textStyle: TextStyle( + fontSize: 30, + fontWeight: FontWeight.bold, + color: Get.isDarkMode ? Colors.grey[400] : Colors.grey[600])); +} + +TextStyle get bodyTextStyle { + return GoogleFonts.lato( + textStyle: TextStyle( + fontSize: 25, + fontWeight: FontWeight.bold, + color: Get.isDarkMode ? Colors.black : Colors.white)); +}