fix(flutter): request notification permission proactively (TODO-041)
When user enables poke notifications, call requestPermission() immediately so OS prompt appears on first enable, not lazily.
This commit is contained in:
@@ -1,13 +1,19 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../l10n/generated/app_localizations.dart';
|
||||
import '../services/poke_notification_service.dart';
|
||||
import '../services/poke_preferences_service.dart';
|
||||
import 'voice_settings_controls.dart';
|
||||
|
||||
class PokeNotificationSettingsDialog extends StatelessWidget {
|
||||
const PokeNotificationSettingsDialog({super.key, required this.preferences});
|
||||
const PokeNotificationSettingsDialog({
|
||||
super.key,
|
||||
required this.preferences,
|
||||
required this.notificationService,
|
||||
});
|
||||
|
||||
final PokePreferencesService preferences;
|
||||
final PokeNotificationService notificationService;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -31,7 +37,15 @@ class PokeNotificationSettingsDialog extends StatelessWidget {
|
||||
title: Text(l10n.pokeSettingsEnableLabel),
|
||||
subtitle: Text(l10n.pokeSettingsEnableDescription),
|
||||
value: enabled,
|
||||
onChanged: (value) => preferences.setPokesEnabled(value),
|
||||
onChanged: (value) async {
|
||||
await preferences.setPokesEnabled(value);
|
||||
// Request notification permission when enabling pokes
|
||||
// so the OS prompt appears immediately rather than on
|
||||
// the first poke event.
|
||||
if (value) {
|
||||
await notificationService.requestPermission();
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
const Divider(height: 24),
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import 'package:chanora_flutter/l10n/generated/app_localizations.dart';
|
||||
import 'package:chanora_flutter/services/poke_notification_service.dart';
|
||||
import 'package:chanora_flutter/services/poke_preferences_service.dart';
|
||||
import 'package:chanora_flutter/widgets/poke_notification_settings.dart';
|
||||
|
||||
@@ -14,11 +15,16 @@ void main() {
|
||||
await preferences.muteSender(BigInt.from(42));
|
||||
addTearDown(preferences.dispose);
|
||||
|
||||
final notificationService = PokeNotificationService();
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
localizationsDelegates: AppL10n.localizationsDelegates,
|
||||
supportedLocales: AppL10n.supportedLocales,
|
||||
home: PokeNotificationSettingsDialog(preferences: preferences),
|
||||
home: PokeNotificationSettingsDialog(
|
||||
preferences: preferences,
|
||||
notificationService: notificationService,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user