27 Commits
Author SHA1 Message Date
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
me 3f0b69d6cf android, import icon version 2 and its monochrome notification counterpart. 2026-09-28 08:32:07 -07:00
me dc97081517 Add updated icon media. Sun is smaller and exactly centered. Version mc is monochrome. 2026-09-28 08:30:50 -07:00
me 8167c748ff main, continue ensuring actual alarm gets changed if sunset time is changed, add reference to notification icon. 2026-09-28 08:27:45 -07:00
me 4926c869b9 main, use global variables for now to decide between notifications and alarms on Android, may become a setting later. 2026-09-28 07:58:15 -07:00
me 7f908a7fab main, change toast phrasing to be consistent. 2026-09-28 07:52:56 -07:00
me 65ce0f8135 main, ensure the alarm time gets changed if modified when already enabled. 2026-09-28 07:44:18 -07:00
me 75b0a6b875 main, check for and use system theme properly. 2026-09-28 07:43:38 -07:00
me aed58f56dc main, add optional timepicker for sunset. 2026-09-28 07:06:43 -07:00
me db94f3bea1 main, add validation for sunset time field. 2026-09-28 06:59:22 -07:00
me 39792270f1 main, change layout so that minutes cannot be modified while the alarm is enabled, also handle validation better. 2026-09-28 06:48:40 -07:00
me 77320b05d6 main, change comments and UI text. 2026-09-28 06:47:53 -07:00
me 4788cdd220 main, attempt to cancel future alarms when untoggled. 2026-09-28 06:45:47 -07:00
me 0659262e61 main, add TBD's. 2026-09-28 06:44:22 -07:00
me 287c2f0cd0 main, use the default user volume. 2026-09-28 05:34:45 -07:00
me b4f8f37c79 android, change manifest label to be human friendly. 2026-09-28 05:30:58 -07:00
me b4acaa308d main, alarm is now successfully working on Android! 2026-09-28 05:14:34 -07:00
me 14372df628 android, re-enable manifest alarm code. 2026-09-28 05:00:02 -07:00
me c32373173b main, re-enable alarm code. 2026-09-28 04:59:46 -07:00
me 64a070fb4e Update version. 2026-09-28 04:56:47 -07:00
me bb1118d071 Add yml file for F-Droid repo. 2026-09-28 04:56:19 -07:00
32 changed files with 396 additions and 219 deletions

No files matched your search

