From bf2760ffefb22a74a5d49293577f5694eef9e81d Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 24 Aug 2022 21:31:20 -0700 Subject: [PATCH] Fixed mobile timeline crash when date group cannot be parsed (#530) * Handle error when datetime is incorrect * Added better debug message --- mobile/lib/modules/home/views/home_page.dart | 64 +++++++++++--------- 1 file changed, 36 insertions(+), 28 deletions(-) diff --git a/mobile/lib/modules/home/views/home_page.dart b/mobile/lib/modules/home/views/home_page.dart index 6c9362c13e..46a6c29d74 100644 --- a/mobile/lib/modules/home/views/home_page.dart +++ b/mobile/lib/modules/home/views/home_page.dart @@ -65,37 +65,45 @@ class HomePage extends HookConsumerWidget { int? lastMonth; assetGroupByDateTime.forEach((dateGroup, immichAssetList) { - DateTime parseDateGroup = DateTime.parse(dateGroup); - int currentMonth = parseDateGroup.month; + try { + DateTime parseDateGroup = DateTime.parse(dateGroup); + int currentMonth = parseDateGroup.month; - if (lastMonth != null) { - if (currentMonth - lastMonth! != 0) { - imageGridGroup.add( - MonthlyTitleText( - isoDate: dateGroup, - ), - ); + if (lastMonth != null) { + if (currentMonth - lastMonth! != 0) { + imageGridGroup.add( + MonthlyTitleText( + isoDate: dateGroup, + ), + ); + } } + + imageGridGroup.add( + DailyTitleText( + key: Key('${dateGroup.toString()}title'), + isoDate: dateGroup, + assetGroup: immichAssetList, + ), + ); + + imageGridGroup.add( + ImageGrid( + assetGroup: immichAssetList, + sortedAssetGroup: sortedAssetList, + tilesPerRow: + appSettingService.getSetting(AppSettingsEnum.tilesPerRow), + showStorageIndicator: appSettingService + .getSetting(AppSettingsEnum.storageIndicator), + ), + ); + + lastMonth = currentMonth; + } catch (e) { + debugPrint( + "[ERROR] Cannot parse $dateGroup - Wrong create date format : ${immichAssetList.map((asset) => asset.createdAt).toList()}", + ); } - - imageGridGroup.add( - DailyTitleText( - key: Key('${dateGroup.toString()}title'), - isoDate: dateGroup, - assetGroup: immichAssetList, - ), - ); - - imageGridGroup.add( - ImageGrid( - assetGroup: immichAssetList, - sortedAssetGroup: sortedAssetList, - tilesPerRow: appSettingService.getSetting(AppSettingsEnum.tilesPerRow), - showStorageIndicator: appSettingService.getSetting(AppSettingsEnum.storageIndicator), - ), - ); - - lastMonth = currentMonth; }); }