Skip to content

Commit

Permalink
Notification Manager left to update
Browse files Browse the repository at this point in the history
  • Loading branch information
deliciafernandes committed Dec 12, 2020
1 parent a833b5b commit d410bf6
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 63 deletions.
2 changes: 2 additions & 0 deletions lib/models/reminder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ class Reminder {
String description;
String date;
String time;
var userLocation;

bool isDone;

Expand All @@ -15,5 +16,6 @@ class Reminder {
this.description,
this.date,
this.time,
this.userLocation,
this.isDone = false});
}
37 changes: 33 additions & 4 deletions lib/models/reminder_db.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ class ReminderDB extends ChangeNotifier {

List<Reminder> _reminderList = [
// Reminder(
// title: 'Reminder Title',
// description: 'Reminder description',
// date: 'Today',
// time: '17:00 pm'),
// title: 'Reminder Title',
// description: 'Reminder description',
// date: 'Today',
// time: '17:00 pm',
// userLocation: 'Andheri East',
// ),
];

UnmodifiableListView<Reminder> get reminderList {
Expand Down Expand Up @@ -61,6 +63,33 @@ class ReminderDB extends ChangeNotifier {
notifyListeners();
}

void addReminderBasedOnLocation(
String title,
String description,
var userLocation,
) {
final reminder = Reminder(
title: title,
description: description,
userLocation: userLocation,
);

//Add reminder to reminder local db
_reminderList.add(reminder);

//Add reminder to reminder remote db only if user is logged in
if (checkIfUserLoggedIn.getCurrentUser()) {
_firestore.collection('locationBasedReminders').add({
'title': title,
'description': description,
'userLocation': userLocation,
'user': checkIfUserLoggedIn.getCurrentUserEmail(),
});
}

notifyListeners();
}

void updateReminder(Reminder reminder) {
reminder.toggleDone();
notifyListeners();
Expand Down
2 changes: 2 additions & 0 deletions lib/views/body_widgets/todays_priorities_body.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class _TodaysPrioritiesBodyState extends State<TodaysPrioritiesBody> {
description: simple.description,
date: simple.date,
time: simple.time,
userLocation: simple.userLocation,
isLocationBased: simple.userLocation != null ? true : false,
isChecked: simple.isDone,
checkBoxCallBack: (checkBoxState) {
reminderDB.updateReminder(simple);
Expand Down
52 changes: 29 additions & 23 deletions lib/widgets/bottom_reminder_modal_sheet.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:checklst/models/reminder_db.dart';
import 'package:checklst/utilities/location_service.dart';
import 'package:checklst/utilities/routing_constants.dart';
import 'package:date_time_picker/date_time_picker.dart';
import 'package:flutter/material.dart';
Expand All @@ -15,6 +16,9 @@ class BottomReminderSheet extends StatefulWidget {
}

class _BottomReminderSheetState extends State<BottomReminderSheet> {
LocationService locationService = LocationService();
var userLocation = 'Mumbai';

bool _isSwitched = false;
final titleTextController = TextEditingController();
final descriptionTextController = TextEditingController();
Expand All @@ -24,9 +28,12 @@ class _BottomReminderSheetState extends State<BottomReminderSheet> {
int hours;
int minutes;

void getUserLocation() async {
userLocation = await locationService.getLocation();
}

void formatDate() {
DateTime parsedDate = DateTime.parse(date);
print(parsedDate);

var newFormat = DateFormat("d MMM y");
date = newFormat.format(parsedDate);
Expand All @@ -42,14 +49,13 @@ class _BottomReminderSheetState extends State<BottomReminderSheet> {

hours = int.parse(reminderTime[0]) - int.parse(currentTime[0]);
minutes = int.parse(reminderTime[1]) - int.parse(currentTime[1]) - 1;

print('$hours $minutes');
}

FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
FlutterLocalNotificationsPlugin();

void initState() {
getUserLocation();
super.initState();
var initializationSettingsAndroid =
AndroidInitializationSettings('playstore');
Expand Down Expand Up @@ -251,28 +257,28 @@ class _BottomReminderSheetState extends State<BottomReminderSheet> {
padding: EdgeInsets.only(
left: 15.w, bottom: 11.h, top: 11.h, right: 15.w),
onPressed: () {
//TODO: fixup location functionality
scheduleNotificationBasedOnTime();
Provider.of<ReminderDB>(context, listen: false).addReminder(
titleTextController.text,
descriptionTextController.text,
date,
time);

titleTextController.clear();
titleTextController.clear();
Navigator.pop(context);
if (titleTextController.text == '' ||
descriptionTextController.text == '') {
//Test case if user clicks add with null title and description
} else {
// Reminder based on location
if (_isSwitched) {
scheduleNotificationBasedOnLocation();
Provider.of<ReminderDB>(context, listen: false)
.addReminderBasedOnLocation(titleTextController.text,
descriptionTextController.text, userLocation);
titleTextController.clear();
titleTextController.clear();
} else {
scheduleNotificationBasedOnTime();
Provider.of<ReminderDB>(context, listen: false)
.addReminder(titleTextController.text,
descriptionTextController.text, date, time);

// Reminder based on location
if (_isSwitched) {
scheduleNotificationBasedOnLocation();
// Provider.of<ReminderDB>(context, listen: false).addReminder(
// titleTextController.text,
// descriptionTextController.text,
// );
titleTextController.clear();
titleTextController.clear();
}

titleTextController.clear();
titleTextController.clear();
Navigator.pop(context);
}
},
Expand Down
116 changes: 80 additions & 36 deletions lib/widgets/reminder_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,24 @@ import 'package:flutter_slidable/flutter_slidable.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class ReminderTile extends StatefulWidget {
final bool isLocationBased;

final String title;
final String description;
final String date;
final String time;
final userLocation;
final bool isChecked;
final Function checkBoxCallBack;
final Function deleteCallBack;

ReminderTile({
@required this.title,
@required this.description,
@required this.date,
@required this.time,
this.date,
this.time,
this.userLocation,
@required this.isLocationBased,
this.isChecked,
this.checkBoxCallBack,
this.deleteCallBack,
Expand Down Expand Up @@ -138,42 +143,81 @@ class _ReminderTileState extends State<ReminderTile> {
),
),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
Icon(
Icons.alarm,
// color: Colors.grey[350],
color: _color,
size: 15.0.h,
),
Text(
' ${widget.date}, ${widget.time}',
style: TextStyle(
fontSize: 13.0.ssp,
fontFamily: 'WorkSans',
fontWeight: FontWeight.w600,
// color: Colors.grey[350],
color: _color,
widget.isLocationBased
? Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
Icon(
Icons.location_on,
// color: Colors.grey[350],
color: _color,
size: 15.0.h,
),
Text(
widget.userLocation,
style: TextStyle(
fontSize: 13.0.ssp,
fontFamily: 'WorkSans',
fontWeight: FontWeight.w600,
// color: Colors.grey[350],
color: _color,
),
),
],
),
),
],
),
Transform.scale(
scale: 0.7,
child: CircularCheckBox(
value: widget.isChecked,
activeColor: Colors.grey[350],
checkColor: Colors.black,
inactiveColor: Colors.grey,
materialTapTargetSize: MaterialTapTargetSize.padded,
onChanged: widget.checkBoxCallBack,
Transform.scale(
scale: 0.7,
child: CircularCheckBox(
value: widget.isChecked,
activeColor: Colors.grey[350],
checkColor: Colors.black,
inactiveColor: Colors.grey,
materialTapTargetSize:
MaterialTapTargetSize.padded,
onChanged: widget.checkBoxCallBack,
),
),
],
)
: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
Icon(
Icons.alarm,
// color: Colors.grey[350],
color: _color,
size: 15.0.h,
),
Text(
' ${widget.date}, ${widget.time}',
style: TextStyle(
fontSize: 13.0.ssp,
fontFamily: 'WorkSans',
fontWeight: FontWeight.w600,
// color: Colors.grey[350],
color: _color,
),
),
],
),
Transform.scale(
scale: 0.7,
child: CircularCheckBox(
value: widget.isChecked,
activeColor: Colors.grey[350],
checkColor: Colors.black,
inactiveColor: Colors.grey,
materialTapTargetSize:
MaterialTapTargetSize.padded,
onChanged: widget.checkBoxCallBack,
),
),
],
),
),
],
),
],
),
),
Expand Down

0 comments on commit d410bf6

Please sign in to comment.