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';
|
||||
|
||||
/// TBD:
|
||||
/// v0.3.0
|
||||
/// - Add other languages (Spanish, Croatian)
|
||||
/// v1.1.0
|
||||
/// - 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?
|
||||
/// :TBD
|
||||
|
||||
@@ -71,12 +72,13 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
final FlutterLocalNotificationsPlugin _notifications =
|
||||
FlutterLocalNotificationsPlugin();
|
||||
|
||||
bool _loading = false;
|
||||
bool _alarmEnabled = false;
|
||||
int _minutesBefore = 30;
|
||||
bool _loading = false;
|
||||
String _plural = 's';
|
||||
|
||||
String? _sunsetErrorText = null;
|
||||
String? _minuteErrorText = null;
|
||||
String? _sunsetErrorText;
|
||||
String? _minuteErrorText;
|
||||
|
||||
static const _alarmId = 1001;
|
||||
|
||||
@@ -202,21 +204,6 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
Timer? _alarmTimer;
|
||||
|
||||
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();
|
||||
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!)',
|
||||
);
|
||||
} 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) {
|
||||
// Android: use zonedSchedule (works in background)
|
||||
final tzAlarm = tz.TZDateTime.from(alarmTime, tz.local);
|
||||
@@ -289,7 +291,7 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
}
|
||||
// End Notification Method ***/
|
||||
|
||||
/*** Alarm Method - WIP ***/
|
||||
/*** Alarm Method - Works ***/
|
||||
if (ANDROID_USE_ALARM) {
|
||||
// Schedule:
|
||||
final settings = AlarmSettings(
|
||||
@@ -305,7 +307,7 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
),
|
||||
notificationSettings: NotificationSettings(
|
||||
title: 'Sunset Alarm',
|
||||
body: 'Sun is setting in ${_minutesBefore} minute(s)!',
|
||||
body: 'Sun is setting in ${_minutesBefore} minute${_plural}!',
|
||||
stopButton: 'Dismiss',
|
||||
icon: 'ic_notification',
|
||||
),
|
||||
@@ -343,6 +345,7 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_savePrefs();
|
||||
_latController.dispose();
|
||||
_lngController.dispose();
|
||||
_sunsetController.dispose();
|
||||
@@ -519,6 +522,7 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
} else {
|
||||
_minuteErrorText = 'Invalid Minute Value';
|
||||
}
|
||||
_plural = (_minutesBefore == 1) ? '' : 's';
|
||||
});
|
||||
},
|
||||
),
|
||||
@@ -531,7 +535,7 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
title: Text(_alarmEnabled ? 'Sunset Alarm Enabled' : ''),
|
||||
subtitle: Text(
|
||||
_alarmEnabled
|
||||
? 'Will alert ${_minutesBefore} min before sunset. ($_alarmDisplayTime)'
|
||||
? '${_minutesBefore} Minute${_plural} Before @ $_alarmDisplayTime'
|
||||
: '',
|
||||
),
|
||||
value: _alarmEnabled,
|
||||
|
||||
Reference in new issue
Block a user