home_widget.dart 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  1. import 'dart:async';
  2. import 'dart:io';
  3. import "dart:math";
  4. import 'package:flutter/material.dart';
  5. import 'package:flutter/scheduler.dart';
  6. import 'package:flutter/services.dart';
  7. import "package:flutter_animate/flutter_animate.dart";
  8. import "package:flutter_local_notifications/flutter_local_notifications.dart";
  9. import 'package:home_widget/home_widget.dart' as hw;
  10. import 'package:logging/logging.dart';
  11. import 'package:media_extension/media_extension_action_types.dart';
  12. import 'package:modal_bottom_sheet/modal_bottom_sheet.dart';
  13. import 'package:move_to_background/move_to_background.dart';
  14. import 'package:photos/core/configuration.dart';
  15. import "package:photos/core/constants.dart";
  16. import 'package:photos/core/event_bus.dart';
  17. import "package:photos/db/files_db.dart";
  18. import 'package:photos/ente_theme_data.dart';
  19. import 'package:photos/events/account_configured_event.dart';
  20. import 'package:photos/events/backup_folders_updated_event.dart';
  21. import "package:photos/events/collection_updated_event.dart";
  22. import "package:photos/events/files_updated_event.dart";
  23. import 'package:photos/events/permission_granted_event.dart';
  24. import 'package:photos/events/subscription_purchased_event.dart';
  25. import 'package:photos/events/sync_status_update_event.dart';
  26. import 'package:photos/events/tab_changed_event.dart';
  27. import 'package:photos/events/trigger_logout_event.dart';
  28. import 'package:photos/events/user_logged_out_event.dart';
  29. import "package:photos/generated/l10n.dart";
  30. import 'package:photos/models/collection/collection_items.dart';
  31. import 'package:photos/models/selected_files.dart';
  32. import 'package:photos/services/app_lifecycle_service.dart';
  33. import 'package:photos/services/collections_service.dart';
  34. import "package:photos/services/entity_service.dart";
  35. import "package:photos/services/favorites_service.dart";
  36. import 'package:photos/services/local_sync_service.dart';
  37. import "package:photos/services/notification_service.dart";
  38. import 'package:photos/services/update_service.dart';
  39. import 'package:photos/services/user_service.dart';
  40. import 'package:photos/states/user_details_state.dart';
  41. import 'package:photos/theme/colors.dart';
  42. import "package:photos/theme/effects.dart";
  43. import 'package:photos/theme/ente_theme.dart';
  44. import 'package:photos/ui/collections/collection_action_sheet.dart';
  45. import 'package:photos/ui/extents_page_view.dart';
  46. import 'package:photos/ui/home/grant_permissions_widget.dart';
  47. import 'package:photos/ui/home/header_widget.dart';
  48. import 'package:photos/ui/home/home_bottom_nav_bar.dart';
  49. import 'package:photos/ui/home/home_gallery_widget.dart';
  50. import 'package:photos/ui/home/landing_page_widget.dart';
  51. import "package:photos/ui/home/loading_photos_widget.dart";
  52. import 'package:photos/ui/home/start_backup_hook_widget.dart';
  53. import 'package:photos/ui/notification/update/change_log_page.dart';
  54. import "package:photos/ui/search_tab.dart";
  55. import 'package:photos/ui/settings/app_update_dialog.dart';
  56. import "package:photos/ui/settings_page.dart";
  57. import "package:photos/ui/tabs/shared_collections_tab.dart";
  58. import "package:photos/ui/tabs/user_collections_tab.dart";
  59. import "package:photos/ui/viewer/gallery/collection_page.dart";
  60. import 'package:photos/ui/viewer/search/search_widget.dart';
  61. import 'package:photos/utils/dialog_util.dart';
  62. import "package:photos/utils/navigation_util.dart";
  63. import "package:photos/utils/thumbnail_util.dart";
  64. import 'package:receive_sharing_intent/receive_sharing_intent.dart';
  65. import "package:shared_preferences/shared_preferences.dart";
  66. import 'package:uni_links/uni_links.dart';
  67. final scaffoldKey = GlobalKey<ScaffoldState>();
  68. class HomeWidget extends StatefulWidget {
  69. const HomeWidget({
  70. Key? key,
  71. }) : super(key: key);
  72. @override
  73. State<StatefulWidget> createState() => _HomeWidgetState();
  74. }
  75. class _HomeWidgetState extends State<HomeWidget> {
  76. static const _userCollectionsTab = UserCollectionsTab();
  77. static const _sharedCollectionTab = SharedCollectionsTab();
  78. static const _searchTab = SearchTab();
  79. static final _settingsPage = SettingsPage(
  80. emailNotifier: UserService.instance.emailValueNotifier,
  81. );
  82. static const _headerWidget = HeaderWidget();
  83. final _logger = Logger("HomeWidgetState");
  84. final _selectedFiles = SelectedFiles();
  85. final GlobalKey shareButtonKey = GlobalKey();
  86. final PageController _pageController = PageController();
  87. int _selectedTabIndex = 0;
  88. // for receiving media files
  89. // ignore: unused_field
  90. StreamSubscription? _intentDataStreamSubscription;
  91. List<SharedMediaFile>? _sharedFiles;
  92. bool _shouldRenderCreateCollectionSheet = false;
  93. bool _showShowBackupHook = false;
  94. final isOnSearchTabNotifier = ValueNotifier<bool>(false);
  95. late StreamSubscription<TabChangedEvent> _tabChangedEventSubscription;
  96. late StreamSubscription<SubscriptionPurchasedEvent>
  97. _subscriptionPurchaseEvent;
  98. late StreamSubscription<TriggerLogoutEvent> _triggerLogoutEvent;
  99. late StreamSubscription<UserLoggedOutEvent> _loggedOutEvent;
  100. late StreamSubscription<PermissionGrantedEvent> _permissionGrantedEvent;
  101. late StreamSubscription<SyncStatusUpdate> _firstImportEvent;
  102. late StreamSubscription<BackupFoldersUpdatedEvent> _backupFoldersUpdatedEvent;
  103. late StreamSubscription<AccountConfiguredEvent> _accountConfiguredEvent;
  104. late StreamSubscription<CollectionUpdatedEvent> _collectionUpdatedEvent;
  105. @override
  106. void initState() {
  107. _logger.info("Building initstate");
  108. if (FavoritesService.instance.hasFavorites()) {
  109. WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
  110. initHomeWidget();
  111. });
  112. }
  113. _tabChangedEventSubscription =
  114. Bus.instance.on<TabChangedEvent>().listen((event) {
  115. _selectedTabIndex = event.selectedIndex;
  116. if (event.selectedIndex == 3) {
  117. isOnSearchTabNotifier.value = true;
  118. } else {
  119. isOnSearchTabNotifier.value = false;
  120. }
  121. if (event.source != TabChangedEventSource.pageView) {
  122. debugPrint(
  123. "TabChange going from $_selectedTabIndex to ${event.selectedIndex} souce: ${event.source}",
  124. );
  125. if (_pageController.hasClients) {
  126. _pageController.animateToPage(
  127. event.selectedIndex,
  128. duration: const Duration(milliseconds: 100),
  129. curve: Curves.easeIn,
  130. );
  131. }
  132. }
  133. });
  134. _subscriptionPurchaseEvent =
  135. Bus.instance.on<SubscriptionPurchasedEvent>().listen((event) {
  136. setState(() {});
  137. });
  138. _accountConfiguredEvent =
  139. Bus.instance.on<AccountConfiguredEvent>().listen((event) {
  140. setState(() {});
  141. });
  142. _triggerLogoutEvent =
  143. Bus.instance.on<TriggerLogoutEvent>().listen((event) async {
  144. await _autoLogoutAlert();
  145. });
  146. _loggedOutEvent = Bus.instance.on<UserLoggedOutEvent>().listen((event) {
  147. _logger.info('logged out, selectTab index to 0');
  148. _selectedTabIndex = 0;
  149. if (mounted) {
  150. setState(() {});
  151. }
  152. });
  153. _permissionGrantedEvent =
  154. Bus.instance.on<PermissionGrantedEvent>().listen((event) async {
  155. if (mounted) {
  156. setState(() {});
  157. }
  158. });
  159. _firstImportEvent =
  160. Bus.instance.on<SyncStatusUpdate>().listen((event) async {
  161. if (mounted && event.status == SyncStatus.completedFirstGalleryImport) {
  162. Duration delayInRefresh = const Duration(milliseconds: 0);
  163. // Loading page will redirect to BackupFolderSelectionPage.
  164. // To avoid showing folder hook in middle during routing,
  165. // delay state refresh for home page
  166. if (!LocalSyncService.instance.hasGrantedLimitedPermissions()) {
  167. delayInRefresh = const Duration(milliseconds: 250);
  168. }
  169. Future.delayed(
  170. delayInRefresh,
  171. () => {
  172. if (mounted)
  173. {
  174. setState(
  175. () {},
  176. ),
  177. },
  178. },
  179. );
  180. }
  181. });
  182. _backupFoldersUpdatedEvent =
  183. Bus.instance.on<BackupFoldersUpdatedEvent>().listen((event) async {
  184. if (mounted) {
  185. setState(() {});
  186. }
  187. });
  188. _collectionUpdatedEvent = Bus.instance.on<CollectionUpdatedEvent>().listen(
  189. (event) async {
  190. // only reset state if backup hook is shown. This is to ensure that
  191. // during first sync, we don't keep showing backup hook if user has
  192. // files
  193. if (mounted &&
  194. _showShowBackupHook &&
  195. event.type == EventType.addedOrUpdated) {
  196. setState(() {});
  197. }
  198. },
  199. );
  200. _initDeepLinks();
  201. UpdateService.instance.shouldUpdate().then((shouldUpdate) {
  202. if (shouldUpdate) {
  203. Future.delayed(Duration.zero, () {
  204. showDialog(
  205. context: context,
  206. builder: (BuildContext context) {
  207. return AppUpdateDialog(
  208. UpdateService.instance.getLatestVersionInfo(),
  209. );
  210. },
  211. barrierColor: Colors.black.withOpacity(0.85),
  212. );
  213. });
  214. }
  215. });
  216. // For sharing images coming from outside the app
  217. _initMediaShareSubscription();
  218. WidgetsBinding.instance.addPostFrameCallback(
  219. (_) => Future.delayed(
  220. const Duration(seconds: 1),
  221. () => {
  222. if (mounted) {showChangeLog(context)},
  223. },
  224. ),
  225. );
  226. SharedPreferences.getInstance().then((preferences) {
  227. NotificationService.instance
  228. .init(_onDidReceiveNotificationResponse, preferences);
  229. });
  230. super.initState();
  231. }
  232. Future<void> initHomeWidget() async {
  233. final collectionID =
  234. await FavoritesService.instance.getFavoriteCollectionID();
  235. final res = await FilesDB.instance.getFilesInCollection(
  236. collectionID!,
  237. galleryLoadStartTime,
  238. galleryLoadEndTime,
  239. );
  240. final previousGeneratedId =
  241. await hw.HomeWidget.getWidgetData<int>("home_widget_last_img");
  242. final files = res.files
  243. .where((element) => element.generatedID != previousGeneratedId);
  244. final randomNumber = Random().nextInt(files.length);
  245. final randomFile = files.elementAt(randomNumber);
  246. final cachedThumbnail = await getThumbnailFromServer(randomFile);
  247. var img = Image.memory(cachedThumbnail);
  248. var imgProvider = img.image;
  249. await precacheImage(imgProvider, context);
  250. img = Image.memory(cachedThumbnail);
  251. imgProvider = img.image;
  252. final image = await decodeImageFromList(cachedThumbnail);
  253. final size = min(image.width.toDouble(), image.height.toDouble());
  254. final widget = ClipRRect(
  255. borderRadius: BorderRadius.circular(32),
  256. child: Container(
  257. width: size,
  258. height: size,
  259. decoration: BoxDecoration(
  260. color: Colors.black,
  261. image: DecorationImage(image: imgProvider, fit: BoxFit.cover),
  262. ),
  263. ),
  264. );
  265. await hw.HomeWidget.renderFlutterWidget(
  266. widget,
  267. logicalSize: Size(size, size),
  268. key: "slideshow",
  269. );
  270. await hw.HomeWidget.updateWidget(
  271. name: 'SlideshowWidgetProvider',
  272. androidName: 'SlideshowWidgetProvider',
  273. qualifiedAndroidName: 'io.ente.photos.SlideshowWidgetProvider',
  274. iOSName: 'SlideshowWidget',
  275. );
  276. if (randomFile.generatedID != null) {
  277. await hw.HomeWidget.saveWidgetData<int>(
  278. "home_widget_last_img",
  279. randomFile.generatedID!,
  280. );
  281. }
  282. _logger
  283. .info(">>> HomeWidget rendered with size ${img.width}x${img.height}");
  284. }
  285. Future<void> _autoLogoutAlert() async {
  286. final AlertDialog alert = AlertDialog(
  287. title: Text(S.of(context).sessionExpired),
  288. content: Text(S.of(context).pleaseLoginAgain),
  289. actions: [
  290. TextButton(
  291. child: Text(
  292. S.of(context).ok,
  293. style: TextStyle(
  294. color: Theme.of(context).colorScheme.greenAlternative,
  295. ),
  296. ),
  297. onPressed: () async {
  298. Navigator.of(context, rootNavigator: true).pop('dialog');
  299. Navigator.of(context).popUntil((route) => route.isFirst);
  300. final dialog =
  301. createProgressDialog(context, S.of(context).loggingOut);
  302. await dialog.show();
  303. await Configuration.instance.logout();
  304. await dialog.hide();
  305. },
  306. ),
  307. ],
  308. );
  309. await showDialog(
  310. context: context,
  311. builder: (BuildContext context) {
  312. return alert;
  313. },
  314. );
  315. }
  316. @override
  317. void dispose() {
  318. _tabChangedEventSubscription.cancel();
  319. _subscriptionPurchaseEvent.cancel();
  320. _triggerLogoutEvent.cancel();
  321. _loggedOutEvent.cancel();
  322. _permissionGrantedEvent.cancel();
  323. _firstImportEvent.cancel();
  324. _backupFoldersUpdatedEvent.cancel();
  325. _accountConfiguredEvent.cancel();
  326. _intentDataStreamSubscription?.cancel();
  327. _collectionUpdatedEvent.cancel();
  328. isOnSearchTabNotifier.dispose();
  329. _pageController.dispose();
  330. super.dispose();
  331. }
  332. void _initMediaShareSubscription() {
  333. // For sharing images coming from outside the app while the app is in the memory
  334. _intentDataStreamSubscription =
  335. ReceiveSharingIntent.getMediaStream().listen(
  336. (List<SharedMediaFile> value) {
  337. setState(() {
  338. _shouldRenderCreateCollectionSheet = true;
  339. _sharedFiles = value;
  340. });
  341. },
  342. onError: (err) {
  343. _logger.severe("getIntentDataStream error: $err");
  344. },
  345. );
  346. // For sharing images coming from outside the app while the app is closed
  347. ReceiveSharingIntent.getInitialMedia().then((List<SharedMediaFile> value) {
  348. if (mounted) {
  349. setState(() {
  350. _sharedFiles = value;
  351. _shouldRenderCreateCollectionSheet = true;
  352. });
  353. }
  354. });
  355. }
  356. @override
  357. Widget build(BuildContext context) {
  358. _logger.info("Building home_Widget with tab $_selectedTabIndex");
  359. bool isSettingsOpen = false;
  360. final enableDrawer = LocalSyncService.instance.hasCompletedFirstImport();
  361. final action = AppLifecycleService.instance.mediaExtensionAction.action;
  362. return UserDetailsStateWidget(
  363. child: WillPopScope(
  364. child: Scaffold(
  365. drawerScrimColor: getEnteColorScheme(context).strokeFainter,
  366. drawerEnableOpenDragGesture: false,
  367. //using a hack instead of enabling this as enabling this will create other problems
  368. drawer: enableDrawer
  369. ? ConstrainedBox(
  370. constraints: const BoxConstraints(maxWidth: 430),
  371. child: Drawer(
  372. width: double.infinity,
  373. child: _settingsPage,
  374. ),
  375. )
  376. : null,
  377. onDrawerChanged: (isOpened) => isSettingsOpen = isOpened,
  378. body: SafeArea(
  379. bottom: false,
  380. child: Builder(
  381. builder: (context) {
  382. return _getBody(context);
  383. },
  384. ),
  385. ),
  386. resizeToAvoidBottomInset: false,
  387. ),
  388. onWillPop: () async {
  389. if (_selectedTabIndex == 0) {
  390. if (isSettingsOpen) {
  391. Navigator.pop(context);
  392. return false;
  393. }
  394. if (Platform.isAndroid && action == IntentAction.main) {
  395. unawaited(MoveToBackground.moveTaskToBack());
  396. return false;
  397. } else {
  398. return true;
  399. }
  400. } else {
  401. Bus.instance
  402. .fire(TabChangedEvent(0, TabChangedEventSource.backButton));
  403. return false;
  404. }
  405. },
  406. ),
  407. );
  408. }
  409. Widget _getBody(BuildContext context) {
  410. if (!Configuration.instance.hasConfiguredAccount()) {
  411. _closeDrawerIfOpen(context);
  412. return const LandingPageWidget();
  413. }
  414. if (!LocalSyncService.instance.hasGrantedPermissions()) {
  415. EntityService.instance.syncEntities();
  416. return const GrantPermissionsWidget();
  417. }
  418. if (!LocalSyncService.instance.hasCompletedFirstImport()) {
  419. return const LoadingPhotosWidget();
  420. }
  421. if (_sharedFiles != null &&
  422. _sharedFiles!.isNotEmpty &&
  423. _shouldRenderCreateCollectionSheet) {
  424. //The gallery is getting rebuilt for some reason when the keyboard is up.
  425. //So to stop showing multiple CreateCollectionSheets, this flag
  426. //needs to be set to false the first time it is rendered.
  427. _shouldRenderCreateCollectionSheet = false;
  428. ReceiveSharingIntent.reset();
  429. Future.delayed(const Duration(milliseconds: 10), () {
  430. showCollectionActionSheet(
  431. context,
  432. sharedFiles: _sharedFiles,
  433. actionType: CollectionActionType.addFiles,
  434. );
  435. });
  436. }
  437. _showShowBackupHook =
  438. !Configuration.instance.hasSelectedAnyBackupFolder() &&
  439. !LocalSyncService.instance.hasGrantedLimitedPermissions() &&
  440. CollectionsService.instance.getActiveCollections().isEmpty;
  441. return Stack(
  442. children: [
  443. Builder(
  444. builder: (context) {
  445. return ExtentsPageView(
  446. onPageChanged: (page) {
  447. Bus.instance.fire(
  448. TabChangedEvent(
  449. page,
  450. TabChangedEventSource.pageView,
  451. ),
  452. );
  453. },
  454. controller: _pageController,
  455. openDrawer: Scaffold.of(context).openDrawer,
  456. physics: const BouncingScrollPhysics(),
  457. children: [
  458. _showShowBackupHook
  459. ? const StartBackupHookWidget(headerWidget: _headerWidget)
  460. : HomeGalleryWidget(
  461. header: _headerWidget,
  462. footer: const SizedBox(
  463. height: 160,
  464. ),
  465. selectedFiles: _selectedFiles,
  466. ),
  467. _userCollectionsTab,
  468. _sharedCollectionTab,
  469. _searchTab,
  470. ],
  471. );
  472. },
  473. ),
  474. Align(
  475. alignment: Alignment.bottomCenter,
  476. child: ValueListenableBuilder(
  477. valueListenable: isOnSearchTabNotifier,
  478. builder: (context, value, child) {
  479. return Container(
  480. decoration: value
  481. ? BoxDecoration(
  482. color: getEnteColorScheme(context).backgroundElevated,
  483. boxShadow: shadowFloatFaintLight,
  484. )
  485. : null,
  486. child: Column(
  487. mainAxisSize: MainAxisSize.min,
  488. children: [
  489. value
  490. ? const SearchWidget()
  491. .animate()
  492. .fadeIn(
  493. duration: const Duration(milliseconds: 225),
  494. curve: Curves.easeInOutSine,
  495. )
  496. .scale(
  497. begin: const Offset(0.8, 0.8),
  498. end: const Offset(1, 1),
  499. duration: const Duration(
  500. milliseconds: 225,
  501. ),
  502. curve: Curves.easeInOutSine,
  503. )
  504. .slide(
  505. begin: const Offset(0, 0.4),
  506. curve: Curves.easeInOutSine,
  507. duration: const Duration(
  508. milliseconds: 225,
  509. ),
  510. )
  511. : const SizedBox.shrink(),
  512. HomeBottomNavigationBar(
  513. _selectedFiles,
  514. selectedTabIndex: _selectedTabIndex,
  515. ),
  516. ],
  517. ),
  518. );
  519. },
  520. ),
  521. ),
  522. ],
  523. );
  524. }
  525. void _closeDrawerIfOpen(BuildContext context) {
  526. Scaffold.of(context).isDrawerOpen
  527. ? SchedulerBinding.instance.addPostFrameCallback((timeStamp) {
  528. Scaffold.of(context).closeDrawer();
  529. })
  530. : null;
  531. }
  532. Future<bool> _initDeepLinks() async {
  533. // Platform messages may fail, so we use a try/catch PlatformException.
  534. try {
  535. final String? initialLink = await getInitialLink();
  536. // Parse the link and warn the user, if it is not correct,
  537. // but keep in mind it could be `null`.
  538. if (initialLink != null) {
  539. _logger.info("Initial link received: " + initialLink);
  540. _getCredentials(context, initialLink);
  541. return true;
  542. } else {
  543. _logger.info("No initial link received.");
  544. }
  545. } on PlatformException {
  546. // Handle exception by warning the user their action did not succeed
  547. // return?
  548. _logger.severe("PlatformException thrown while getting initial link");
  549. }
  550. // Attach a listener to the stream
  551. linkStream.listen(
  552. (String? link) {
  553. _logger.info("Link received: " + link!);
  554. _getCredentials(context, link);
  555. },
  556. onError: (err) {
  557. _logger.severe(err);
  558. },
  559. );
  560. return false;
  561. }
  562. void _getCredentials(BuildContext context, String? link) {
  563. if (Configuration.instance.hasConfiguredAccount()) {
  564. return;
  565. }
  566. final ott = Uri.parse(link!).queryParameters["ott"]!;
  567. UserService.instance.verifyEmail(context, ott);
  568. }
  569. showChangeLog(BuildContext context) async {
  570. final bool show = await UpdateService.instance.showChangeLog();
  571. if (!show || !Configuration.instance.isLoggedIn()) {
  572. return;
  573. }
  574. final colorScheme = getEnteColorScheme(context);
  575. await showBarModalBottomSheet(
  576. topControl: const SizedBox.shrink(),
  577. shape: const RoundedRectangleBorder(
  578. borderRadius: BorderRadius.only(
  579. topLeft: Radius.circular(5),
  580. topRight: Radius.circular(5),
  581. ),
  582. ),
  583. backgroundColor: colorScheme.backgroundElevated,
  584. enableDrag: false,
  585. barrierColor: backdropFaintDark,
  586. context: context,
  587. builder: (BuildContext context) {
  588. return Padding(
  589. padding:
  590. EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),
  591. child: const ChangeLogPage(),
  592. );
  593. },
  594. );
  595. // Do not show change dialog again
  596. UpdateService.instance.hideChangeLog().ignore();
  597. }
  598. void _onDidReceiveNotificationResponse(
  599. NotificationResponse notificationResponse,
  600. ) async {
  601. final String? payload = notificationResponse.payload;
  602. if (payload != null) {
  603. debugPrint('notification payload: $payload');
  604. final collectionID = Uri.parse(payload).queryParameters["collectionID"];
  605. if (collectionID != null) {
  606. final collection = CollectionsService.instance
  607. .getCollectionByID(int.parse(collectionID))!;
  608. final thumbnail =
  609. await CollectionsService.instance.getCover(collection);
  610. // ignore: unawaited_futures
  611. routeToPage(
  612. context,
  613. CollectionPage(
  614. CollectionWithThumbnail(
  615. collection,
  616. thumbnail,
  617. ),
  618. ),
  619. );
  620. }
  621. }
  622. }
  623. }