main, more UI/UX fixes and enhancements.
This commit is contained in:
1 parent
251e03db5b
commit
f5e368a902
1 file changed
+28
-24
+28
-24
@@ -13,9 +13,10 @@ import 'package:alarm/alarm.dart';
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
/// TBD:
|
/// TBD:
|
||||||
/// v0.3.0
|
/// - Add other languages (Spanish, Croatian)
|
||||||
|
/// v1.1.0
|
||||||
/// - Change sunset grabber to checkbox and retrieve it each alarm or open.
|
/// - Change sunset grabber to checkbox and retrieve it each alarm or open.
|
||||||
/// v1.0.0
|
/// v2.0.0
|
||||||
/// - Add sunrise section and change app name to Sunshine Alarm?
|
/// - Add sunrise section and change app name to Sunshine Alarm?
|
||||||
/// :TBD
|
/// :TBD
|
||||||
|
|
||||||
@@ -71,12 +72,13 @@ class _HomeScreenState extends State<HomeScreen> {
|
|||||||
final FlutterLocalNotificationsPlugin _notifications =
|
final FlutterLocalNotificationsPlugin _notifications =
|
||||||
FlutterLocalNotificationsPlugin();
|
FlutterLocalNotificationsPlugin();
|
||||||
|
|
||||||
|
bool _loading = false;
|
||||||
bool _alarmEnabled = false;
|
bool _alarmEnabled = false;
|
||||||
int _minutesBefore = 30;
|
int _minutesBefore = 30;
|
||||||
bool _loading = false;
|
String _plural = 's';
|
||||||
|
|
||||||
String? _sunsetErrorText = null;
|
String? _sunsetErrorText;
|
||||||
String? _minuteErrorText = null;
|
String? _minuteErrorText;
|
||||||
|
|
||||||
static const _alarmId = 1001;
|
static const _alarmId = 1001;
|
||||||
|
|
||||||
@@ -202,21 +204,6 @@ class _HomeScreenState extends State<HomeScreen> {
|
|||||||
Timer? _alarmTimer;
|
Timer? _alarmTimer;
|
||||||
|
|
||||||
Future<void> _scheduleAlarm() async {
|
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 Need Granted, Requesting...');
|
|
||||||
await android?.requestExactAlarmsPermission();
|
|
||||||
}
|
|
||||||
|
|
||||||
final sunsetText = _sunsetController.text.trim();
|
final sunsetText = _sunsetController.text.trim();
|
||||||
if (sunsetText.isEmpty) return;
|
if (sunsetText.isEmpty) return;
|
||||||
|
|
||||||
@@ -259,7 +246,22 @@ class _HomeScreenState extends State<HomeScreen> {
|
|||||||
'Alarm Enabled @ ${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) {
|
} else if (Platform.isAndroid) {
|
||||||
/*** Notifcation Method - Works ***/
|
// 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) {
|
if (ANDROID_USE_NOTIF) {
|
||||||
// Android: use zonedSchedule (works in background)
|
// Android: use zonedSchedule (works in background)
|
||||||
final tzAlarm = tz.TZDateTime.from(alarmTime, tz.local);
|
final tzAlarm = tz.TZDateTime.from(alarmTime, tz.local);
|
||||||
@@ -289,7 +291,7 @@ class _HomeScreenState extends State<HomeScreen> {
|
|||||||
}
|
}
|
||||||
// End Notification Method ***/
|
// End Notification Method ***/
|
||||||
|
|
||||||
/*** Alarm Method - WIP ***/
|
/*** Alarm Method - Works ***/
|
||||||
if (ANDROID_USE_ALARM) {
|
if (ANDROID_USE_ALARM) {
|
||||||
// Schedule:
|
// Schedule:
|
||||||
final settings = AlarmSettings(
|
final settings = AlarmSettings(
|
||||||
@@ -305,7 +307,7 @@ class _HomeScreenState extends State<HomeScreen> {
|
|||||||
),
|
),
|
||||||
notificationSettings: NotificationSettings(
|
notificationSettings: NotificationSettings(
|
||||||
title: 'Sunset Alarm',
|
title: 'Sunset Alarm',
|
||||||
body: 'Sun is setting in ${_minutesBefore} minute(s)!',
|
body: 'Sun is setting in ${_minutesBefore} minute${_plural}!',
|
||||||
stopButton: 'Dismiss',
|
stopButton: 'Dismiss',
|
||||||
icon: 'ic_notification',
|
icon: 'ic_notification',
|
||||||
),
|
),
|
||||||
@@ -343,6 +345,7 @@ class _HomeScreenState extends State<HomeScreen> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
|
_savePrefs();
|
||||||
_latController.dispose();
|
_latController.dispose();
|
||||||
_lngController.dispose();
|
_lngController.dispose();
|
||||||
_sunsetController.dispose();
|
_sunsetController.dispose();
|
||||||
@@ -519,6 +522,7 @@ class _HomeScreenState extends State<HomeScreen> {
|
|||||||
} else {
|
} else {
|
||||||
_minuteErrorText = 'Invalid Minute Value';
|
_minuteErrorText = 'Invalid Minute Value';
|
||||||
}
|
}
|
||||||
|
_plural = (_minutesBefore == 1) ? '' : 's';
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@@ -531,7 +535,7 @@ class _HomeScreenState extends State<HomeScreen> {
|
|||||||
title: Text(_alarmEnabled ? 'Sunset Alarm Enabled' : ''),
|
title: Text(_alarmEnabled ? 'Sunset Alarm Enabled' : ''),
|
||||||
subtitle: Text(
|
subtitle: Text(
|
||||||
_alarmEnabled
|
_alarmEnabled
|
||||||
? 'Will alert ${_minutesBefore} min before sunset. ($_alarmDisplayTime)'
|
? '${_minutesBefore} Minute${_plural} Before @ $_alarmDisplayTime'
|
||||||
: '',
|
: '',
|
||||||
),
|
),
|
||||||
value: _alarmEnabled,
|
value: _alarmEnabled,
|
||||||
|
|||||||
Reference in new issue
Block a user