1.0.0 #2
+13
-3
@@ -6,6 +6,7 @@ import 'package:geolocator/geolocator.dart';
|
|||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||||
import 'package:timezone/data/latest_all.dart' as tz;
|
import 'package:timezone/data/latest_all.dart' as tz;
|
||||||
|
import 'package:timezone/timezone.dart' as tz;
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
import 'package:alarm/alarm.dart';
|
import 'package:alarm/alarm.dart';
|
||||||
|
|
||||||
@@ -25,6 +26,9 @@ void main() async {
|
|||||||
runApp(const SunsetAlarmApp());
|
runApp(const SunsetAlarmApp());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ANDROID_USE_NOTIF = false;
|
||||||
|
const ANDROID_USE_ALARM = !ANDROID_USE_NOTIF;
|
||||||
|
|
||||||
class SunsetAlarmApp extends StatelessWidget {
|
class SunsetAlarmApp extends StatelessWidget {
|
||||||
const SunsetAlarmApp({super.key});
|
const SunsetAlarmApp({super.key});
|
||||||
|
|
||||||
@@ -252,6 +256,7 @@ class _HomeScreenState extends State<HomeScreen> {
|
|||||||
);
|
);
|
||||||
} else if (Platform.isAndroid) {
|
} else if (Platform.isAndroid) {
|
||||||
/*** Notifcation Method - Works ***/
|
/*** Notifcation Method - Works ***/
|
||||||
|
if (ANDROID_USE_NOTIF) {
|
||||||
// Android: use zonedSchedule (works in background)
|
// Android: use zonedSchedule (works in background)
|
||||||
final tzAlarm = tz.TZDateTime.from(alarmTime, tz.local);
|
final tzAlarm = tz.TZDateTime.from(alarmTime, tz.local);
|
||||||
const androidDetails = AndroidNotificationDetails(
|
const androidDetails = AndroidNotificationDetails(
|
||||||
@@ -268,16 +273,20 @@ class _HomeScreenState extends State<HomeScreen> {
|
|||||||
title: 'Sunset in ${_minutesBefore} min',
|
title: 'Sunset in ${_minutesBefore} min',
|
||||||
body: 'The sun sets at $sunsetText. Time to get ready!',
|
body: 'The sun sets at $sunsetText. Time to get ready!',
|
||||||
scheduledDate: tzAlarm,
|
scheduledDate: tzAlarm,
|
||||||
notificationDetails: const NotificationDetails(android: androidDetails),
|
notificationDetails: const NotificationDetails(
|
||||||
|
android: androidDetails,
|
||||||
|
),
|
||||||
androidScheduleMode: AndroidScheduleMode.alarmClock,
|
androidScheduleMode: AndroidScheduleMode.alarmClock,
|
||||||
);
|
);
|
||||||
_showSnack('Alarm scheduled!');
|
_showSnack('Alarm scheduled!');
|
||||||
debugPrint('DEBUG: Alarm time: ${tzAlarm.toString()}');
|
debugPrint('DEBUG: Alarm time: ${tzAlarm.toString()}');
|
||||||
debugPrint('DEBUG: Current time: ${DateTime.now().toUtc().toString()}');
|
debugPrint('DEBUG: Current time: ${DateTime.now().toUtc().toString()}');
|
||||||
debugPrint('DEBUG: ${_notifications.toString()}');
|
debugPrint('DEBUG: ${_notifications.toString()}');
|
||||||
|
}
|
||||||
// End Notification Method ***/
|
// End Notification Method ***/
|
||||||
|
|
||||||
/*** Alarm Method - WIP ***/
|
/*** Alarm Method - WIP ***/
|
||||||
|
if (ANDROID_USE_ALARM) {
|
||||||
// Schedule:
|
// Schedule:
|
||||||
final settings = AlarmSettings(
|
final settings = AlarmSettings(
|
||||||
id: _alarmId,
|
id: _alarmId,
|
||||||
@@ -297,6 +306,7 @@ class _HomeScreenState extends State<HomeScreen> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
await Alarm.set(alarmSettings: settings);
|
await Alarm.set(alarmSettings: settings);
|
||||||
|
}
|
||||||
// End Alarm Method ***/
|
// End Alarm Method ***/
|
||||||
_showSnack('Alarm Scheduled @ ${alarmTime}');
|
_showSnack('Alarm Scheduled @ ${alarmTime}');
|
||||||
} else {
|
} else {
|
||||||
@@ -313,10 +323,10 @@ class _HomeScreenState extends State<HomeScreen> {
|
|||||||
_alarmTimer?.cancel();
|
_alarmTimer?.cancel();
|
||||||
if (!Platform.isLinux) {
|
if (!Platform.isLinux) {
|
||||||
// Notification Method
|
// Notification Method
|
||||||
//await _notifications.cancel(id: _alarmId);
|
if (ANDROID_USE_NOTIF) await _notifications.cancel(id: _alarmId);
|
||||||
|
|
||||||
// Alarm Method
|
// Alarm Method
|
||||||
await Alarm.stop(_alarmId);
|
if (ANDROID_USE_ALARM) await Alarm.stop(_alarmId);
|
||||||
}
|
}
|
||||||
_showSnack('Alarm Cancelled');
|
_showSnack('Alarm Cancelled');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user