From d44a8cdc2bea4f1d32a23cf50aad6994f65429b4 Mon Sep 17 00:00:00 2001 From: ShashankDeepak Date: Wed, 12 Jun 2024 13:12:14 +0530 Subject: [PATCH] app crash when notification permission denied fixed, issue #201 --- .gradle/8.1.1/checksums/checksums.lock | Bin 0 -> 17 bytes .../dependencies-accessors.lock | Bin 0 -> 17 bytes .../dependencies-accessors/gc.properties | 0 .../executionHistory/executionHistory.lock | Bin 0 -> 17 bytes .gradle/8.1.1/fileChanges/last-build.bin | Bin 0 -> 1 bytes .gradle/8.1.1/fileHashes/fileHashes.lock | Bin 0 -> 17 bytes .gradle/8.1.1/gc.properties | 0 .../buildOutputCleanup.lock | Bin 17 -> 17 bytes .gradle/buildOutputCleanup/cache.properties | 4 +- .gradle/buildOutputCleanup/outputFiles.bin | Bin 18713 -> 0 bytes lib/home_page.dart | 8 +- lib/main.dart | 11 +- lib/services/notificationService.dart | 128 ++++++++++++------ pubspec.lock | 40 +++--- 14 files changed, 119 insertions(+), 72 deletions(-) create mode 100644 .gradle/8.1.1/checksums/checksums.lock create mode 100644 .gradle/8.1.1/dependencies-accessors/dependencies-accessors.lock create mode 100644 .gradle/8.1.1/dependencies-accessors/gc.properties create mode 100644 .gradle/8.1.1/executionHistory/executionHistory.lock create mode 100644 .gradle/8.1.1/fileChanges/last-build.bin create mode 100644 .gradle/8.1.1/fileHashes/fileHashes.lock create mode 100644 .gradle/8.1.1/gc.properties delete mode 100644 .gradle/buildOutputCleanup/outputFiles.bin diff --git a/.gradle/8.1.1/checksums/checksums.lock b/.gradle/8.1.1/checksums/checksums.lock new file mode 100644 index 0000000000000000000000000000000000000000..b0e50e96a850b516b12d55e843bc621c80efb102 GIT binary patch literal 17 TcmZR6uyxa)3xZBt8K3|FLem8w literal 0 HcmV?d00001 diff --git a/.gradle/8.1.1/dependencies-accessors/dependencies-accessors.lock b/.gradle/8.1.1/dependencies-accessors/dependencies-accessors.lock new file mode 100644 index 0000000000000000000000000000000000000000..34f1fe54eb14128a72523b1b2ac14f47833f2cd8 GIT binary patch literal 17 TcmZP;T%+8nq`vMp0~7!NCJO^U literal 0 HcmV?d00001 diff --git a/.gradle/8.1.1/dependencies-accessors/gc.properties b/.gradle/8.1.1/dependencies-accessors/gc.properties new file mode 100644 index 0000000..e69de29 diff --git a/.gradle/8.1.1/executionHistory/executionHistory.lock b/.gradle/8.1.1/executionHistory/executionHistory.lock new file mode 100644 index 0000000000000000000000000000000000000000..f827d4a023d1390ddf68c292054f1371a8332c23 GIT binary patch literal 17 ScmZSfol&zu)-QyE0SW*mDgw*^ literal 0 HcmV?d00001 diff --git a/.gradle/8.1.1/fileChanges/last-build.bin b/.gradle/8.1.1/fileChanges/last-build.bin new file mode 100644 index 0000000000000000000000000000000000000000..f76dd238ade08917e6712764a16a22005a50573d GIT binary patch literal 1 IcmZPo000310RR91 literal 0 HcmV?d00001 diff --git a/.gradle/8.1.1/fileHashes/fileHashes.lock b/.gradle/8.1.1/fileHashes/fileHashes.lock new file mode 100644 index 0000000000000000000000000000000000000000..dca5ee9e25fea26020a74945490b5e01c82e17b7 GIT binary patch literal 17 ScmZQ>3U*v0?ZM*D00jUb)&hJ0 literal 0 HcmV?d00001 diff --git a/.gradle/8.1.1/gc.properties b/.gradle/8.1.1/gc.properties new file mode 100644 index 0000000..e69de29 diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock index 557a19ada59d9b8587443ae7e4a6025d9631e975..ec889f36497f67468d9b070be8c8d4e3498480fd 100644 GIT binary patch literal 17 UcmZR+eBGypN<}1+y64?bBQ^txd|z_+F5k<`*rZ;?yd6+hex; zKd|He#lzC_x#^DdgNxqX{q%6k^rG~KS*w!Vo_{jEAiWZ~Ik}sNRZYK_-WI-I^`|=r zOka?my1jCm;)5Ngk4VpScfD-|UfWHdk)91XkJI(JJ=2e+=ht#a_NBFH`txTmN3xkv zIdA%z^p#j*eR64P!|US#>GD>}m-P0S5kLR|1Q0*~0R#|0009ILKmY**5I_I{1Q0*~ z0R#|0009ILKmY**5I_I{1Q0*~0R#|0009IL_*;Q~eSCu+K6kiN^OvH-ua%#j{{5?u F@(y5NtF8b5 diff --git a/lib/home_page.dart b/lib/home_page.dart index e66aa4c..4924df6 100644 --- a/lib/home_page.dart +++ b/lib/home_page.dart @@ -1,6 +1,5 @@ import 'dart:ui'; import 'package:flutter_screenutil/flutter_screenutil.dart'; - import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:opso/opso_timeline.dart'; @@ -17,7 +16,7 @@ import 'package:opso/widgets/book_mark_screen.dart'; import 'package:adaptive_theme/adaptive_theme.dart'; import 'package:opso/widgets/faq.dart'; import 'dart:math' as math; - +import 'package:awesome_notifications/awesome_notifications.dart'; import 'about.dart'; class HomePage extends StatefulWidget { @@ -30,7 +29,7 @@ class HomePage extends StatefulWidget { class _HomePageState extends State { @override void initState() { - showNotification(); + // showNotification(); super.initState(); _getInitialThemeMode(); } @@ -250,8 +249,7 @@ class _HomePageState extends State { Navigator.push( context, MaterialPageRoute( - builder: (context) => - FAQPage(), + builder: (context) => FAQPage(), ), ); }, diff --git a/lib/main.dart b/lib/main.dart index bd0cf86..87e2cd7 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -12,7 +12,7 @@ import 'package:opso/programs%20screen/social_winter_of_code.dart'; import 'package:opso/services/notificationService.dart'; import 'home_page.dart'; import 'package:adaptive_theme/adaptive_theme.dart'; -import 'splash_screen.dart'; +import 'splash_screen.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); @@ -35,7 +35,7 @@ class OpSoApp extends StatelessWidget { dark: ThemeData.dark(), initial: AdaptiveThemeMode.system, builder: (theme, darkTheme) => MaterialApp( - initialRoute: '/splash_screen', + initialRoute: '/splash_screen', routes: { "/progarm_page": (context) => const HomePage(), "/girl_script_summer_of_code": (context) => const GSSOCScreen(), @@ -50,7 +50,7 @@ class OpSoApp extends StatelessWidget { const MajorLeagueHackingFellowship(), "/linux_foundation": (context) => const LinuxFoundation(), "/landing_page": (context) => const LandingPage(), - '/splash_screen': (context) => SplashScreen(), + '/splash_screen': (context) => SplashScreen(), }, title: 'OpSo', debugShowCheckedModeBanner: false, @@ -60,10 +60,9 @@ class OpSoApp extends StatelessWidget { // primarySwatch: Colors.blue, // visualDensity: VisualDensity.adaptivePlatformDensity, // ), - home: const HomePage(), - + // home: const HomePage(), ), ); }); } -} \ No newline at end of file +} diff --git a/lib/services/notificationService.dart b/lib/services/notificationService.dart index a42fb6f..5dbda2b 100644 --- a/lib/services/notificationService.dart +++ b/lib/services/notificationService.dart @@ -29,10 +29,10 @@ class NotificationService { debug: true, ); - bool isAllowed = await AwesomeNotifications().isNotificationAllowed(); - if (!isAllowed) { - await AwesomeNotifications().requestPermissionToSendNotifications(); - } + // bool isAllowed = await AwesomeNotifications().isNotificationAllowed(); + // if (!isAllowed) { + // await AwesomeNotifications().requestPermissionToSendNotifications(); + // } await AwesomeNotifications().setListeners( onActionReceivedMethod: onActionReceivedMethod, @@ -70,7 +70,7 @@ class NotificationService { } } - static Future showNotification( + static Future showNotification( {required final String title, required final String body, final String? summary, @@ -83,29 +83,61 @@ class NotificationService { final bool scheduled = false, final int? interval}) async { assert(!scheduled || (scheduled && interval != null)); - await AwesomeNotifications().createNotification( - content: NotificationContent( - id: -1, - channelKey: 'high_importance_channel', - title: title, - body: body, - actionType: actionType, - notificationLayout: notificationLayout, - summary: summary, - category: category, - payload: payload, - bigPicture: bigPicture, - ), - actionButtons: actionButtons, - schedule: scheduled - ? NotificationInterval( - interval: interval, - timeZone: - await AwesomeNotifications().getLocalTimeZoneIdentifier(), - preciseAlarm: true, - ) - : null, - ); + bool allowed = + await AwesomeNotifications().requestPermissionToSendNotifications(); + if (allowed) { + await AwesomeNotifications().createNotification( + content: NotificationContent( + id: -1, + channelKey: 'high_importance_channel', + title: title, + body: body, + actionType: actionType, + notificationLayout: notificationLayout, + summary: summary, + category: category, + payload: payload, + bigPicture: bigPicture, + ), + actionButtons: actionButtons, + schedule: scheduled + ? NotificationInterval( + interval: interval, + timeZone: + await AwesomeNotifications().getLocalTimeZoneIdentifier(), + preciseAlarm: true, + ) + : null, + ); + } else { + allowed = await AwesomeNotifications().isNotificationAllowed(); + if (allowed) { + await AwesomeNotifications().createNotification( + content: NotificationContent( + id: -1, + channelKey: 'high_importance_channel', + title: title, + body: body, + actionType: actionType, + notificationLayout: notificationLayout, + summary: summary, + category: category, + payload: payload, + bigPicture: bigPicture, + ), + actionButtons: actionButtons, + schedule: scheduled + ? NotificationInterval( + interval: interval, + timeZone: + await AwesomeNotifications().getLocalTimeZoneIdentifier(), + preciseAlarm: true, + ) + : null, + ); + } + } + return allowed; } static Future scheduleNotificationsForEvent( @@ -132,17 +164,35 @@ class NotificationService { ); } - static Future _scheduleNotification( + static Future _scheduleNotification( String description, String body, DateTime dateTime) async { - await AwesomeNotifications().createNotification( - content: NotificationContent( - id: DateTime.now().millisecondsSinceEpoch.remainder(100000), - channelKey: 'high_importance_channel', - title: description, - body: body, - notificationLayout: NotificationLayout.Default, - ), - schedule: NotificationCalendar.fromDate(date: dateTime), - ); + if (await AwesomeNotifications().isNotificationAllowed()) { + await AwesomeNotifications().createNotification( + content: NotificationContent( + id: DateTime.now().millisecondsSinceEpoch.remainder(100000), + channelKey: 'high_importance_channel', + title: description, + body: body, + notificationLayout: NotificationLayout.Default, + ), + schedule: NotificationCalendar.fromDate(date: dateTime), + ); + return true; + } else { + bool allowed = await AwesomeNotifications().isNotificationAllowed(); + if (allowed) { + await AwesomeNotifications().createNotification( + content: NotificationContent( + id: DateTime.now().millisecondsSinceEpoch.remainder(100000), + channelKey: 'high_importance_channel', + title: description, + body: body, + notificationLayout: NotificationLayout.Default, + ), + schedule: NotificationCalendar.fromDate(date: dateTime), + ); + } + return allowed; + } } } diff --git a/pubspec.lock b/pubspec.lock index c36028c..6cc3be2 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -260,26 +260,26 @@ packages: dependency: transitive description: name: leak_tracker - sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a" + sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa" url: "https://pub.dev" source: hosted - version: "10.0.4" + version: "10.0.0" leak_tracker_flutter_testing: dependency: transitive description: name: leak_tracker_flutter_testing - sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8" + sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0 url: "https://pub.dev" source: hosted - version: "3.0.3" + version: "2.0.1" leak_tracker_testing: dependency: transitive description: name: leak_tracker_testing - sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3" + sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47 url: "https://pub.dev" source: hosted - version: "3.0.1" + version: "2.0.1" lints: dependency: transitive description: @@ -308,10 +308,10 @@ packages: dependency: transitive description: name: meta - sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136" + sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04 url: "https://pub.dev" source: hosted - version: "1.12.0" + version: "1.11.0" multi_select_flutter: dependency: "direct main" description: @@ -396,10 +396,10 @@ packages: dependency: transitive description: name: shared_preferences_android - sha256: "93d0ec9dd902d85f326068e6a899487d1f65ffcd5798721a95330b26c8131577" + sha256: "1ee8bf911094a1b592de7ab29add6f826a7331fb854273d55918693d5364a1f2" url: "https://pub.dev" source: hosted - version: "2.2.3" + version: "2.2.2" shared_preferences_foundation: dependency: transitive description: @@ -489,10 +489,10 @@ packages: dependency: transitive description: name: test_api - sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f" + sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" url: "https://pub.dev" source: hosted - version: "0.7.0" + version: "0.6.1" timeline_tile: dependency: "direct main" description: @@ -521,10 +521,10 @@ packages: dependency: transitive description: name: url_launcher_android - sha256: ceb2625f0c24ade6ef6778d1de0b2e44f2db71fded235eb52295247feba8c5cf + sha256: "17cd5e205ea615e2c6ea7a77323a11712dffa0720a8a90540db57a01347f9ad9" url: "https://pub.dev" source: hosted - version: "6.3.3" + version: "6.3.2" url_launcher_ios: dependency: transitive description: @@ -609,10 +609,10 @@ packages: dependency: transitive description: name: vm_service - sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec" + sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957 url: "https://pub.dev" source: hosted - version: "14.2.1" + version: "13.0.0" web: dependency: transitive description: @@ -625,10 +625,10 @@ packages: dependency: transitive description: name: win32 - sha256: a79dbe579cb51ecd6d30b17e0cae4e0ea15e2c0e66f69ad4198f22a6789e94f4 + sha256: "0eaf06e3446824099858367950a813472af675116bf63f008a4c2a75ae13e9cb" url: "https://pub.dev" source: hosted - version: "5.5.1" + version: "5.5.0" xdg_directories: dependency: transitive description: @@ -654,5 +654,5 @@ packages: source: hosted version: "3.1.2" sdks: - dart: ">=3.4.0 <4.0.0" - flutter: ">=3.22.0" + dart: ">=3.3.3 <4.0.0" + flutter: ">=3.19.0"