Skip to content

Commit

Permalink
Notifications Done
Browse files Browse the repository at this point in the history
  • Loading branch information
HossamElghamry committed Jul 3, 2019
1 parent 8603728 commit 69a1aa1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
8 changes: 7 additions & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.medicine_reminder">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
Expand Down Expand Up @@ -31,5 +30,12 @@
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<receiver android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationBootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"></action>
</intent-filter>
</receiver>

<receiver android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationReceiver" />
</application>
</manifest>
6 changes: 5 additions & 1 deletion lib/src/ui/medicine_details/medicine_details.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class MedicineDetails extends StatelessWidget {

MedicineDetails(this.medicine, this.type);

void deleteMedicine() {}

@override
Widget build(BuildContext context) {
return Scaffold(
Expand Down Expand Up @@ -50,7 +52,9 @@ class MedicineDetails extends StatelessWidget {
child: FlatButton(
color: Color(0xFF3EB16F),
shape: StadiumBorder(),
onPressed: () {},
onPressed: () {
deleteMedicine();
},
child: Center(
child: Text(
"DELETE MEDICINE",
Expand Down
17 changes: 11 additions & 6 deletions lib/src/ui/new_entry/new_entry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import 'package:medicine_reminder/src/ui/new_entry/new_entry_bloc.dart';
import 'package:provider/provider.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';

FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin;

class NewEntry extends StatefulWidget {
@override
_NewEntryState createState() => _NewEntryState();
Expand All @@ -18,25 +16,30 @@ class NewEntry extends StatefulWidget {
class _NewEntryState extends State<NewEntry> {
TextEditingController nameController = TextEditingController();
TextEditingController dosageController = TextEditingController();
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
FlutterLocalNotificationsPlugin();

void dispose() {
super.dispose();
nameController.dispose();
dosageController.dispose();
}

void initState() {
super.initState();
flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
initializeNotifications() async {
var initializationSettingsAndroid =
AndroidInitializationSettings('@mipmap/ic_launcher');
var initializationSettingsIOS = IOSInitializationSettings();
var initializationSettings = InitializationSettings(
initializationSettingsAndroid, initializationSettingsIOS);
flutterLocalNotificationsPlugin.initialize(initializationSettings,
await flutterLocalNotificationsPlugin.initialize(initializationSettings,
onSelectNotification: onSelectNotification);
}

void initState() {
super.initState();
initializeNotifications();
}

Future onSelectNotification(String payload) async {
if (payload != null) {
debugPrint('notification payload: ' + payload);
Expand All @@ -61,6 +64,7 @@ class _NewEntryState extends State<NewEntry> {
var iOSPlatformChannelSpecifics = IOSNotificationDetails();
var platformChannelSpecifics = NotificationDetails(
androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);

for (int i = 0; i < (24 / medicine.interval).floor(); i++) {
if ((hour + (medicine.interval * i) > 24)) {
hour = hour + (medicine.interval * i) - 24;
Expand All @@ -75,6 +79,7 @@ class _NewEntryState extends State<NewEntry> {
platformChannelSpecifics);
hour = ogValue;
}
//await flutterLocalNotificationsPlugin.cancelAll();
}

@override
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ dependencies:
rxdart: ^0.22.0
provider: ^3.0.0+1
shared_preferences: 0.5.2
flutter_local_notifications:
flutter_local_notifications:

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit 69a1aa1

Please sign in to comment.