Compare commits
14
Commits
dfca094c95
...
0.1.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bf1c4614a1 | ||
|
|
9c681094c1 | ||
|
|
a44d4b1574 | ||
|
|
ee9821f30f | ||
|
|
efde9624ff | ||
|
|
b9bc2ca77d | ||
|
|
105591910c | ||
|
|
6030da178c | ||
|
|
dad8fff6d2 | ||
|
|
3d89661b37 | ||
|
|
6de5fbe991 | ||
|
|
9ac5fdd4f6 | ||
|
|
5f14dbbc5b | ||
|
|
aade4fd7f2 |
No files matched your search
@@ -1,4 +1,32 @@
|
|||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
<manifest
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
>
|
||||||
|
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
|
||||||
|
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
|
||||||
|
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM"/>
|
||||||
|
<uses-permission android:name="android.permission.USE_EXACT_ALARM"/>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
|
||||||
|
<uses-permission android:name="android.permission.WAKE_LOCK"/>
|
||||||
|
<uses-permission android:name="android.permission.VIBRATE"/>
|
||||||
|
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT"/>
|
||||||
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY"/>
|
||||||
|
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
|
||||||
|
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
|
||||||
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK"/>
|
||||||
|
<uses-permission android:name="android.permission.USE_EXACT_ALARM"/>
|
||||||
|
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM"/>
|
||||||
|
|
||||||
|
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
|
||||||
|
<uses-permission android:name="android.permission.WAKE_LOCK"/>
|
||||||
|
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM"/>
|
||||||
|
-->
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:label="sunset_alarm"
|
android:label="sunset_alarm"
|
||||||
android:name="${applicationName}"
|
android:name="${applicationName}"
|
||||||
@@ -30,6 +58,60 @@
|
|||||||
<meta-data
|
<meta-data
|
||||||
android:name="flutterEmbedding"
|
android:name="flutterEmbedding"
|
||||||
android:value="2" />
|
android:value="2" />
|
||||||
|
|
||||||
|
<receiver
|
||||||
|
android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationReceiver"
|
||||||
|
android:enabled="true" />
|
||||||
|
<receiver
|
||||||
|
android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationBootReceiver"
|
||||||
|
android:enabled="true"
|
||||||
|
android:exported="false">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||||
|
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
|
||||||
|
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
|
||||||
|
<action android:name="com.htc.intent.action.QUICKBOOT_POWERON" />
|
||||||
|
</intent-filter>
|
||||||
|
</receiver>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
<service
|
||||||
|
android:name="com.gdelataillade.alarm.AlarmService"
|
||||||
|
android:foregroundServiceType="mediaPlayback"
|
||||||
|
android:exported="false" />
|
||||||
|
|
||||||
|
<receiver
|
||||||
|
android:name="com.gdelataillade.alarm.AlarmBroadcastReceiver"
|
||||||
|
android:exported="false" />
|
||||||
|
|
||||||
|
<receiver
|
||||||
|
android:name="com.gdelataillade.alarm.BootBroadcastReceiver"
|
||||||
|
android:enabled="false"
|
||||||
|
android:exported="false">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||||
|
</intent-filter>
|
||||||
|
</receiver>
|
||||||
|
|
||||||
|
<service
|
||||||
|
android:name="dev.fluttercommunity.plus.androidalarmmanager.AlarmService"
|
||||||
|
android:permission="android.permission.BIND_JOB_SERVICE"
|
||||||
|
android:exported="false"
|
||||||
|
tools:ignore="MissingClass"/>
|
||||||
|
<receiver
|
||||||
|
android:name="dev.fluttercommunity.plus.androidalarmmanager.AlarmBroadcastReceiver"
|
||||||
|
android:exported="false"
|
||||||
|
tools:ignore="MissingClass"/>
|
||||||
|
<receiver
|
||||||
|
android:name="dev.fluttercommunity.plus.androidalarmmanager.RebootBroadcastReceiver"
|
||||||
|
android:enabled="false"
|
||||||
|
android:exported="false"
|
||||||
|
tools:ignore="MissingClass">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||||
|
</intent-filter>
|
||||||
|
</receiver>
|
||||||
|
-->
|
||||||
</application>
|
</application>
|
||||||
<!-- Required to query activities that can process text, see:
|
<!-- Required to query activities that can process text, see:
|
||||||
https://developer.android.com/training/package-visibility and
|
https://developer.android.com/training/package-visibility and
|
||||||
@@ -42,9 +124,4 @@
|
|||||||
<data android:mimeType="text/plain"/>
|
<data android:mimeType="text/plain"/>
|
||||||
</intent>
|
</intent>
|
||||||
</queries>
|
</queries>
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
|
|
||||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
|
|
||||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
|
|
||||||
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM"/>
|
|
||||||
</manifest>
|
</manifest>
|
||||||
+56
-16
@@ -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/data/latest_all.dart' as tz;
|
||||||
import 'package:timezone/timezone.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 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
tz.initializeTimeZones();
|
tz.initializeTimeZones();
|
||||||
|
//await Alarm.init();
|
||||||
runApp(const SunsetAlarmApp());
|
runApp(const SunsetAlarmApp());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,7 +71,7 @@ class _HomeScreenState extends State<HomeScreen> {
|
|||||||
defaultActionName: 'Sunset Alarm',
|
defaultActionName: 'Sunset Alarm',
|
||||||
);
|
);
|
||||||
await _notifications.initialize(
|
await _notifications.initialize(
|
||||||
const InitializationSettings(
|
settings: const InitializationSettings(
|
||||||
android: androidInit,
|
android: androidInit,
|
||||||
iOS: iosInit,
|
iOS: iosInit,
|
||||||
linux: linuxInit,
|
linux: linuxInit,
|
||||||
@@ -173,6 +175,15 @@ class _HomeScreenState extends State<HomeScreen> {
|
|||||||
Timer? _alarmTimer;
|
Timer? _alarmTimer;
|
||||||
|
|
||||||
Future<void> _scheduleAlarm() async {
|
Future<void> _scheduleAlarm() async {
|
||||||
|
// Get the Notifications permission:
|
||||||
|
final android =
|
||||||
|
_notifications
|
||||||
|
.resolvePlatformSpecificImplementation<
|
||||||
|
AndroidFlutterLocalNotificationsPlugin
|
||||||
|
>();
|
||||||
|
await android?.requestNotificationsPermission();
|
||||||
|
|
||||||
|
// Ensure that Android has the correct alarm permissions.
|
||||||
final canSchedule = await android?.canScheduleExactNotifications();
|
final canSchedule = await android?.canScheduleExactNotifications();
|
||||||
if (canSchedule != true) {
|
if (canSchedule != true) {
|
||||||
_showSnack('Permissions not yet granted, requesting...');
|
_showSnack('Permissions not yet granted, requesting...');
|
||||||
@@ -211,16 +222,17 @@ class _HomeScreenState extends State<HomeScreen> {
|
|||||||
timeout: LinuxNotificationTimeout.expiresNever(),
|
timeout: LinuxNotificationTimeout.expiresNever(),
|
||||||
);
|
);
|
||||||
_notifications.show(
|
_notifications.show(
|
||||||
_alarmId,
|
id: _alarmId,
|
||||||
'Sunset in ${_minutesBefore} min',
|
title: 'Sunset in ${_minutesBefore} min',
|
||||||
'The sun sets at $sunsetText. Time to get ready!',
|
body: 'The sun sets at $sunsetText. Time to get ready!',
|
||||||
const NotificationDetails(linux: linuxDetails),
|
notificationDetails: const NotificationDetails(linux: linuxDetails),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
_showSnack(
|
_showSnack(
|
||||||
'Alarm set for ${alarmTime.hour.toString().padLeft(2, '0')}:${alarmTime.minute.toString().padLeft(2, '0')} (app must stay open)',
|
'Alarm set for ${alarmTime.hour.toString().padLeft(2, '0')}:${alarmTime.minute.toString().padLeft(2, '0')} (app must stay open)',
|
||||||
);
|
);
|
||||||
} else {
|
} else if (Platform.isAndroid) {
|
||||||
|
/*** Notifcation Method - Works ***/
|
||||||
// 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(
|
||||||
@@ -233,16 +245,42 @@ class _HomeScreenState extends State<HomeScreen> {
|
|||||||
category: AndroidNotificationCategory.alarm,
|
category: AndroidNotificationCategory.alarm,
|
||||||
);
|
);
|
||||||
await _notifications.zonedSchedule(
|
await _notifications.zonedSchedule(
|
||||||
_alarmId,
|
id: _alarmId,
|
||||||
'Sunset in ${_minutesBefore} min',
|
title: 'Sunset in ${_minutesBefore} min',
|
||||||
'The sun sets at $sunsetText. Time to get ready!',
|
body: 'The sun sets at $sunsetText. Time to get ready!',
|
||||||
tzAlarm,
|
scheduledDate: tzAlarm,
|
||||||
const NotificationDetails(android: androidDetails),
|
notificationDetails: const NotificationDetails(android: androidDetails),
|
||||||
androidScheduleMode: AndroidScheduleMode.alarmClock,
|
androidScheduleMode: AndroidScheduleMode.alarmClock,
|
||||||
uiLocalNotificationDateInterpretation:
|
|
||||||
UILocalNotificationDateInterpretation.absoluteTime,
|
|
||||||
);
|
);
|
||||||
_showSnack('Alarm scheduled.');
|
_showSnack('Alarm scheduled!');
|
||||||
|
debugPrint('DEBUG: Alarm time: ${tzAlarm.toString()}');
|
||||||
|
debugPrint('DEBUG: Current time: ${DateTime.now().toUtc().toString()}');
|
||||||
|
debugPrint('DEBUG: ${_notifications.toString()}');
|
||||||
|
// End Notification Method ***/
|
||||||
|
|
||||||
|
/*** 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);
|
||||||
|
// End Alarm Method ***/
|
||||||
|
} else {
|
||||||
|
_showSnack('Platform not detected, unsure how to show alarm.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -254,7 +292,7 @@ class _HomeScreenState extends State<HomeScreen> {
|
|||||||
} else {
|
} else {
|
||||||
_alarmTimer?.cancel();
|
_alarmTimer?.cancel();
|
||||||
if (!Platform.isLinux) {
|
if (!Platform.isLinux) {
|
||||||
await _notifications.cancel(_alarmId);
|
await _notifications.cancel(id: _alarmId);
|
||||||
}
|
}
|
||||||
_showSnack('Alarm cancelled.');
|
_showSnack('Alarm cancelled.');
|
||||||
}
|
}
|
||||||
@@ -383,8 +421,10 @@ class _HomeScreenState extends State<HomeScreen> {
|
|||||||
),
|
),
|
||||||
onChanged: (v) {
|
onChanged: (v) {
|
||||||
final val = int.tryParse(v);
|
final val = int.tryParse(v);
|
||||||
if (val != null && val > 0) {
|
if (val != null && val >= 0) {
|
||||||
_minutesBefore = val;
|
_minutesBefore = val;
|
||||||
|
} else {
|
||||||
|
_showSnack('Invalid Minute Value');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|||||||
+7
-6
@@ -9,16 +9,17 @@ environment:
|
|||||||
dependencies:
|
dependencies:
|
||||||
flutter:
|
flutter:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
geolocator: ^13.0.0
|
geolocator: ^14.1.1
|
||||||
shared_preferences: ^2.3.0
|
shared_preferences: ^2.5.5
|
||||||
flutter_local_notifications: ^18.0.0
|
flutter_local_notifications: ^22.3.1
|
||||||
timezone: ^0.9.0
|
timezone: ^0.11.1
|
||||||
http: ^1.2.0
|
http: ^1.6.0
|
||||||
|
alarm: ^5.13.2
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
flutter_lints: ^5.0.0
|
flutter_lints: ^6.0.0
|
||||||
|
|
||||||
flutter:
|
flutter:
|
||||||
uses-material-design: true
|
uses-material-design: true
|
||||||
Reference in new issue
Block a user