Begin changes to ask for Android permissions rather than silrently failing.
This commit is contained in:
1 parent
280e748bb7
commit
e643e797c9
1 file changed
+32
@@ -1,5 +1,6 @@
|
|||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:geolocator/geolocator.dart';
|
import 'package:geolocator/geolocator.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.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/data/latest_all.dart' as tz;
|
||||||
import 'package:timezone/timezone.dart' as tz;
|
import 'package:timezone/timezone.dart' as tz;
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
|
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
@@ -171,6 +173,12 @@ class _HomeScreenState extends State<HomeScreen> {
|
|||||||
Timer? _alarmTimer;
|
Timer? _alarmTimer;
|
||||||
|
|
||||||
Future<void> _scheduleAlarm() async {
|
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();
|
final sunsetText = _sunsetController.text.trim();
|
||||||
if (sunsetText.isEmpty) return;
|
if (sunsetText.isEmpty) return;
|
||||||
|
|
||||||
@@ -417,3 +425,27 @@ class _HomeScreenState extends State<HomeScreen> {
|
|||||||
return '${dh.toString().padLeft(2, '0')}:${dm.toString().padLeft(2, '0')}';
|
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