Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
39792270f1 | ||
|
|
77320b05d6 | ||
|
|
4788cdd220 | ||
|
|
0659262e61 | ||
|
|
287c2f0cd0 |
+47
-21
@@ -11,6 +11,18 @@ import 'package:alarm/alarm.dart';
|
|||||||
|
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
|
/// TBD:
|
||||||
|
/// v0.2.1
|
||||||
|
/// - Fix time to get 0 prefixed if before 10:00 (5:30 becomes 05:30).
|
||||||
|
/// - Fix time to validate properly rather than allowing garbage (error 530).
|
||||||
|
/// v0.3.0
|
||||||
|
/// - Add sunrise section and change app name to Sunshine Alarm?
|
||||||
|
/// v1.0.0
|
||||||
|
/// - Follow system theme rather than using a custom theme.
|
||||||
|
/// v1.0.1
|
||||||
|
/// - Use a timepicker if the user clicks on the sunset/sunrise time.
|
||||||
|
/// :TBD
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
tz.initializeTimeZones();
|
tz.initializeTimeZones();
|
||||||
@@ -54,6 +66,9 @@ class _HomeScreenState extends State<HomeScreen> {
|
|||||||
int _minutesBefore = 30;
|
int _minutesBefore = 30;
|
||||||
bool _loading = false;
|
bool _loading = false;
|
||||||
|
|
||||||
|
String? _sunsetErrorText = null;
|
||||||
|
String? _minuteErrorText = null;
|
||||||
|
|
||||||
static const _alarmId = 1001;
|
static const _alarmId = 1001;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -261,13 +276,13 @@ class _HomeScreenState extends State<HomeScreen> {
|
|||||||
// Schedule:
|
// Schedule:
|
||||||
final settings = AlarmSettings(
|
final settings = AlarmSettings(
|
||||||
id: _alarmId,
|
id: _alarmId,
|
||||||
dateTime: alarmTime, // your computed sunset time
|
dateTime: alarmTime,
|
||||||
//assetAudioPath: 'assets/alarm.mp3', // put an alarm sound in assets/
|
//assetAudioPath: 'assets/alarm.mp3', // use default rather than custom
|
||||||
loopAudio: true, // keeps ringing until dismissed
|
loopAudio: true, // keeps ringing until dismissed
|
||||||
vibrate: true,
|
vibrate: true,
|
||||||
androidFullScreenIntent: true, // wakes screen like clock app
|
androidFullScreenIntent: true, // wakes screen like clock app
|
||||||
volumeSettings: VolumeSettings.fade(
|
volumeSettings: VolumeSettings.fade(
|
||||||
volume: 0.8,
|
//volume: 0.8, // use default rather than custom
|
||||||
fadeDuration: Duration(seconds: 60),
|
fadeDuration: Duration(seconds: 60),
|
||||||
),
|
),
|
||||||
notificationSettings: NotificationSettings(
|
notificationSettings: NotificationSettings(
|
||||||
@@ -291,7 +306,11 @@ class _HomeScreenState extends State<HomeScreen> {
|
|||||||
} else {
|
} else {
|
||||||
_alarmTimer?.cancel();
|
_alarmTimer?.cancel();
|
||||||
if (!Platform.isLinux) {
|
if (!Platform.isLinux) {
|
||||||
await _notifications.cancel(id: _alarmId);
|
// Notification Method
|
||||||
|
//await _notifications.cancel(id: _alarmId);
|
||||||
|
|
||||||
|
// Alarm Method
|
||||||
|
await Alarm.stop(_alarmId);
|
||||||
}
|
}
|
||||||
_showSnack('Alarm cancelled.');
|
_showSnack('Alarm cancelled.');
|
||||||
}
|
}
|
||||||
@@ -359,7 +378,7 @@ class _HomeScreenState extends State<HomeScreen> {
|
|||||||
const SizedBox(width: 8),
|
const SizedBox(width: 8),
|
||||||
IconButton.filledTonal(
|
IconButton.filledTonal(
|
||||||
icon: const Icon(Icons.my_location),
|
icon: const Icon(Icons.my_location),
|
||||||
tooltip: 'Get GPS location',
|
tooltip: 'Get GPS Location',
|
||||||
onPressed: _getGpsLocation,
|
onPressed: _getGpsLocation,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -378,7 +397,7 @@ class _HomeScreenState extends State<HomeScreen> {
|
|||||||
child: TextField(
|
child: TextField(
|
||||||
controller: _sunsetController,
|
controller: _sunsetController,
|
||||||
decoration: const InputDecoration(
|
decoration: const InputDecoration(
|
||||||
labelText: 'Sunset time (HH:MM)',
|
labelText: 'Sunset Time (HH:MM)',
|
||||||
border: OutlineInputBorder(),
|
border: OutlineInputBorder(),
|
||||||
),
|
),
|
||||||
onChanged: (_) => _savePrefs(),
|
onChanged: (_) => _savePrefs(),
|
||||||
@@ -394,55 +413,62 @@ class _HomeScreenState extends State<HomeScreen> {
|
|||||||
child: CircularProgressIndicator(strokeWidth: 2),
|
child: CircularProgressIndicator(strokeWidth: 2),
|
||||||
)
|
)
|
||||||
: const Icon(Icons.cloud_done_outlined),
|
: const Icon(Icons.cloud_done_outlined),
|
||||||
tooltip: 'Fetch sunset from Open-Meteo',
|
tooltip: 'Fetch Sunset Time from Open-Meteo',
|
||||||
onPressed: _loading ? null : _fetchSunset,
|
onPressed: _loading ? null : _fetchSunset,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
|
|
||||||
// --- Minutes before ---
|
|
||||||
const Text(
|
const Text(
|
||||||
'Alert Before Sunset',
|
'Alert',
|
||||||
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
|
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
|
|
||||||
|
// --- Minutes before ---
|
||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
const Text('Minutes before: '),
|
if (!_alarmEnabled)
|
||||||
SizedBox(
|
Expanded(
|
||||||
width: 80,
|
|
||||||
child: TextField(
|
child: TextField(
|
||||||
controller: _minutesController,
|
controller: _minutesController,
|
||||||
keyboardType: TextInputType.number,
|
keyboardType: TextInputType.number,
|
||||||
decoration: const InputDecoration(
|
decoration: InputDecoration(
|
||||||
border: OutlineInputBorder(),
|
border: OutlineInputBorder(),
|
||||||
|
labelText: 'Minutes Before Sunset',
|
||||||
|
errorText: _minuteErrorText,
|
||||||
),
|
),
|
||||||
onChanged: (v) {
|
onChanged: (v) {
|
||||||
final val = int.tryParse(v);
|
final val = int.tryParse(v);
|
||||||
if (val != null && val >= 0) {
|
setState(() {
|
||||||
|
if (val != null) {
|
||||||
|
_minuteErrorText = null;
|
||||||
_minutesBefore = val;
|
_minutesBefore = val;
|
||||||
} else {
|
} else {
|
||||||
_showSnack('Invalid Minute Value');
|
_minuteErrorText = 'Invalid Minute Value';
|
||||||
}
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(height: 24),
|
|
||||||
|
|
||||||
// --- Toggle ---
|
// --- Toggle ---
|
||||||
SwitchListTile(
|
Expanded(
|
||||||
title: const Text('Enable Sunset Alarm'),
|
child: SwitchListTile(
|
||||||
|
//title: const Text('Enable Sunset Alarm'),
|
||||||
|
title: Text(_alarmEnabled ? 'Sunset Alarm Enabled' : ''),
|
||||||
subtitle: Text(
|
subtitle: Text(
|
||||||
_alarmEnabled
|
_alarmEnabled
|
||||||
? 'Will alert ${_minutesBefore} min before sunset. ($_alarmDisplayTime)'
|
? 'Will alert ${_minutesBefore} min before sunset. ($_alarmDisplayTime)'
|
||||||
: 'Alarm is off',
|
: '',
|
||||||
),
|
),
|
||||||
value: _alarmEnabled,
|
value: _alarmEnabled,
|
||||||
onChanged: _toggleAlarm,
|
onChanged: _toggleAlarm,
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in new issue
Block a user