4 Commits
26 changed files with 22 additions and 7 deletions

No files matched your search

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 216 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 173 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 284 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 443 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 565 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 816 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 910 B

After

Width:  |  Height:  |  Size: 456 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.5 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 818 B

After

Width:  |  Height:  |  Size: 626 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 602 B

After

Width:  |  Height:  |  Size: 334 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1022 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 586 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 946 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.7 KiB

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.0 KiB

After

Width:  |  Height:  |  Size: 6.8 KiB

+22 -7
View File
@@ -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});
@@ -189,6 +193,10 @@ class _HomeScreenState extends State<HomeScreen> {
} finally { } finally {
setState(() => _loading = false); setState(() => _loading = false);
} }
if (_alarmEnabled) {
_scheduleAlarm();
}
} }
Timer? _alarmTimer; Timer? _alarmTimer;
@@ -251,7 +259,8 @@ class _HomeScreenState extends State<HomeScreen> {
'Alarm Enabled @ ${alarmTime.hour.toString().padLeft(2, '0')}:${alarmTime.minute.toString().padLeft(2, '0')} (App Must Stay Open!)', 'Alarm Enabled @ ${alarmTime.hour.toString().padLeft(2, '0')}:${alarmTime.minute.toString().padLeft(2, '0')} (App Must Stay Open!)',
); );
} 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 +277,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,
@@ -294,9 +307,11 @@ class _HomeScreenState extends State<HomeScreen> {
title: 'Sunset Alarm', title: 'Sunset Alarm',
body: 'Sun is setting in ${_minutesBefore} minute(s)!', body: 'Sun is setting in ${_minutesBefore} minute(s)!',
stopButton: 'Dismiss', stopButton: 'Dismiss',
icon: 'ic_notification',
), ),
); );
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 +328,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');
} }
@@ -434,6 +449,9 @@ class _HomeScreenState extends State<HomeScreen> {
_sunsetController.text, _sunsetController.text,
), ),
); );
if (_alarmEnabled) {
_scheduleAlarm();
}
} }
}, },
), ),
@@ -466,9 +484,6 @@ class _HomeScreenState extends State<HomeScreen> {
onPressed: () { onPressed: () {
if (!_loading) { if (!_loading) {
_fetchSunset(); _fetchSunset();
if (_alarmEnabled) {
_scheduleAlarm();
}
} }
}, },
), ),
Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.