Skip to content

Commit f89a4d5

Browse files
committed
refactor(notifications): simulate permission request in NoOpPushNotificationService
- Add ValueNotifier to simulate permission state - Implement requestPermission to update permission state - Modify hasPermission to reflect simulated permission state
1 parent b497446 commit f89a4d5

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

lib/notifications/services/no_op_push_notification_service.dart

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:core/core.dart';
2+
import 'package:flutter/foundation.dart';
23
import 'package:flutter_news_app_mobile_client_full_source_code/notifications/services/push_notification_service.dart';
34

45
/// {@template no_op_push_notification_service}
@@ -10,14 +11,26 @@ import 'package:flutter_news_app_mobile_client_full_source_code/notifications/se
1011
/// empty implementations for all required methods.
1112
/// {@endtemplate}
1213
class NoOpPushNotificationService extends PushNotificationService {
14+
final ValueNotifier<bool> _permissionState = ValueNotifier(false);
15+
1316
@override
1417
Future<void> initialize() async {}
1518

1619
@override
17-
Future<bool> requestPermission() async => true;
20+
Future<bool> requestPermission() async {
21+
// Simulate the user granting permission.
22+
_permissionState.value = true;
23+
return Future.value(true);
24+
}
1825

1926
@override
20-
Future<bool> hasPermission() async => true;
27+
Future<bool> hasPermission() async {
28+
// In the demo environment, this simulates the permission state.
29+
// It starts as `false` and becomes `true` after `requestPermission` is
30+
// called, allowing the UI to show a pre-permission dialog on the first
31+
// attempt.
32+
return Future.value(_permissionState.value);
33+
}
2134

2235
@override
2336
Future<void> registerDevice({required String userId}) async {}

0 commit comments

Comments
 (0)