1.1.0 #4
+69
-83
@@ -272,10 +272,11 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
);
|
||||
} else if (Platform.isAndroid) {
|
||||
// Get the Notifications permission:
|
||||
final android = _notifications
|
||||
.resolvePlatformSpecificImplementation<
|
||||
AndroidFlutterLocalNotificationsPlugin
|
||||
>();
|
||||
final android =
|
||||
_notifications
|
||||
.resolvePlatformSpecificImplementation<
|
||||
AndroidFlutterLocalNotificationsPlugin
|
||||
>();
|
||||
await android?.requestNotificationsPermission();
|
||||
|
||||
// Ensure that Android has the correct alarm permissions.
|
||||
@@ -493,9 +494,10 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
'${picked.hour.toString().padLeft(2, '0')}:'
|
||||
'${picked.minute.toString().padLeft(2, '0')}';
|
||||
setState(
|
||||
() => _sunsetErrorText = _validateTime(
|
||||
_sunsetController.text,
|
||||
),
|
||||
() =>
|
||||
_sunsetErrorText = _validateTime(
|
||||
_sunsetController.text,
|
||||
),
|
||||
);
|
||||
if (_alarmEnabled) {
|
||||
_scheduleAlarm();
|
||||
@@ -523,13 +525,14 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
IconButton.filledTonal(
|
||||
icon: _loading
|
||||
? const SizedBox(
|
||||
width: 20,
|
||||
height: 20,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
)
|
||||
: const Icon(Icons.cloud_done_outlined),
|
||||
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) {
|
||||
@@ -548,69 +551,50 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
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();
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
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,
|
||||
),
|
||||
// --- Toggle ---
|
||||
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,
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -639,10 +623,11 @@ final _plugin = FlutterLocalNotificationsPlugin();
|
||||
|
||||
Future<void> requestPermissions() async {
|
||||
if (Platform.isAndroid) {
|
||||
final android = _plugin
|
||||
.resolvePlatformSpecificImplementation<
|
||||
AndroidFlutterLocalNotificationsPlugin
|
||||
>();
|
||||
final android =
|
||||
_plugin
|
||||
.resolvePlatformSpecificImplementation<
|
||||
AndroidFlutterLocalNotificationsPlugin
|
||||
>();
|
||||
|
||||
// Android 13+ — standard notification permission (shows a dialog)
|
||||
await android?.requestNotificationsPermission();
|
||||
@@ -652,7 +637,8 @@ Future<void> requestPermissions() async {
|
||||
}
|
||||
}
|
||||
|
||||
final android = _plugin
|
||||
.resolvePlatformSpecificImplementation<
|
||||
AndroidFlutterLocalNotificationsPlugin
|
||||
>();
|
||||
final android =
|
||||
_plugin
|
||||
.resolvePlatformSpecificImplementation<
|
||||
AndroidFlutterLocalNotificationsPlugin
|
||||
>();
|
||||
Reference in new issue
Block a user