0.1.2 #1
@@ -1,5 +1,6 @@
|
||||
import 'dart:io';
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
@@ -7,6 +8,7 @@ import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||
import 'package:timezone/data/latest_all.dart' as tz;
|
||||
import 'package:timezone/timezone.dart' as tz;
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
import 'dart:convert';
|
||||
|
||||
void main() async {
|
||||
@@ -171,6 +173,12 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
Timer? _alarmTimer;
|
||||
|
||||
Future<void> _scheduleAlarm() async {
|
||||
final canSchedule = await android?.canScheduleExactNotifications();
|
||||
if (canSchedule != true) {
|
||||
_showSnack('Permissions not yet granted, requesting...');
|
||||
await android?.requestExactAlarmsPermission();
|
||||
}
|
||||
|
||||
final sunsetText = _sunsetController.text.trim();
|
||||
if (sunsetText.isEmpty) return;
|
||||
|
||||
@@ -417,3 +425,27 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
return '${dh.toString().padLeft(2, '0')}:${dm.toString().padLeft(2, '0')}';
|
||||
}
|
||||
}
|
||||
|
||||
final _plugin = FlutterLocalNotificationsPlugin();
|
||||
|
||||
Future<void> requestPermissions() async {
|
||||
if (Platform.isAndroid) {
|
||||
final android =
|
||||
_plugin
|
||||
.resolvePlatformSpecificImplementation<
|
||||
AndroidFlutterLocalNotificationsPlugin
|
||||
>();
|
||||
|
||||
// Android 13+ — standard notification permission (shows a dialog)
|
||||
await android?.requestNotificationsPermission();
|
||||
|
||||
// Android 12+ — exact alarm special access (opens system settings page)
|
||||
await android?.requestExactAlarmsPermission();
|
||||
}
|
||||
}
|
||||
|
||||
final android =
|
||||
_plugin
|
||||
.resolvePlatformSpecificImplementation<
|
||||
AndroidFlutterLocalNotificationsPlugin
|
||||
>();
|
||||
Reference in new issue
Block a user