0.1.2 #1
+24
-1
@@ -8,12 +8,14 @@ import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||
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:alarm/alarm.dart';
|
||||
|
||||
import 'dart:convert';
|
||||
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
tz.initializeTimeZones();
|
||||
await Alarm.init();
|
||||
runApp(const SunsetAlarmApp());
|
||||
}
|
||||
|
||||
@@ -230,6 +232,7 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
'Alarm set for ${alarmTime.hour.toString().padLeft(2, '0')}:${alarmTime.minute.toString().padLeft(2, '0')} (app must stay open)',
|
||||
);
|
||||
} else if (Platform.isAndroid) {
|
||||
/*** Notifcation Method - Works ***/
|
||||
// Android: use zonedSchedule (works in background)
|
||||
final tzAlarm = tz.TZDateTime.from(alarmTime, tz.local);
|
||||
const androidDetails = AndroidNotificationDetails(
|
||||
@@ -256,7 +259,27 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
debugPrint('DEBUG: Current time: ${DateTime.now().toUtc().toString()}');
|
||||
debugPrint('DEBUG: ${_notifications.toString()}');
|
||||
|
||||
debugPrint('alarm: $tzAlarm, now: ${tz.TZDateTime.now(tz.local)}');
|
||||
/*** Alarm Method - WIP ***/
|
||||
// Schedule:
|
||||
final settings = AlarmSettings(
|
||||
id: 42,
|
||||
dateTime: alarmTime, // your computed sunset time
|
||||
assetAudioPath: 'assets/alarm.mp3', // put an alarm sound in assets/
|
||||
loopAudio: true, // keeps ringing until dismissed
|
||||
vibrate: true,
|
||||
androidFullScreenIntent: true, // wakes screen like clock app
|
||||
volumeSettings: VolumeSettings.fade(
|
||||
volume: 0.8,
|
||||
fadeDuration: Duration(seconds: 5),
|
||||
),
|
||||
notificationSettings: const NotificationSettings(
|
||||
title: 'Sunset Alarm',
|
||||
body: 'The sun sets now. Time to get ready!',
|
||||
stopButton: 'Dismiss',
|
||||
),
|
||||
);
|
||||
|
||||
await Alarm.set(alarmSettings: settings);
|
||||
} else {
|
||||
_showSnack('Platform not detected, unsure how to show alarm.');
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user