main, change layout so that minutes cannot be modified while the alarm is enabled, also handle validation better.

This commit is contained in:
me committed 2026-09-28 06:48:40 -07:00
1 parent 77320b05d6
commit 39792270f1
1 file changed
+21 -12
+21 -12
View File
@@ -66,6 +66,9 @@ class _HomeScreenState extends State<HomeScreen> {
int _minutesBefore = 30;
bool _loading = false;
String? _sunsetErrorText = null;
String? _minuteErrorText = null;
static const _alarmId = 1001;
@override
@@ -426,40 +429,46 @@ class _HomeScreenState extends State<HomeScreen> {
// --- Minutes before ---
Row(
children: [
const Text('Minutes before: '),
SizedBox(
width: 80,
if (!_alarmEnabled)
Expanded(
child: TextField(
controller: _minutesController,
keyboardType: TextInputType.number,
decoration: const InputDecoration(
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Minutes Before Sunset',
errorText: _minuteErrorText,
),
onChanged: (v) {
final val = int.tryParse(v);
if (val != null && val >= 0) {
setState(() {
if (val != null) {
_minuteErrorText = null;
_minutesBefore = val;
} else {
_showSnack('Invalid Minute Value');
_minuteErrorText = 'Invalid Minute Value';
}
});
},
),
),
],
),
const SizedBox(height: 24),
// --- Toggle ---
SwitchListTile(
title: const Text('Enable Sunset Alarm'),
Expanded(
child: SwitchListTile(
//title: const Text('Enable Sunset Alarm'),
title: Text(_alarmEnabled ? 'Sunset Alarm Enabled' : ''),
subtitle: Text(
_alarmEnabled
? 'Will alert ${_minutesBefore} min before sunset. ($_alarmDisplayTime)'
: 'Alarm is off',
: '',
),
value: _alarmEnabled,
onChanged: _toggleAlarm,
),
),
],
),
],
),
),