Browse Source

Notifiend task screen added

master
Apalak Dutta 2 years ago
parent
commit
2562aa8dea
8 changed files with 144 additions and 22 deletions
  1. +1
    -1
      android/app/src/main/AndroidManifest.xml
  2. +1
    -1
      ios/Runner/Info.plist
  3. +31
    -5
      lib/services/notification_service.dart
  4. +13
    -0
      lib/ui/add_task_screen.dart
  5. +27
    -13
      lib/ui/my_home_screen.dart
  6. +53
    -0
      lib/ui/notified_screen.dart
  7. +2
    -2
      lib/utils/colors.dart
  8. +16
    -0
      lib/utils/textStyles.dart

+ 1
- 1
android/app/src/main/AndroidManifest.xml View File

@ -8,7 +8,7 @@
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<application
android:label="sqflite_pust_local_notification"
android:label="My Task"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">
<activity


+ 1
- 1
ios/Runner/Info.plist View File

@ -13,7 +13,7 @@
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>sqflite_pust_local_notification</string>
<string>My Task</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>


+ 31
- 5
lib/services/notification_service.dart View File

@ -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));
}
}
}

+ 13
- 0
lib/ui/add_task_screen.dart View File

@ -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<AddTaskScreen> {
];
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<AddTaskScreen> {
_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(


+ 27
- 13
lib/ui/my_home_screen.dart View File

@ -26,6 +26,7 @@ class _MyHomeScreenState extends State<MyHomeScreen> {
final TaskController _taskController = Get.put(TaskController());
var taskList = <TaskModel>[].obs;
DateTime _selectedDate = DateTime.now();
DateTime _today = DateTime.now();
var notifyHelper;
@override
void initState() {
@ -34,6 +35,7 @@ class _MyHomeScreenState extends State<MyHomeScreen> {
notifyHelper = NotifyHelper();
notifyHelper.initializeNotification();
notifyHelper.requestIOSPermissions();
_taskController.getTask();
//_getTask();
}
@ -159,10 +161,21 @@ class _MyHomeScreenState extends State<MyHomeScreen> {
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<MyHomeScreen> {
));
}
_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),
)
],
)),
));
}


+ 53
- 0
lib/ui/notified_screen.dart View 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),
),
);
}
}

+ 2
- 2
lib/utils/colors.dart View File

@ -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);


+ 16
- 0
lib/utils/textStyles.dart View File

@ -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));
}

Loading…
Cancel
Save