···11package space.kasper.notifier;
2233+import android.content.pm.PackageManager;
34import android.os.Bundle;
55+46import io.flutter.app.FlutterActivity;
77+import io.flutter.plugin.common.MethodCall;
88+import io.flutter.plugin.common.MethodChannel;
59import io.flutter.plugins.GeneratedPluginRegistrant;
1010+import android.content.pm.PackageInfo;
611712public class MainActivity extends FlutterActivity {
1313+ private static final String CHANNEL = "space.kasper.notifier/get_install_date";
1414+815 @Override
916 protected void onCreate(Bundle savedInstanceState) {
1017 super.onCreate(savedInstanceState);
1118 GeneratedPluginRegistrant.registerWith(this);
1919+2020+ new MethodChannel(getFlutterView(), CHANNEL).setMethodCallHandler(
2121+ new MethodChannel.MethodCallHandler() {
2222+ @Override
2323+ public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) {
2424+ if (methodCall.method.equals("get_install_date")) {
2525+ PackageInfo packageInfo = null;
2626+ try {
2727+ packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
2828+ long firstInstallTime = packageInfo.firstInstallTime;
2929+ result.success(String.valueOf(firstInstallTime));
3030+ } catch (PackageManager.NameNotFoundException e) {
3131+ e.printStackTrace();
3232+ result.error("PACKAGE NAME NOT FOUND", "Package name was not found", null);
3333+ }
3434+ }
3535+ }
3636+ }
3737+ );
1238 }
1339}
+21-8
lib/models/list.dart
···22import 'dart:convert';
33import 'dart:core';
44import 'dart:ui';
55+import 'package:flutter/material.dart';
66+import 'package:flutter/services.dart';
57import 'package:scoped_model/scoped_model.dart';
68import 'package:shared_preferences/shared_preferences.dart';
79import 'package:flutter_local_notifications/flutter_local_notifications.dart';
···110112 int daysTillMonday = (7 - dateWeekday);
111113 // set newDay to monday next week
112114 newDay += daysTillMonday;
113113-115115+114116 // skip weeks. If it's repeated every 2 week, add 7 days to newDay
115117 newDay += (7 * repeatEvery) - 1;
116118···118120 int firstCheckedWeekday = weekdays.indexOf(true);
119121 newDay += firstCheckedWeekday;
120122 }
121121-122123 } else if (repeat == 'monthly') {
123124 newMonth += repeatEvery;
124125 } else if (repeat == 'yearly') {
···141142142143 setNotifications() async {
143144 print('[notifier] _setNotification');
145145+146146+ const platform = MethodChannel('space.kasper.notifier/get_install_date');
147147+ String installDateInt = await platform.invokeMethod('get_install_date');
148148+ DateTime installDate = DateTime.fromMillisecondsSinceEpoch(int.parse(installDateInt));
144149145150 var androidPlatformChannelSpecifics = AndroidNotificationDetails(
146151 'scheduled_notifications',
···178183 // date to schedule notification to now
179184 DateTime date = DateTime.fromMillisecondsSinceEpoch(notificationItem['date']);
180185 // date to schedule notification to next time
181181- DateTime nextDate = getNextDate(
182182- date: date,
183183- repeat: notificationItem['repeat'],
184184- repeatEvery: notificationItem['repeatEvery'],
185185- weekdays: List<bool>.from(notificationItem['weekdays']),
186186- );
186186+ bool done = false;
187187+ DateTime nextDate;
188188+ while (!done) {
189189+ nextDate = getNextDate(
190190+ date: date,
191191+ repeat: notificationItem['repeat'],
192192+ repeatEvery: notificationItem['repeatEvery'],
193193+ weekdays: List<bool>.from(notificationItem['weekdays']),
194194+ );
195195+ // if the app was installed after nextDate, get skip over this date and get the next nextDate. This is for when you reinstall the app and get your old notifications loaded (e.g via google backup).
196196+ if (installDate.millisecondsSinceEpoch > nextDate.millisecondsSinceEpoch) {
197197+ done = true;
198198+ }
199199+ }
187200188201 // Only set date to nextDate if the notification has already fired. The date needs to be the closest future notification date. When notifications are scheduled for the first time, their date should therefore not be updated.
189202 if (notificationItem['date'] < DateTime.now().millisecondsSinceEpoch) {