+23 -1
View File
@@ -15,6 +15,8 @@ android {
compileSdk = flutter.compileSdkVersion
ndkVersion = flutter.ndkVersion
compileOptions {
isCoreLibraryDesugaringEnabled = true
targetCompatibility = JavaVersion.VERSION_17
@@ -40,10 +42,30 @@ android {
}
buildTypes {
release {
getByName("release") {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
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)
}
}
}
View File
Whitespace-only changes.
+6 -8
View File
@@ -3,13 +3,14 @@
xmlns:tools="http://schemas.android.com/tools"
>
<!-- Allow notifications to work. -->
<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"/>
<!--
<!-- Allow alarms to work. -->
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.VIBRATE"/>
@@ -25,10 +26,9 @@
<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
android:label="sunset_alarm"
android:label="Sunset Alarm"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">
<activity
@@ -59,6 +59,7 @@
android:name="flutterEmbedding"
android:value="2" />
<!-- Allow notifications to work. -->
<receiver
android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationReceiver"
android:enabled="true" />
@@ -74,16 +75,14 @@
</intent-filter>
</receiver>
<!--
<!-- Allow alarms to work. -->
<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"
@@ -92,7 +91,6 @@
<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"
@@ -111,7 +109,7 @@
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
-->
</application>
<!-- Required to query activities that can process text, see:
https://developer.android.com/training/package-visibility and
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

+16
View File
@@ -0,0 +1,16 @@
AuthorName: 'Chad Michael "Hyperling" Greenwood'
AuthorEmail: 'me+sunset@hyperling.com'
AuthorWebSite: 'https://hyperling.com/about/'
Donate: 'https://hyperling.com/donate/'
Liberapay: 'HyperVegan'
Bitcoin: 'bc1qsfe8dkvry3d34kztz449gkq67wq8fu2nkgfkh0'
Litecoin: 'ltc1qavmpu5d6ljntxsd6jj548m4yys83zwscl0dzkx'
IssueTracker: 'https://hyperling.com/contact/'
Categories:
- fdroid
- hyperling
- utilities
Name: Sunset Timer
Summary: 'Play a notification at your chosen time before sunset.'
SourceCode: 'https://git.hyperling.com/me/flutter-sunset-alarm/'
WebSite: 'https://hyperling.com/apps/#sunset'
+49 -11
View File
@@ -15,6 +15,7 @@ function log {
function clean_flutter {
log "Cleaning..."
flutter clean
echo "Done!"
}
## Variables ##
@@ -41,12 +42,23 @@ fi
RELEASE="release/$name-$version"
echo "Running for '$RELEASE'."
BUILD_OPTIONS=(
--release
--obfuscate
--split-debug-info=./debug-info/
--extra-gen-snapshot-options="--strip"
)
## Main ##
clean_flutter
# Linux
log "Building Linux Bundle..."
flutter build linux
set -x
flutter build linux ${BUILD_OPTIONS[@]}
set +x
log "Saving Linux Bundle..."
filename=$RELEASE.linux-bundle.zip
@@ -56,15 +68,41 @@ fi
zip -r $filename build/linux/x64/release/bundle/*
ls -sh $filename
clean_flutter
# Android
log "Building APK..."
flutter build apk
log "Building Universal APK..."
# Creates a generic (and large) app-release.apk
set -x
flutter build apk ${BUILD_OPTIONS[@]}
set +x
log "Saving APK..."
filename=$RELEASE.apk
if [[ -e $filename ]]; then
rm -v $filename
fi
cp -v build/app/outputs/flutter-apk/app-release.apk $filename
ls -sh $filename
#log "Saving Universal APK..."
#apk="build/app/outputs/flutter-apk/app-release.apk"
#filename=`basename $apk`
#filename=${filename//app/${RELEASE}}
#if [[ -e $filename ]]; then
# rm -v $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
+301 -198
View File
@@ -8,28 +8,49 @@ 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 'package:alarm/alarm.dart';
import 'dart:convert';
/// TBD:
/// - Add other languages (Spanish, Croatian)
/// v1.1.0
/// - Change sunset grabber to checkbox and retrieve it each alarm or open.
/// v2.0.0
/// - Add sunrise section and change app name to Sunshine Alarm?
/// :TBD
void main() async {
WidgetsFlutterBinding.ensureInitialized();
tz.initializeTimeZones();
//await Alarm.init();
await Alarm.init();
runApp(const SunsetAlarmApp());
}
const ANDROID_USE_NOTIF = false;
const ANDROID_USE_ALARM = !ANDROID_USE_NOTIF;
class SunsetAlarmApp extends StatelessWidget {
const SunsetAlarmApp({super.key});
@override
Widget build(BuildContext context) {
const seedColor = Colors.deepOrange;
return MaterialApp(
title: 'Sunset Alarm',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepOrange),
useMaterial3: true,
colorScheme: ColorScheme.fromSeed(
seedColor: seedColor,
brightness: Brightness.light,
),
),
darkTheme: ThemeData(
colorScheme: ColorScheme.fromSeed(
seedColor: seedColor,
brightness: Brightness.dark,
),
),
themeMode: ThemeMode.system,
home: const HomeScreen(),
);
}
@@ -51,9 +72,13 @@ class _HomeScreenState extends State<HomeScreen> {
final FlutterLocalNotificationsPlugin _notifications =
FlutterLocalNotificationsPlugin();
bool _loading = false;
bool _alarmEnabled = false;
int _minutesBefore = 30;
bool _loading = false;
String _plural = 's';
String? _sunsetErrorText;
String? _minuteErrorText;
static const _alarmId = 1001;
@@ -114,14 +139,14 @@ class _HomeScreenState extends State<HomeScreen> {
try {
bool serviceEnabled = await Geolocator.isLocationServiceEnabled();
if (!serviceEnabled) {
_showSnack('Location services are disabled.');
_showSnack('Location Services Disabled');
return;
}
LocationPermission permission = await Geolocator.checkPermission();
if (permission == LocationPermission.denied) {
permission = await Geolocator.requestPermission();
if (permission == LocationPermission.denied) {
_showSnack('Location permission denied.');
_showSnack('Location Permission Denied');
return;
}
}
@@ -133,9 +158,9 @@ class _HomeScreenState extends State<HomeScreen> {
_lngController.text = position.longitude.toString();
});
await _savePrefs();
_showSnack('Location updated.');
_showSnack('Location Updated.');
} catch (e) {
_showSnack('GPS error: $e');
_showSnack('GPS Error: $e');
}
}
@@ -143,7 +168,7 @@ class _HomeScreenState extends State<HomeScreen> {
final lat = double.tryParse(_latController.text);
final lng = double.tryParse(_lngController.text);
if (lat == null || lng == null) {
_showSnack('Enter valid latitude and longitude first.');
_showSnack('Enter Valid Latitude & Longitude');
return;
}
@@ -161,35 +186,24 @@ class _HomeScreenState extends State<HomeScreen> {
final timePart = sunsetStr.split('T')[1];
setState(() => _sunsetController.text = timePart);
await _savePrefs();
_showSnack('Sunset: $timePart');
_showSnack('Sunset Time Retrieved: $timePart');
} else {
_showSnack('API error: ${response.statusCode}');
_showSnack('API Error: ${response.statusCode}');
}
} catch (e) {
_showSnack('Network error: $e');
_showSnack('Network Error: $e');
} finally {
setState(() => _loading = false);
}
if (_alarmEnabled) {
_scheduleAlarm();
}
}
Timer? _alarmTimer;
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 not yet granted, requesting...');
await android?.requestExactAlarmsPermission();
}
final sunsetText = _sunsetController.text.trim();
if (sunsetText.isEmpty) return;
@@ -207,7 +221,7 @@ class _HomeScreenState extends State<HomeScreen> {
alarmTime = alarmTime.subtract(Duration(minutes: _minutesBefore));
if (alarmTime.isBefore(now)) {
_showSnack('Alarm time is in the past. Will fire tomorrow.');
_showSnack('Alarm Time In Past - Will Start Tomorrow');
alarmTime = alarmTime.add(const Duration(days: 1));
}
@@ -223,64 +237,87 @@ class _HomeScreenState extends State<HomeScreen> {
);
_notifications.show(
id: _alarmId,
title: 'Sunset in ${_minutesBefore} min',
body: 'The sun sets at $sunsetText. Time to get ready!',
title: 'Sunset in ${_minutesBefore} min!',
body: 'The sun sets at $sunsetText.',
notificationDetails: const NotificationDetails(linux: linuxDetails),
);
});
_showSnack(
'Alarm set for ${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) {
/*** Notifcation Method - Works ***/
// Android: use zonedSchedule (works in background)
final tzAlarm = tz.TZDateTime.from(alarmTime, tz.local);
const androidDetails = AndroidNotificationDetails(
'sunset_alarm',
'Sunset Alarm',
channelDescription: 'Alarm X minutes before sunset',
importance: Importance.max,
priority: Priority.high,
fullScreenIntent: true,
category: AndroidNotificationCategory.alarm,
);
await _notifications.zonedSchedule(
id: _alarmId,
title: 'Sunset in ${_minutesBefore} min',
body: 'The sun sets at $sunsetText. Time to get ready!',
scheduledDate: tzAlarm,
notificationDetails: const NotificationDetails(android: androidDetails),
androidScheduleMode: AndroidScheduleMode.alarmClock,
);
_showSnack('Alarm scheduled!');
debugPrint('DEBUG: Alarm time: ${tzAlarm.toString()}');
debugPrint('DEBUG: Current time: ${DateTime.now().toUtc().toString()}');
debugPrint('DEBUG: ${_notifications.toString()}');
// 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) {
// Android: use zonedSchedule (works in background)
final tzAlarm = tz.TZDateTime.from(alarmTime, tz.local);
const androidDetails = AndroidNotificationDetails(
'sunset_alarm',
'Sunset Alarm',
channelDescription: 'Alarm X minutes before sunset',
importance: Importance.max,
priority: Priority.high,
fullScreenIntent: true,
category: AndroidNotificationCategory.alarm,
);
await _notifications.zonedSchedule(
id: _alarmId,
title: 'Sunset in ${_minutesBefore} min',
body: 'The sun sets at $sunsetText. Time to get ready!',
scheduledDate: tzAlarm,
notificationDetails: const NotificationDetails(
android: androidDetails,
),
androidScheduleMode: AndroidScheduleMode.alarmClock,
);
_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);
/*** Alarm Method - Works ***/
if (ANDROID_USE_ALARM) {
// Schedule:
final settings = AlarmSettings(
id: _alarmId,
dateTime: alarmTime,
//assetAudioPath: 'assets/alarm.mp3', // use default rather than custom
loopAudio: true, // keeps ringing until dismissed
vibrate: true,
androidFullScreenIntent: true, // wakes screen like clock app
volumeSettings: VolumeSettings.fade(
//volume: 0.8, // use default rather than custom
fadeDuration: Duration(seconds: 60),
),
notificationSettings: NotificationSettings(
title: 'Sunset Alarm',
body: 'Sun is setting in ${_minutesBefore} minute${_plural}!',
stopButton: 'Dismiss',
icon: 'ic_notification',
),
);
await Alarm.set(alarmSettings: settings);
}
// End Alarm Method ***/
_showSnack('Alarm Scheduled @ ${alarmTime}');
} else {
_showSnack('Platform not detected, unsure how to show alarm.');
_showSnack('Platform Not Detected - Contact Developer');
}
}
@@ -292,9 +329,13 @@ class _HomeScreenState extends State<HomeScreen> {
} else {
_alarmTimer?.cancel();
if (!Platform.isLinux) {
await _notifications.cancel(id: _alarmId);
// Notification Method
if (ANDROID_USE_NOTIF) await _notifications.cancel(id: _alarmId);
// Alarm Method
if (ANDROID_USE_ALARM) await Alarm.stop(_alarmId);
}
_showSnack('Alarm cancelled.');
_showSnack('Alarm Cancelled');
}
}
@@ -304,6 +345,7 @@ class _HomeScreenState extends State<HomeScreen> {
@override
void dispose() {
_savePrefs();
_latController.dispose();
_lngController.dispose();
_sunsetController.dispose();
@@ -311,140 +353,201 @@ class _HomeScreenState extends State<HomeScreen> {
super.dispose();
}
String? _validateTime(String? value) {
if (value == null || !RegExp(r'^\d{2}:\d{2}$').hasMatch(value)) {
return 'Use HH:MM Format';
}
final h = int.parse(value.substring(0, 2));
final m = int.parse(value.substring(3, 5));
if (h > 23) return 'Hour Must Be 0–23';
if (m > 59) return 'Minute Must Be 0–59';
return null; // valid
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Sunset Alarm')),
body: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// --- Location section ---
const Text(
'Location',
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
const SizedBox(height: 8),
Row(
children: [
Expanded(
child: TextField(
controller: _latController,
keyboardType: const TextInputType.numberWithOptions(
signed: true,
decimal: true,
resizeToAvoidBottomInset: true, // default, but be explicit
body: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// --- Location section ---
const Text(
'Location',
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
const SizedBox(height: 8),
Row(
children: [
Expanded(
child: TextField(
controller: _latController,
keyboardType: const TextInputType.numberWithOptions(
signed: true,
decimal: true,
),
decoration: const InputDecoration(
labelText: 'Latitude',
border: OutlineInputBorder(),
),
onChanged: (_) => _savePrefs(),
),
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,
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(),
),
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),
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: const InputDecoration(
labelText: 'Sunset time (HH:MM)',
border: OutlineInputBorder(),
// --- 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;
});
},
),
onChanged: (_) => _savePrefs(),
),
),
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 sunset from Open-Meteo',
onPressed: _loading ? null : _fetchSunset,
),
],
),
const SizedBox(height: 16),
// --- Minutes before ---
const Text(
'Alert Before Sunset',
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
const SizedBox(height: 8),
Row(
children: [
const Text('Minutes before: '),
SizedBox(
width: 80,
child: TextField(
controller: _minutesController,
keyboardType: TextInputType.number,
decoration: const InputDecoration(
border: OutlineInputBorder(),
),
onChanged: (v) {
final val = int.tryParse(v);
if (val != null && val >= 0) {
_minutesBefore = val;
} else {
_showSnack('Invalid Minute Value');
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: 24),
// --- Toggle ---
SwitchListTile(
title: const Text('Enable Sunset Alarm'),
subtitle: Text(
_alarmEnabled
? 'Will alert ${_minutesBefore} min before sunset. ($_alarmDisplayTime)'
: 'Alarm is off',
],
),
value: _alarmEnabled,
onChanged: _toggleAlarm,
),
],
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(
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';
}
_plural = (_minutesBefore == 1) ? '' : 's';
});
},
),
),
// --- Toggle ---
Expanded(
child: SwitchListTile(
//title: const Text('Enable Sunset Alarm'),
title: Text(_alarmEnabled ? 'Sunset Alarm Enabled' : ''),
subtitle: Text(
_alarmEnabled
? '${_minutesBefore} Minute${_plural} Before @ $_alarmDisplayTime'
: '',
),
value: _alarmEnabled,
onChanged: _toggleAlarm,
),
),
],
),
],
),
),
),
);
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.
+1 -1
View File
@@ -1,7 +1,7 @@
name: sunset_alarm
description: "Set an alarm to go off a specified time before sunset."
publish_to: 'none'
version: 0.1.2
version: 1.0.0
environment:
sdk: ^3.7.2