Ask for location permission first, notifications later. Roadmap.

This commit is contained in:
stopflock
2026-02-03 16:22:46 -06:00
parent aba919f8d4
commit 38245bfb5b
5 changed files with 53 additions and 10 deletions

View File

@@ -27,6 +27,7 @@ import '../services/changelog_service.dart';
import 'coordinators/sheet_coordinator.dart';
import 'coordinators/navigation_coordinator.dart';
import 'coordinators/map_interaction_handler.dart';
import 'package:geolocator/geolocator.dart';
class HomeScreen extends StatefulWidget {
const HomeScreen({super.key});
@@ -153,6 +154,33 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
);
}
// Request location permission on first launch
Future<void> _requestLocationPermissionIfFirstLaunch() async {
if (!mounted) return;
try {
// Only request on first launch or if user has never seen welcome
final isFirstLaunch = await ChangelogService().isFirstLaunch();
final hasSeenWelcome = await ChangelogService().hasSeenWelcome();
if (isFirstLaunch || !hasSeenWelcome) {
// Check if location services are enabled
bool serviceEnabled = await Geolocator.isLocationServiceEnabled();
if (!serviceEnabled) {
debugPrint('[HomeScreen] Location services disabled - skipping permission request');
return;
}
// Request location permission (this will show system dialog if needed)
final permission = await Geolocator.requestPermission();
debugPrint('[HomeScreen] First launch location permission result: $permission');
}
} catch (e) {
// Silently handle errors to avoid breaking the app launch
debugPrint('[HomeScreen] Error requesting location permission: $e');
}
}
// Check for and display welcome/changelog popup
Future<void> _checkForPopup() async {
if (!mounted) return;
@@ -178,6 +206,10 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
barrierDismissible: false,
builder: (context) => const WelcomeDialog(),
);
// Request location permission right after welcome dialog on first launch
if (!mounted) return;
await _requestLocationPermissionIfFirstLaunch();
break;
case PopupType.changelog:

View File

@@ -41,9 +41,9 @@ class ProximityAlertService {
const androidSettings = AndroidInitializationSettings('@mipmap/ic_launcher');
const iosSettings = DarwinInitializationSettings(
requestAlertPermission: true,
requestBadgePermission: true,
requestSoundPermission: true,
requestAlertPermission: false,
requestBadgePermission: false,
requestSoundPermission: false,
);
const initSettings = InitializationSettings(
@@ -55,12 +55,10 @@ class ProximityAlertService {
final initialized = await _notifications!.initialize(initSettings);
_isInitialized = initialized ?? false;
// Request notification permissions (especially important for Android 13+)
if (_isInitialized) {
await _requestNotificationPermissions();
}
// Note: We don't request notification permissions here anymore.
// Permissions are requested on-demand when user enables proximity alerts.
debugPrint('[ProximityAlertService] Initialized: $_isInitialized');
debugPrint('[ProximityAlertService] Initialized: $_isInitialized (permissions deferred)');
} catch (e) {
debugPrint('[ProximityAlertService] Failed to initialize: $e');
_isInitialized = false;