From b810baa89f029b9add157ac911fdd9bbb8266ff8 Mon Sep 17 00:00:00 2001 From: Hitesh Kumar Saini Date: Thu, 6 Oct 2022 12:11:29 +0530 Subject: [PATCH] fix: android 13 notifications permission --- lib/main.dart | 9 +++++++++ lib/widgets/settings.dart | 3 ++- pubspec.lock | 35 +++++++++++++++++++++++++++++++++++ pubspec.yaml | 1 + 4 files changed, 47 insertions(+), 1 deletion(-) diff --git a/lib/main.dart b/lib/main.dart index c75ee694..3a326658 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -22,6 +22,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:provider/provider.dart'; import 'package:hive_flutter/hive_flutter.dart'; +import 'package:permission_handler/permission_handler.dart'; import 'package:status_bar_control/status_bar_control.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; @@ -38,6 +39,14 @@ final navigatorKey = GlobalKey(); Future main() async { WidgetsFlutterBinding.ensureInitialized(); + // Request notifications permission for iOS and Android 13+. + try { + final result = await Permission.notification.request(); + debugPrint(result.toString()); + } catch (exception, stacktrace) { + debugPrint(exception.toString()); + debugPrint(stacktrace.toString()); + } HttpOverrides.global = DevHttpOverrides(); await Hive.initFlutter(); await MobileViewProvider.ensureInitialized(); diff --git a/lib/widgets/settings.dart b/lib/widgets/settings.dart index f6bdd3f9..a24b599e 100644 --- a/lib/widgets/settings.dart +++ b/lib/widgets/settings.dart @@ -151,7 +151,8 @@ class _SettingsState extends State { final timeOfDay = await showTimePicker( context: context, helpText: AppLocalizations.of(context) - .snoozeNotificationsUntil, + .snoozeNotificationsUntil + .toUpperCase(), initialTime: TimeOfDay.fromDateTime(DateTime.now()), useRootNavigator: false, builder: (_, child) => diff --git a/pubspec.lock b/pubspec.lock index e19a84d6..905a195f 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -399,6 +399,41 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.0.7" + permission_handler: + dependency: "direct main" + description: + name: permission_handler + url: "https://pub.dartlang.org" + source: hosted + version: "10.1.0" + permission_handler_android: + dependency: transitive + description: + name: permission_handler_android + url: "https://pub.dartlang.org" + source: hosted + version: "10.1.0" + permission_handler_apple: + dependency: transitive + description: + name: permission_handler_apple + url: "https://pub.dartlang.org" + source: hosted + version: "9.0.6" + permission_handler_platform_interface: + dependency: transitive + description: + name: permission_handler_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "3.8.0" + permission_handler_windows: + dependency: transitive + description: + name: permission_handler_windows + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.1" petitparser: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index fe6a2cee..c4ce46f3 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -53,6 +53,7 @@ dependencies: hive: ^2.2.3 hive_flutter: ^1.1.0 video_thumbnail: ^0.5.0 + permission_handler: ^10.1.0 dev_dependencies: flutter_test: