From 0006a94632c3961c285b8bb0f35569b88fc82ffc Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Mon, 19 Aug 2024 09:19:29 +0800 Subject: [PATCH] :bug: Fix local db old data cause crash --- ios/Runner.xcodeproj/project.pbxproj | 29 ++++++++++++++++---- lib/models/event.dart | 2 +- lib/widgets/attachments/attachment_list.dart | 1 + lib/widgets/chat/chat_event.dart | 2 +- lib/widgets/posts/post_item.dart | 2 +- 5 files changed, 28 insertions(+), 8 deletions(-) diff --git a/ios/Runner.xcodeproj/project.pbxproj b/ios/Runner.xcodeproj/project.pbxproj index 44314ce..80bce2c 100644 --- a/ios/Runner.xcodeproj/project.pbxproj +++ b/ios/Runner.xcodeproj/project.pbxproj @@ -254,6 +254,7 @@ buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */; buildPhases = ( B1CDA9DD5B638A2BB88053CB /* [CP] Check Pods Manifest.lock */, + 7356FAC42C72724B0051A465 /* [Crashlytics] Clear dSYM */, 9740EEB61CF901F6004384FC /* Run Script */, 97C146EA1CF9000F007C117D /* Sources */, 97C146EB1CF9000F007C117D /* Frameworks */, @@ -263,7 +264,7 @@ 3B06AD1E1E4923F5004D2608 /* Thin Binary */, 287A33C298CA352A7E7F32A4 /* [CP] Embed Pods Frameworks */, 0818E8E4321C0D7433E07576 /* [CP] Copy Pods Resources */, - 1A9FD6BE5DEE99CDA7399504 /* FlutterFire: "flutterfire upload-crashlytics-symbols" */, + 1A9FD6BE5DEE99CDA7399504 /* [Crashlytics] Upload dSYM */, ); buildRules = ( ); @@ -366,7 +367,7 @@ shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources.sh\"\n"; showEnvVarsInLog = 0; }; - 1A9FD6BE5DEE99CDA7399504 /* FlutterFire: "flutterfire upload-crashlytics-symbols" */ = { + 1A9FD6BE5DEE99CDA7399504 /* [Crashlytics] Upload dSYM */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( @@ -375,14 +376,14 @@ ); inputPaths = ( ); - name = "FlutterFire: \"flutterfire upload-crashlytics-symbols\""; + name = "[Crashlytics] Upload dSYM"; outputFileListPaths = ( ); outputPaths = ( ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "\n#!/bin/bash\nPATH=${PATH}:$FLUTTER_ROOT/bin:$HOME/.pub-cache/bin\nflutterfire upload-crashlytics-symbols --upload-symbols-script-path=$PODS_ROOT/FirebaseCrashlytics/upload-symbols --platform=ios --apple-project-path=${SRCROOT} --env-platform-name=${PLATFORM_NAME} --env-configuration=${CONFIGURATION} --env-project-dir=${PROJECT_DIR} --env-built-products-dir=${BUILT_PRODUCTS_DIR} --env-dwarf-dsym-folder-path=${DWARF_DSYM_FOLDER_PATH} --env-dwarf-dsym-file-name=${DWARF_DSYM_FILE_NAME} --env-infoplist-path=${INFOPLIST_PATH} --default-config=default\n"; + shellScript = "\n#!/bin/bash\nsleep 1 # Without this, there seems a chance that the script runs before dSYM generation is finished \n$PODS_ROOT/FirebaseCrashlytics/upload-symbols -gsp $PROJECT_DIR/Runner/GoogleService-Info.plist -p ios $DWARF_DSYM_FOLDER_PATH/$DWARF_DSYM_FILE_NAME\n"; }; 259653AE41D478F4C6BAE9B2 /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; @@ -439,6 +440,24 @@ shellPath = /bin/sh; shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin"; }; + 7356FAC42C72724B0051A465 /* [Crashlytics] Clear dSYM */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + ); + name = "[Crashlytics] Clear dSYM"; + outputFileListPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\n#!/bin/bash\nrm -rf $DWARF_DSYM_FOLDER_PATH/$DWARF_DSYM_FILE_NAME\n"; + }; 9740EEB61CF901F6004384FC /* Run Script */ = { isa = PBXShellScriptBuildPhase; alwaysOutOfDate = 1; @@ -452,7 +471,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build"; + shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build\n"; }; B1CDA9DD5B638A2BB88053CB /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; diff --git a/lib/models/event.dart b/lib/models/event.dart index c138992..a5ed28b 100644 --- a/lib/models/event.dart +++ b/lib/models/event.dart @@ -82,7 +82,7 @@ class EventMessageBody { text: json['text'] ?? '', algorithm: json['algorithm'] ?? 'plain', attachments: json['attachments'] != null - ? List.from(json['attachments'].map((x) => x)) + ? List.from(json['attachments']?.whereType()) : null, quoteEvent: json['quote_event'], relatedEvent: json['related_event'], diff --git a/lib/widgets/attachments/attachment_list.dart b/lib/widgets/attachments/attachment_list.dart index 49626c9..231edfd 100644 --- a/lib/widgets/attachments/attachment_list.dart +++ b/lib/widgets/attachments/attachment_list.dart @@ -72,6 +72,7 @@ class _AttachmentListState extends State { double? consistentValue; int portrait = 0, square = 0, landscape = 0; for (var entry in _attachmentsMeta) { + if (entry == null) continue; if (entry!.metadata?['ratio'] != null) { if (entry.metadata?['ratio'] is int) { consistentValue ??= entry.metadata?['ratio'].toDouble(); diff --git a/lib/widgets/chat/chat_event.dart b/lib/widgets/chat/chat_event.dart index fe06956..956c5a3 100644 --- a/lib/widgets/chat/chat_event.dart +++ b/lib/widgets/chat/chat_event.dart @@ -39,7 +39,7 @@ class ChatEvent extends StatelessWidget { Widget _buildAttachment(BuildContext context, {bool isMinimal = false}) { final attachments = item.body['attachments'] != null - ? List.from(item.body['attachments'].map((x) => x)) + ? List.from(item.body['attachments']?.whereType()) : List.empty(); if (attachments.isEmpty) return const SizedBox(); diff --git a/lib/widgets/posts/post_item.dart b/lib/widgets/posts/post_item.dart index e6431cd..35da428 100644 --- a/lib/widgets/posts/post_item.dart +++ b/lib/widgets/posts/post_item.dart @@ -293,7 +293,7 @@ class _PostItemState extends State { @override Widget build(BuildContext context) { final List attachments = item.body['attachments'] is List - ? item.body['attachments']?.cast() + ? List.from(item.body['attachments']?.whereType()) : List.empty(); final hasAttachment = attachments.isNotEmpty;