Skip to content

Commit

Permalink
fix: android 13 notifications permission
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmercerind committed Oct 6, 2022
1 parent 42f1bc0 commit b810baa
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
9 changes: 9 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -38,6 +39,14 @@ final navigatorKey = GlobalKey<NavigatorState>();

Future<void> 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();
Expand Down
3 changes: 2 additions & 1 deletion lib/widgets/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ class _SettingsState extends State<Settings> {
final timeOfDay = await showTimePicker(
context: context,
helpText: AppLocalizations.of(context)
.snoozeNotificationsUntil,
.snoozeNotificationsUntil
.toUpperCase(),
initialTime: TimeOfDay.fromDateTime(DateTime.now()),
useRootNavigator: false,
builder: (_, child) =>
Expand Down
35 changes: 35 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit b810baa

Please sign in to comment.