Notifiend task screen added
This commit is contained in:
parent
78b23af75a
commit
2562aa8dea
@ -8,7 +8,7 @@
|
|||||||
<uses-permission android:name="android.permission.VIBRATE" />
|
<uses-permission android:name="android.permission.VIBRATE" />
|
||||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
|
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
|
||||||
<application
|
<application
|
||||||
android:label="sqflite_pust_local_notification"
|
android:label="My Task"
|
||||||
android:name="${applicationName}"
|
android:name="${applicationName}"
|
||||||
android:icon="@mipmap/ic_launcher">
|
android:icon="@mipmap/ic_launcher">
|
||||||
<activity
|
<activity
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
<key>CFBundleInfoDictionaryVersion</key>
|
<key>CFBundleInfoDictionaryVersion</key>
|
||||||
<string>6.0</string>
|
<string>6.0</string>
|
||||||
<key>CFBundleName</key>
|
<key>CFBundleName</key>
|
||||||
<string>sqflite_pust_local_notification</string>
|
<string>My Task</string>
|
||||||
<key>CFBundlePackageType</key>
|
<key>CFBundlePackageType</key>
|
||||||
<string>APPL</string>
|
<string>APPL</string>
|
||||||
<key>CFBundleShortVersionString</key>
|
<key>CFBundleShortVersionString</key>
|
||||||
|
@ -3,9 +3,12 @@ import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
|||||||
import 'package:flutter_native_timezone/flutter_native_timezone.dart';
|
import 'package:flutter_native_timezone/flutter_native_timezone.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:sqflite_pust_local_notification/models/task_model.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/data/latest.dart' as tz;
|
||||||
import 'package:timezone/timezone.dart' as tz;
|
import 'package:timezone/timezone.dart' as tz;
|
||||||
|
|
||||||
|
import '../utils/assets_string.dart';
|
||||||
|
|
||||||
class NotifyHelper {
|
class NotifyHelper {
|
||||||
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
|
FlutterLocalNotificationsPlugin 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 {
|
displayNotification({required String title, required String body}) async {
|
||||||
print("doing test");
|
print("doing test");
|
||||||
var androidPlatformChannelSpecifics = new AndroidNotificationDetails(
|
var androidPlatformChannelSpecifics = new AndroidNotificationDetails(
|
||||||
@ -61,7 +85,7 @@ class NotifyHelper {
|
|||||||
title,
|
title,
|
||||||
body,
|
body,
|
||||||
platformChannelSpecifics,
|
platformChannelSpecifics,
|
||||||
payload: 'Default_Sound',
|
payload: title,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,7 +104,8 @@ class NotifyHelper {
|
|||||||
androidAllowWhileIdle: true,
|
androidAllowWhileIdle: true,
|
||||||
uiLocalNotificationDateInterpretation:
|
uiLocalNotificationDateInterpretation:
|
||||||
UILocalNotificationDateInterpretation.absoluteTime,
|
UILocalNotificationDateInterpretation.absoluteTime,
|
||||||
matchDateTimeComponents: DateTimeComponents.time);
|
matchDateTimeComponents: DateTimeComponents.time,
|
||||||
|
payload: "${taskModel.title}|" + "${taskModel.note}|");
|
||||||
}
|
}
|
||||||
|
|
||||||
tz.TZDateTime _convertTimeDeration(int hours, int minutes) {
|
tz.TZDateTime _convertTimeDeration(int hours, int minutes) {
|
||||||
@ -113,8 +138,9 @@ class NotifyHelper {
|
|||||||
} else {
|
} else {
|
||||||
print("Notification Done");
|
print("Notification Done");
|
||||||
}
|
}
|
||||||
Get.to(() => Container(
|
if (payload == "Theme Change" || payload == "Add Task") {
|
||||||
color: Colors.white,
|
} else {
|
||||||
));
|
Get.to(() => NotifiedScreen(lable: payload));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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/colors.dart';
|
||||||
import 'package:sqflite_pust_local_notification/utils/textStyles.dart';
|
import 'package:sqflite_pust_local_notification/utils/textStyles.dart';
|
||||||
import 'package:sqflite_pust_local_notification/widgets/my_button.dart';
|
import 'package:sqflite_pust_local_notification/widgets/my_button.dart';
|
||||||
|
import '../services/notification_service.dart';
|
||||||
import '../utils/assets_string.dart';
|
import '../utils/assets_string.dart';
|
||||||
import '../widgets/my_input_field.dart';
|
import '../widgets/my_input_field.dart';
|
||||||
|
|
||||||
@ -40,6 +41,16 @@ class _AddTaskScreenState extends State<AddTaskScreen> {
|
|||||||
];
|
];
|
||||||
|
|
||||||
int _selectedColor = 0;
|
int _selectedColor = 0;
|
||||||
|
var notifyHelper;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
// TODO: implement initState
|
||||||
|
super.initState();
|
||||||
|
notifyHelper = NotifyHelper();
|
||||||
|
notifyHelper.initializeNotification();
|
||||||
|
notifyHelper.requestIOSPermissions();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@ -177,6 +188,8 @@ class _AddTaskScreenState extends State<AddTaskScreen> {
|
|||||||
_validateDate() {
|
_validateDate() {
|
||||||
if (_titleController.text.isNotEmpty && _noteController.text.isNotEmpty) {
|
if (_titleController.text.isNotEmpty && _noteController.text.isNotEmpty) {
|
||||||
_addTaskToDb();
|
_addTaskToDb();
|
||||||
|
notifyHelper.displayNotification(
|
||||||
|
title: "Add Task", body: "A new task is added");
|
||||||
Get.back();
|
Get.back();
|
||||||
} else if (_titleController.text.isEmpty || _noteController.text.isEmpty) {
|
} else if (_titleController.text.isEmpty || _noteController.text.isEmpty) {
|
||||||
Get.snackbar(
|
Get.snackbar(
|
||||||
|
@ -26,6 +26,7 @@ class _MyHomeScreenState extends State<MyHomeScreen> {
|
|||||||
final TaskController _taskController = Get.put(TaskController());
|
final TaskController _taskController = Get.put(TaskController());
|
||||||
var taskList = <TaskModel>[].obs;
|
var taskList = <TaskModel>[].obs;
|
||||||
DateTime _selectedDate = DateTime.now();
|
DateTime _selectedDate = DateTime.now();
|
||||||
|
DateTime _today = DateTime.now();
|
||||||
var notifyHelper;
|
var notifyHelper;
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@ -34,6 +35,7 @@ class _MyHomeScreenState extends State<MyHomeScreen> {
|
|||||||
notifyHelper = NotifyHelper();
|
notifyHelper = NotifyHelper();
|
||||||
notifyHelper.initializeNotification();
|
notifyHelper.initializeNotification();
|
||||||
notifyHelper.requestIOSPermissions();
|
notifyHelper.requestIOSPermissions();
|
||||||
|
_taskController.getTask();
|
||||||
//_getTask();
|
//_getTask();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,10 +161,21 @@ class _MyHomeScreenState extends State<MyHomeScreen> {
|
|||||||
int.parse(myTime.toString().split(":")[0]),
|
int.parse(myTime.toString().split(":")[0]),
|
||||||
int.parse(myTime.toString().split(":")[1]),
|
int.parse(myTime.toString().split(":")[1]),
|
||||||
taskModel);
|
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)) {
|
if (taskModel.date == DateFormat.yMd().format(_selectedDate)) {
|
||||||
return _setTAskView(index, taskModel);
|
return _setTaskView(index, taskModel);
|
||||||
} else {
|
} else {
|
||||||
return Container();
|
return Container();
|
||||||
}
|
}
|
||||||
@ -171,11 +184,12 @@ class _MyHomeScreenState extends State<MyHomeScreen> {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
_setTAskView(int index, TaskModel taskModel) {
|
_setTaskView(int index, TaskModel taskModel) {
|
||||||
return AnimationConfiguration.staggeredList(
|
return AnimationConfiguration.staggeredList(
|
||||||
position: index,
|
position: index,
|
||||||
child: SlideAnimation(
|
child: SlideAnimation(
|
||||||
child: FadeInAnimation(
|
child: FlipAnimation(
|
||||||
|
delay: Duration(milliseconds: 200),
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
GestureDetector(
|
GestureDetector(
|
||||||
|
53
lib/ui/notified_screen.dart
Normal file
53
lib/ui/notified_screen.dart
Normal file
@ -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),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -1,9 +1,9 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
const Color bluishClr = Color(0xFF00bfff);
|
const Color bluishClr = Color(0xFF00bfff);
|
||||||
const Color yellowClr = Color(0xFFf8de7e);
|
const Color yellowClr = Color(0xFFf4c430);
|
||||||
const Color whiteClr = Color(0xFFffffff);
|
const Color whiteClr = Color(0xFFffffff);
|
||||||
const Color pinkClr = Color(0xFFffc0cb);
|
const Color pinkClr = Color(0xFFff1493);
|
||||||
const Color darkgratClr = Color(0xFFdcdcdc);
|
const Color darkgratClr = Color(0xFFdcdcdc);
|
||||||
const Color blackClr = Color(0xFF000000);
|
const Color blackClr = Color(0xFF000000);
|
||||||
|
|
||||||
|
@ -61,3 +61,19 @@ TextStyle get taskIsComplete {
|
|||||||
textStyle: TextStyle(
|
textStyle: TextStyle(
|
||||||
fontSize: 10, fontWeight: FontWeight.bold, color: Colors.white));
|
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));
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user