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
+38 -29
+38 -29
View File
@@ -66,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
@@ -426,40 +429,46 @@ class _HomeScreenState extends State<HomeScreen> {
// --- Minutes before --- // --- 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: InputDecoration(
decoration: const InputDecoration( border: OutlineInputBorder(),
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';
}
});
},
), ),
onChanged: (v) { ),
final val = int.tryParse(v);
if (val != null && val >= 0) { // --- Toggle ---
_minutesBefore = val; Expanded(
} else { child: SwitchListTile(
_showSnack('Invalid Minute Value'); //title: const Text('Enable Sunset Alarm'),
} title: Text(_alarmEnabled ? 'Sunset Alarm Enabled' : ''),
}, subtitle: Text(
_alarmEnabled
? 'Will alert ${_minutesBefore} min before sunset. ($_alarmDisplayTime)'
: '',
),
value: _alarmEnabled,
onChanged: _toggleAlarm,
), ),
), ),
], ],
), ),
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,
),
], ],
), ),
), ),