30 Commits
Author SHA1 Message Date
me af32c1e313 Merge pull request '1.0.1' (#3) from dev into main
Reviewed-on: #3
2026-09-29 17:54:04 -07:00
me 4f15f94629 main, forget about the switch title fanciness for now, will make them different rows in a future version and handle minutes dynamically. 2026-09-29 17:51:49 -07:00
me b02a6ff80a main, more work on getting variables to flow properly and minutes to not take up space when the switch has text. 2026-09-29 17:28:41 -07:00
me b649c9c1e7 Random file, likely created by Flutter. 2026-09-29 17:27:54 -07:00
me 23ca37c671 main, handle variable state values a bit better. 2026-09-29 15:51:00 -07:00
me 11616841b3 gradle, upgrade to 9.8.0. 2026-09-29 15:50:34 -07:00
me 085031bc26 gradle, add task to print variables. 2026-09-29 15:49:49 -07:00
me 05f1b68d3f Add root certificate for Let's Encrypt in order to access Open Meteo on older devices. 2026-09-29 13:31:25 -07:00
me 0bc20a6e08 config, add cert path to assets. 2026-09-29 13:30:42 -07:00
me a661cfabbb main, put more variables in the cache, load them directly into their vars rather than having intermediates. 2026-09-29 13:30:13 -07:00
me 0e481f13cc main, swap the switch with text rather than disabling, allows giving a better error message. 2026-09-29 13:29:24 -07:00
me 436c96285c main, fix cert issues on older versions of Android (before Let's Encrypt existed). 2026-09-29 13:24:02 -07:00
me dd9d15172c main, handle the time being invalid better. 2026-09-29 13:23:28 -07:00
me 42d4992b6b icon, fix notification icon, may have chosen trim last time. 2026-09-29 12:30:28 -07:00
me f20bd99da4 icon, add another accidentally deleted XML. 2026-09-29 12:30:08 -07:00
me 79578de1f7 icon, untrim and ensure they are PNG. 2026-09-29 11:57:23 -07:00
me 183634dee5 main, disable the slide switch if the time is missing, stop the alarm if the time is completely backed out. 2026-09-29 11:57:09 -07:00
me 2606116c62 manifest, allow internet access. 2026-09-29 10:55:27 -07:00
me 424176a529 Add launch background XML's back in, 2026-09-29 10:50:59 -07:00
me 13a00917f9 icon, remove the old versions which were lingering and install version 03. 2026-09-29 08:25:00 -07:00
me 76ef8a7131 icon, modify to be circular and add an inversed monochrome version. 2026-09-29 08:24:36 -07:00
me 8b466229e1 compile, exclude the v from the version number. 2026-09-28 11:05:29 -07:00
me b62eff80c9 Increment version. 2026-09-28 11:05:17 -07:00
me 07447a2ffe Merge pull request '1.0.0' (#2) from dev into main
Reviewed-on: #2
2026-09-28 10:50:01 -07:00
me 6627ab46e8 fdroid, add to email that the user came from sunset. 2026-09-28 10:48:55 -07:00
me 79d9da8285 compile, further enhance the script as well as add space-saving options and platform specific APKs. 2026-09-28 10:34:52 -07:00
me 03f9e2fa56 android, add release build rules which slightly help to reduce filesizes. 2026-09-28 10:30:13 -07:00
me 7ab13dd4de main, fix older versions of Android not being able to see bottom widgets when keyboard is open. 2026-09-28 09:07:22 -07:00
me f5e368a902 main, more UI/UX fixes and enhancements. 2026-09-28 09:02:10 -07:00
me 251e03db5b Update version to 1.0.0, feeling feature complete until doing sunrise too. 2026-09-28 08:36:38 -07:00
61 changed files with 436 additions and 238 deletions

No files matched your search

+45 -1
View File
@@ -40,10 +40,30 @@ android {
} }
buildTypes { buildTypes {
release { getByName("release") {
// TODO: Add your own signing config for the release build. // TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works. // Signing with the debug keys for now, so `flutter run --release` works.
signingConfig = signingConfigs.getByName("debug") signingConfig = signingConfigs.getByName("debug")
/// 20260928 - Without minifying.
/// Built build/app/outputs/flutter-apk/app-release.apk (54.3MB)
/// Built build/app/outputs/flutter-apk/app-armeabi-v7a-release.apk (17.2MB)
/// Built build/app/outputs/flutter-apk/app-arm64-v8a-release.apk (19.8MB)
/// Built build/app/outputs/flutter-apk/app-x86_64-release.apk (21.2MB)
isMinifyEnabled = true
isShrinkResources = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
/// 20260928 - With minifying, helped some, but also used
/// in combination with `--obfuscate --split-debug-info=./debug-info/`
/// Built build/app/outputs/flutter-apk/app-release.apk (54.3MB)
/// Built build/app/outputs/flutter-apk/app-armeabi-v7a-release.apk (16.1MB)
/// Built build/app/outputs/flutter-apk/app-arm64-v8a-release.apk (18.8MB)
/// Built build/app/outputs/flutter-apk/app-x86_64-release.apk (20.3MB)
} }
} }
} }
@@ -55,3 +75,27 @@ dependencies {
flutter { flutter {
source = "../.." source = "../.."
} }
/// To use this, first be in $PROJ/android/, then run: ./gradlew printFlutterVariables
tasks.register("printFlutterVariables") {
description = "Print Local Flutter Variables"
doLast {
// android //
// compileSdk = flutter.compileSdkVersion
println("compileSdk: ${android.compileSdk}")
println("compileSdkVersion: ${android.compileSdkVersion}")
// ndkVersion = flutter.ndkVersion
println("ndkVersion: ${android.ndkVersion}")
// android.defaultConfig //
// minSdk = flutter.minSdkVersion
println("minSdk: ${android.defaultConfig.minSdk}")
// targetSdk = flutter.targetSdkVersion
println("targetSdk: ${android.defaultConfig.targetSdk}")
println("targetSdkVersion: ${android.defaultConfig.targetSdkVersion}")
// versionCode = flutter.versionCode
println("versionCode: ${android.defaultConfig.versionCode}")
// versionName = flutter.versionName
println("versionName: ${android.defaultConfig.versionName}")
}
}
View File
Whitespace-only changes.
+3
View File
@@ -27,6 +27,9 @@
<uses-permission android:name="android.permission.WAKE_LOCK"/> <uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM"/> <uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM"/>
<!-- Allow internet to work. -->
<uses-permission android:name="android.permission.INTERNET"/>
<application <application
android:label="Sunset Alarm" android:label="Sunset Alarm"
android:name="${applicationName}" android:name="${applicationName}"
Binary file not shown.

Before

Width:  |  Height:  |  Size: 216 B

After

Width:  |  Height:  |  Size: 431 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 173 B

After

Width:  |  Height:  |  Size: 306 B

@@ -10,3 +10,4 @@
android:src="@mipmap/launch_image" /> android:src="@mipmap/launch_image" />
</item> --> </item> -->
</layer-list> </layer-list>
Binary file not shown.

Before

Width:  |  Height:  |  Size: 284 B

After

Width:  |  Height:  |  Size: 574 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 443 B

After

Width:  |  Height:  |  Size: 842 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 565 B

After

Width:  |  Height:  |  Size: 1.2 KiB

@@ -10,3 +10,4 @@
android:src="@mipmap/launch_image" /> android:src="@mipmap/launch_image" />
</item> --> </item> -->
</layer-list> </layer-list>
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android"> <adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background"/> <background android:drawable="@color/ic_launcher_background"/>
<foreground android:drawable="@mipmap/ic_launcher_foreground"/> <foreground android:drawable="@mipmap/ic_launcher_foreground"/>
<monochrome android:drawable="@mipmap/ic_launcher_foreground"/> <monochrome android:drawable="@mipmap/ic_launcher_monochrome"/>
</adaptive-icon> </adaptive-icon>
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android"> <adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background"/> <background android:drawable="@color/ic_launcher_background"/>
<foreground android:drawable="@mipmap/ic_launcher_foreground"/> <foreground android:drawable="@mipmap/ic_launcher_foreground"/>
<monochrome android:drawable="@mipmap/ic_launcher_foreground"/> <monochrome android:drawable="@mipmap/ic_launcher_monochrome"/>
</adaptive-icon> </adaptive-icon>
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 816 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 456 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 626 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 334 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1022 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 586 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 946 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.8 KiB

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="ic_launcher_background">#FFFFFF</color>
</resources>
+1 -1
View File
@@ -1,7 +1,7 @@
#Sat Sep 12 19:36:23 MST 2026 #Sat Sep 12 19:36:23 MST 2026
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-9.7.1-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-9.8.0-bin.zip
#distributionUrl=https\://services.gradle.org/distributions/gradle-9.1.0-bin.zip #distributionUrl=https\://services.gradle.org/distributions/gradle-9.1.0-bin.zip
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
+1 -1
View File
@@ -1,5 +1,5 @@
AuthorName: 'Chad Michael "Hyperling" Greenwood' AuthorName: 'Chad Michael "Hyperling" Greenwood'
AuthorEmail: 'me@hyperling.com' AuthorEmail: 'me+sunset@hyperling.com'
AuthorWebSite: 'https://hyperling.com/about/' AuthorWebSite: 'https://hyperling.com/about/'
Donate: 'https://hyperling.com/donate/' Donate: 'https://hyperling.com/donate/'
Liberapay: 'HyperVegan' Liberapay: 'HyperVegan'
+50 -12
View File
@@ -15,6 +15,7 @@ function log {
function clean_flutter { function clean_flutter {
log "Cleaning..." log "Cleaning..."
flutter clean flutter clean
echo "Done!"
} }
## Variables ## ## Variables ##
@@ -31,7 +32,7 @@ version=""
for i in `grep version $app_details`; do for i in `grep version $app_details`; do
version="$i" version="$i"
done done
version="v${version// /_}" version="${version// /_}"
if [[ -z $name || -z $version ]]; then if [[ -z $name || -z $version ]]; then
echo "ERROR: Could not retrieve name or version. name='$name' version='$version'" echo "ERROR: Could not retrieve name or version. name='$name' version='$version'"
@@ -41,12 +42,23 @@ fi
RELEASE="release/$name-$version" RELEASE="release/$name-$version"
echo "Running for '$RELEASE'." echo "Running for '$RELEASE'."
BUILD_OPTIONS=(
--release
--obfuscate
--split-debug-info=./debug-info/
--extra-gen-snapshot-options="--strip"
)
## Main ## ## Main ##
clean_flutter clean_flutter
# Linux
log "Building Linux Bundle..." log "Building Linux Bundle..."
flutter build linux set -x
flutter build linux ${BUILD_OPTIONS[@]}
set +x
log "Saving Linux Bundle..." log "Saving Linux Bundle..."
filename=$RELEASE.linux-bundle.zip filename=$RELEASE.linux-bundle.zip
@@ -56,15 +68,41 @@ fi
zip -r $filename build/linux/x64/release/bundle/* zip -r $filename build/linux/x64/release/bundle/*
ls -sh $filename ls -sh $filename
clean_flutter # Android
log "Building APK..." log "Building Universal APK..."
flutter build apk # Creates a generic (and large) app-release.apk
set -x
flutter build apk ${BUILD_OPTIONS[@]}
set +x
log "Saving APK..." #log "Saving Universal APK..."
filename=$RELEASE.apk #apk="build/app/outputs/flutter-apk/app-release.apk"
if [[ -e $filename ]]; then #filename=`basename $apk`
rm -v $filename #filename=${filename//app/${RELEASE}}
fi #if [[ -e $filename ]]; then
cp -v build/app/outputs/flutter-apk/app-release.apk $filename # rm -v $filename
ls -sh $filename #fi
#cp -v "$apk" "$filename"
#ls -sh "$filename"
log "Building Individual APKs..."
# Creates files such as build/app/outputs/flutter-apk/app-arm64-v8a-release.apk
set -x
flutter build apk ${BUILD_OPTIONS[@]} --split-per-abi
set +x
log "Saving APKs..."
for apk in `ls build/app/outputs/flutter-apk/app*release.apk`; do
#if [[ "$apk" == *"x86"* ]]; then echo "Skipping $apk" continue; fi
#log "APK: $apk"
filename=`basename $apk`
filename=${filename//app/${RELEASE}}
cp -v "$apk" "$filename"
ls -sh "$filename"
echo " "
done
# Finish
exit 0
+3
View File
@@ -0,0 +1,3 @@
description: This file stores settings for Dart & Flutter DevTools.
documentation: https://docs.flutter.dev/tools/devtools/extensions#configure-extension-enablement-states
extensions:
+289 -218
View File
@@ -12,15 +12,31 @@ import 'package:alarm/alarm.dart';
import 'dart:convert'; import 'dart:convert';
// For trusting Let's Encrypt on older devices (SDK 24, Android 7)
//import 'dart:io';
//import 'package:http/http.dart' as http;
import 'package:flutter/services.dart' show rootBundle;
/// TBD: /// TBD:
/// v0.3.0 /// - Add other languages (Spanish, Croatian)
/// v1.1.0
/// - Move the switchtile back to its own row so that it handles titles better.
/// v1.2.0
/// - Change sunset grabber to checkbox and retrieve it each alarm or open. /// - Change sunset grabber to checkbox and retrieve it each alarm or open.
/// v1.0.0 /// v2.0.0
/// - Add sunrise section and change app name to Sunshine Alarm? /// - Add sunrise section and change app name to Sunshine Alarm?
/// :TBD /// :TBD
void main() async { void main() async {
WidgetsFlutterBinding.ensureInitialized(); WidgetsFlutterBinding.ensureInitialized();
final certData = await rootBundle.load(
'media/certs/open-meteo-com_isrg-root-x1.pem',
);
SecurityContext.defaultContext.setTrustedCertificatesBytes(
certData.buffer.asUint8List(),
);
tz.initializeTimeZones(); tz.initializeTimeZones();
await Alarm.init(); await Alarm.init();
runApp(const SunsetAlarmApp()); runApp(const SunsetAlarmApp());
@@ -65,18 +81,20 @@ class HomeScreen extends StatefulWidget {
class _HomeScreenState extends State<HomeScreen> { class _HomeScreenState extends State<HomeScreen> {
final _latController = TextEditingController(); final _latController = TextEditingController();
final _lngController = TextEditingController(); final _lngController = TextEditingController();
final _sunsetController = TextEditingController(); final _sunsetController = TextEditingController(text: "18:00");
final _minutesController = TextEditingController(text: '30'); final _minutesController = TextEditingController(text: "30");
final FlutterLocalNotificationsPlugin _notifications = final FlutterLocalNotificationsPlugin _notifications =
FlutterLocalNotificationsPlugin(); FlutterLocalNotificationsPlugin();
bool _loading = false;
bool _alarmEnabled = false; bool _alarmEnabled = false;
int _minutesBefore = 30; int _minutesBefore = 30;
bool _loading = false; String _plural = 's';
String? _sunsetErrorText = null; String? _sunsetErrorText;
String? _minuteErrorText = null; String? _minuteErrorText;
bool _validTime = false;
static const _alarmId = 1001; static const _alarmId = 1001;
@@ -105,15 +123,20 @@ class _HomeScreenState extends State<HomeScreen> {
Future<void> _loadPrefs() async { Future<void> _loadPrefs() async {
final prefs = await SharedPreferences.getInstance(); final prefs = await SharedPreferences.getInstance();
setState(() { setState(() {
final lat = prefs.getDouble('lat'); final lat = prefs.getDouble('lat').toString();
final lng = prefs.getDouble('lng'); final lng = prefs.getDouble('lng').toString();
final sunset = prefs.getString('sunset_time'); final sun = prefs.getString('sunset_time');
_alarmEnabled = prefs.getBool('alarm_enabled') ?? false; _latController.text = (lat == "null") ? "" : lat;
_lngController.text = (lng == "null") ? "" : lng;
_sunsetController.text = sun ?? "";
_minutesBefore = prefs.getInt('minutes_before') ?? 30; _minutesBefore = prefs.getInt('minutes_before') ?? 30;
if (lat != null) _latController.text = lat.toString(); _minutesController.text = _minutesBefore.toString();
if (lng != null) _lngController.text = lng.toString();
if (sunset != null) _sunsetController.text = sunset; _alarmEnabled = prefs.getBool('alarm_enabled') ?? false;
_minutesController.text = '$_minutesBefore'; _validTime = prefs.getBool('valid_time') ?? false;
_calcPlural();
}); });
if (_alarmEnabled && _sunsetController.text.isNotEmpty) { if (_alarmEnabled && _sunsetController.text.isNotEmpty) {
_scheduleAlarm(); _scheduleAlarm();
@@ -131,6 +154,7 @@ class _HomeScreenState extends State<HomeScreen> {
} }
await prefs.setBool('alarm_enabled', _alarmEnabled); await prefs.setBool('alarm_enabled', _alarmEnabled);
await prefs.setInt('minutes_before', _minutesBefore); await prefs.setInt('minutes_before', _minutesBefore);
await prefs.setBool('valid_time', _validTime);
} }
Future<void> _getGpsLocation() async { Future<void> _getGpsLocation() async {
@@ -191,7 +215,10 @@ class _HomeScreenState extends State<HomeScreen> {
} catch (e) { } catch (e) {
_showSnack('Network Error: $e'); _showSnack('Network Error: $e');
} finally { } finally {
setState(() => _loading = false); setState(() {
_loading = false;
_validTime = true;
});
} }
if (_alarmEnabled) { if (_alarmEnabled) {
@@ -202,21 +229,6 @@ 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();
if (canSchedule != true) {
_showSnack('Permissions Need Granted, Requesting...');
await android?.requestExactAlarmsPermission();
}
final sunsetText = _sunsetController.text.trim(); final sunsetText = _sunsetController.text.trim();
if (sunsetText.isEmpty) return; if (sunsetText.isEmpty) return;
@@ -259,7 +271,21 @@ 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 ***/ // 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();
if (canSchedule != true) {
_showSnack('Permissions Need Granted, Requesting...');
await android?.requestExactAlarmsPermission();
}
/*** Notification Method - Works ***/
if (ANDROID_USE_NOTIF) { 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);
@@ -289,7 +315,7 @@ class _HomeScreenState extends State<HomeScreen> {
} }
// End Notification Method ***/ // End Notification Method ***/
/*** Alarm Method - WIP ***/ /*** Alarm Method - Works ***/
if (ANDROID_USE_ALARM) { if (ANDROID_USE_ALARM) {
// Schedule: // Schedule:
final settings = AlarmSettings( final settings = AlarmSettings(
@@ -305,7 +331,7 @@ class _HomeScreenState extends State<HomeScreen> {
), ),
notificationSettings: NotificationSettings( notificationSettings: NotificationSettings(
title: 'Sunset Alarm', title: 'Sunset Alarm',
body: 'Sun is setting in ${_minutesBefore} minute(s)!', body: 'Sun is setting in ${_minutesBefore} minute${_plural}!',
stopButton: 'Dismiss', stopButton: 'Dismiss',
icon: 'ic_notification', icon: 'ic_notification',
), ),
@@ -325,24 +351,33 @@ class _HomeScreenState extends State<HomeScreen> {
if (value) { if (value) {
await _scheduleAlarm(); await _scheduleAlarm();
} else { } else {
_alarmTimer?.cancel(); _stopAlarm();
if (!Platform.isLinux) {
// Notification Method
if (ANDROID_USE_NOTIF) await _notifications.cancel(id: _alarmId);
// Alarm Method
if (ANDROID_USE_ALARM) await Alarm.stop(_alarmId);
}
_showSnack('Alarm Cancelled');
} }
} }
Future<void> _stopAlarm() async {
if (Platform.isLinux) {
_alarmTimer?.cancel();
} else if (Platform.isAndroid) {
// Notification Method
if (ANDROID_USE_NOTIF) {
await _notifications.cancel(id: _alarmId);
}
// Alarm Method
if (ANDROID_USE_ALARM) {
await Alarm.stop(_alarmId);
}
}
_showSnack('Alarm Cancelled');
}
void _showSnack(String msg) { void _showSnack(String msg) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(msg))); ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(msg)));
} }
@override @override
void dispose() { void dispose() {
_savePrefs();
_latController.dispose(); _latController.dispose();
_lngController.dispose(); _lngController.dispose();
_sunsetController.dispose(); _sunsetController.dispose();
@@ -351,6 +386,9 @@ class _HomeScreenState extends State<HomeScreen> {
} }
String? _validateTime(String? value) { String? _validateTime(String? value) {
setState(() {
_validTime = false;
});
if (value == null || !RegExp(r'^\d{2}:\d{2}$').hasMatch(value)) { if (value == null || !RegExp(r'^\d{2}:\d{2}$').hasMatch(value)) {
return 'Use HH:MM Format'; return 'Use HH:MM Format';
} }
@@ -358,189 +396,224 @@ class _HomeScreenState extends State<HomeScreen> {
final m = int.parse(value.substring(3, 5)); final m = int.parse(value.substring(3, 5));
if (h > 23) return 'Hour Must Be 0–23'; if (h > 23) return 'Hour Must Be 0–23';
if (m > 59) return 'Minute Must Be 0–59'; if (m > 59) return 'Minute Must Be 0–59';
setState(() {
_validTime = true;
});
return null; // valid return null; // valid
} }
void _calcPlural() {
setState(() {
_plural = (_minutesBefore == 1) ? '' : 's';
});
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
appBar: AppBar(title: const Text('Sunset Alarm')), appBar: AppBar(title: const Text('Sunset Alarm')),
body: Padding( resizeToAvoidBottomInset: true, // default, but be explicit
padding: const EdgeInsets.all(16), body: SingleChildScrollView(
child: Column( child: Padding(
crossAxisAlignment: CrossAxisAlignment.start, padding: const EdgeInsets.all(16),
children: [ child: Column(
// --- Location section --- crossAxisAlignment: CrossAxisAlignment.start,
const Text( children: [
'Location', // --- Location section ---
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold), const Text(
), 'Location',
const SizedBox(height: 8), style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
Row( ),
children: [ const SizedBox(height: 8),
Expanded( Row(
child: TextField( children: [
controller: _latController,
keyboardType: const TextInputType.numberWithOptions(
signed: true,
decimal: true,
),
decoration: const InputDecoration(
labelText: 'Latitude',
border: OutlineInputBorder(),
),
onChanged: (_) => _savePrefs(),
),
),
const SizedBox(width: 8),
Expanded(
child: TextField(
controller: _lngController,
keyboardType: const TextInputType.numberWithOptions(
signed: true,
decimal: true,
),
decoration: const InputDecoration(
labelText: 'Longitude',
border: OutlineInputBorder(),
),
onChanged: (_) => _savePrefs(),
),
),
const SizedBox(width: 8),
IconButton.filledTonal(
icon: const Icon(Icons.my_location),
tooltip: 'Get GPS Location',
onPressed: _getGpsLocation,
),
],
),
const SizedBox(height: 16),
// --- Sunset time section ---
const Text(
'Sunset',
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
const SizedBox(height: 8),
Row(
children: [
Expanded(
child: TextField(
controller: _sunsetController,
decoration: InputDecoration(
labelText: 'Sunset Time (HH:MM)',
border: OutlineInputBorder(),
errorText: _sunsetErrorText,
suffixIcon: IconButton(
icon: Icon(Icons.access_time),
onPressed: () async {
final picked = await showTimePicker(
context: context,
initialTime: TimeOfDay.now(),
);
if (picked != null) {
_sunsetController.text =
'${picked.hour.toString().padLeft(2, '0')}:'
'${picked.minute.toString().padLeft(2, '0')}';
setState(
() =>
_sunsetErrorText = _validateTime(
_sunsetController.text,
),
);
if (_alarmEnabled) {
_scheduleAlarm();
}
}
},
),
),
onChanged: (v) {
final val = _validateTime(v);
if (val == null) {
_savePrefs();
if (_alarmEnabled) {
_scheduleAlarm();
}
}
setState(() {
_sunsetErrorText = val;
});
},
),
),
const SizedBox(width: 8),
IconButton.filledTonal(
icon:
_loading
? const SizedBox(
width: 20,
height: 20,
child: CircularProgressIndicator(strokeWidth: 2),
)
: const Icon(Icons.cloud_done_outlined),
tooltip: 'Fetch Open-Meteo Sunset Data',
onPressed: () {
if (!_loading) {
_fetchSunset();
}
},
),
],
),
const SizedBox(height: 16),
const Text(
'Alert',
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
const SizedBox(height: 8),
// --- Minutes before ---
Row(
children: [
if (!_alarmEnabled)
Expanded( Expanded(
child: TextField( child: TextField(
controller: _minutesController, controller: _latController,
keyboardType: TextInputType.number, keyboardType: const TextInputType.numberWithOptions(
decoration: InputDecoration( signed: true,
decimal: true,
),
decoration: const InputDecoration(
labelText: 'Latitude',
border: OutlineInputBorder(), border: OutlineInputBorder(),
labelText: 'Minutes Before Sunset', ),
errorText: _minuteErrorText, onChanged: (_) => _savePrefs(),
),
),
const SizedBox(width: 8),
Expanded(
child: TextField(
controller: _lngController,
keyboardType: const TextInputType.numberWithOptions(
signed: true,
decimal: true,
),
decoration: const InputDecoration(
labelText: 'Longitude',
border: OutlineInputBorder(),
),
onChanged: (_) => _savePrefs(),
),
),
const SizedBox(width: 8),
IconButton.filledTonal(
icon: const Icon(Icons.my_location),
tooltip: 'Get GPS Location',
onPressed: _getGpsLocation,
),
],
),
const SizedBox(height: 16),
// --- Sunset time section ---
const Text(
'Sunset',
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
const SizedBox(height: 8),
Row(
children: [
Expanded(
child: TextField(
controller: _sunsetController,
decoration: InputDecoration(
labelText: 'Sunset Time (HH:MM)',
border: OutlineInputBorder(),
errorText: _sunsetErrorText,
suffixIcon: IconButton(
icon: Icon(Icons.access_time),
onPressed: () async {
final picked = await showTimePicker(
context: context,
initialTime: TimeOfDay.now(),
);
if (picked != null) {
_sunsetController.text =
'${picked.hour.toString().padLeft(2, '0')}:'
'${picked.minute.toString().padLeft(2, '0')}';
setState(
() => _sunsetErrorText = _validateTime(
_sunsetController.text,
),
);
if (_alarmEnabled) {
_scheduleAlarm();
}
}
},
),
), ),
onChanged: (v) { onChanged: (v) {
final val = int.tryParse(v); if (v == "") {
setState(() { _stopAlarm();
if (val != null) { }
_minuteErrorText = null; final val = _validateTime(v);
_minutesBefore = val; if (val == null) {
} else { _savePrefs();
_minuteErrorText = 'Invalid Minute Value'; if (_alarmEnabled) {
_scheduleAlarm();
} }
}
setState(() {
_sunsetErrorText = val;
}); });
}, },
), ),
), ),
const SizedBox(width: 8),
// --- Toggle --- IconButton.filledTonal(
Expanded( icon: _loading
child: SwitchListTile( ? const SizedBox(
//title: const Text('Enable Sunset Alarm'), width: 20,
title: Text(_alarmEnabled ? 'Sunset Alarm Enabled' : ''), height: 20,
subtitle: Text( child: CircularProgressIndicator(strokeWidth: 2),
_alarmEnabled )
? 'Will alert ${_minutesBefore} min before sunset. ($_alarmDisplayTime)' : const Icon(Icons.cloud_done_outlined),
: '', tooltip: 'Fetch Open-Meteo Sunset Data',
), onPressed: () {
value: _alarmEnabled, if (!_loading) {
onChanged: _toggleAlarm, _fetchSunset();
}
},
), ),
), ],
], ),
), const SizedBox(height: 16),
],
const Text(
'Alert',
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
const SizedBox(height: 8),
// --- Minutes before ---
Row(
children: [
if (!_alarmEnabled)
Expanded(
flex: 1, // _validTime ? 3 : 2,
child: TextField(
controller: _minutesController,
keyboardType: TextInputType.number,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Minutes Before Sunset',
errorText: _minuteErrorText,
),
onChanged: (v) {
final val = int.tryParse(v);
setState(() {
if (val != null) {
_minuteErrorText = null;
_minutesBefore = val;
} else {
_minuteErrorText = 'Invalid Minute Value';
}
_calcPlural();
});
},
),
),
//Expanded(
// flex: 3,
// child: Center(
// child:
// _validTime ? Text("") : Text("Sunset Time Needed") ,
// ),
//),
// --- Toggle ---
Expanded(
flex: 1, //_validTime ? 2 : 5,
child: SwitchListTile(
title: Center(
child: Text(
_validTime
? _alarmEnabled
? "Sunset Alarm Enabled"
: "" //"Enable"
: "", // "Disabled",
),
),
subtitle: Center(
child: Text(
_validTime
? _alarmEnabled
? "${_minutesBefore} Minute${_plural} Before @ $_alarmDisplayTime"
: "" //"Sunset Alarm"
: "", //"Enter Valid Time",
),
),
value: _validTime ? _alarmEnabled : false,
onChanged: _validTime ? _toggleAlarm : null,
),
),
],
),
],
),
), ),
), ),
); );
@@ -566,11 +639,10 @@ final _plugin = FlutterLocalNotificationsPlugin();
Future<void> requestPermissions() async { Future<void> requestPermissions() async {
if (Platform.isAndroid) { if (Platform.isAndroid) {
final android = final android = _plugin
_plugin .resolvePlatformSpecificImplementation<
.resolvePlatformSpecificImplementation< AndroidFlutterLocalNotificationsPlugin
AndroidFlutterLocalNotificationsPlugin >();
>();
// Android 13+ — standard notification permission (shows a dialog) // Android 13+ — standard notification permission (shows a dialog)
await android?.requestNotificationsPermission(); await android?.requestNotificationsPermission();
@@ -580,8 +652,7 @@ Future<void> requestPermissions() async {
} }
} }
final android = final android = _plugin
_plugin .resolvePlatformSpecificImplementation<
.resolvePlatformSpecificImplementation< AndroidFlutterLocalNotificationsPlugin
AndroidFlutterLocalNotificationsPlugin >();
>();
@@ -0,0 +1,31 @@
-----BEGIN CERTIFICATE-----
MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw
TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh
cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4
WhcNMzUwNjA0MTEwNDM4WjBPMQswCQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJu
ZXQgU2VjdXJpdHkgUmVzZWFyY2ggR3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdCBY
MTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAK3oJHP0FDfzm54rVygc
h77ct984kIxuPOZXoHj3dcKi/vVqbvYATyjb3miGbESTtrFj/RQSa78f0uoxmyF+
0TM8ukj13Xnfs7j/EvEhmkvBioZxaUpmZmyPfjxwv60pIgbz5MDmgK7iS4+3mX6U
A5/TR5d8mUgjU+g4rk8Kb4Mu0UlXjIB0ttov0DiNewNwIRt18jA8+o+u3dpjq+sW
T8KOEUt+zwvo/7V3LvSye0rgTBIlDHCNAymg4VMk7BPZ7hm/ELNKjD+Jo2FR3qyH
B5T0Y3HsLuJvW5iB4YlcNHlsdu87kGJ55tukmi8mxdAQ4Q7e2RCOFvu396j3x+UC
B5iPNgiV5+I3lg02dZ77DnKxHZu8A/lJBdiB3QW0KtZB6awBdpUKD9jf1b0SHzUv
KBds0pjBqAlkd25HN7rOrFleaJ1/ctaJxQZBKT5ZPt0m9STJEadao0xAH0ahmbWn
OlFuhjuefXKnEgV4We0+UXgVCwOPjdAvBbI+e0ocS3MFEvzG6uBQE3xDk3SzynTn
jh8BCNAw1FtxNrQHusEwMFxIt4I7mKZ9YIqioymCzLq9gwQbooMDQaHWBfEbwrbw
qHyGO0aoSCqI3Haadr8faqU9GY/rOPNk3sgrDQoo//fb4hVC1CLQJ13hef4Y53CI
rU7m2Ys6xt0nUW7/vGT1M0NPAgMBAAGjQjBAMA4GA1UdDwEB/wQEAwIBBjAPBgNV
HRMBAf8EBTADAQH/MB0GA1UdDgQWBBR5tFnme7bl5AFzgAiIyBpY9umbbjANBgkq
hkiG9w0BAQsFAAOCAgEAVR9YqbyyqFDQDLHYGmkgJykIrGF1XIpu+ILlaS/V9lZL
ubhzEFnTIZd+50xx+7LSYK05qAvqFyFWhfFQDlnrzuBZ6brJFe+GnY+EgPbk6ZGQ
3BebYhtF8GaV0nxvwuo77x/Py9auJ/GpsMiu/X1+mvoiBOv/2X/qkSsisRcOj/KK
NFtY2PwByVS5uCbMiogziUwthDyC3+6WVwW6LLv3xLfHTjuCvjHIInNzktHCgKQ5
ORAzI4JMPJ+GslWYHb4phowim57iaztXOoJwTdwJx4nLCgdNbOhdjsnvzqvHu7Ur
TkXWStAmzOVyyghqpZXjFaH3pO3JLF+l+/+sKAIuvtd7u+Nxe5AW0wdeRlN8NwdC
jNPElpzVmbUq4JUagEiuTDkHzsxHpFKVK7q4+63SM1N95R1NbdWhscdCb+ZAJzVc
oyi3B43njTOQ5yOf+1CceWxG1bQVs5ZufpsMljq4Ui0/1lvh+wjChP4kqKOJ2qxq
4RgqsahDYVvTH9w7jXbyLeiNdd8XM2w9U/t7y0Ff/9yi0GE44Za4rF2LN9d11TPA
mRGunUHBcnWEvgJBQl9nJEiU0Zsnvgc/ubhPgXRR4Xq37Z0j4r7g1SgEEzwxA57d
emyPxgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc=
-----END CERTIFICATE-----
Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.
+3 -1
View File
@@ -1,7 +1,7 @@
name: sunset_alarm name: sunset_alarm
description: "Set an alarm to go off a specified time before sunset." description: "Set an alarm to go off a specified time before sunset."
publish_to: 'none' publish_to: 'none'
version: 0.2.0 version: 1.0.1
environment: environment:
sdk: ^3.7.2 sdk: ^3.7.2
@@ -23,3 +23,5 @@ dev_dependencies:
flutter: flutter:
uses-material-design: true uses-material-design: true
assets:
- media/certs/