我的应用程序在提交评论后不断崩溃。我相信当Firebase去检索评论数据以显示它时,崩溃就会发生。这仅在尝试提交评论时发生。当我发布照片或喜欢任何帖子时,它不会发生。所以我无法弄清楚为什么我在那里只有一个 Firestore 问题。
这是我的颤振配置:
(base) Indigos-MacBook-Pro:buddies_gram indigoguerra$ flutter doctor -v
[✓] Flutter (Channel stable, v1.17.4, on Mac OS X 10.15 19A603, locale en-US)
• Flutter version 1.17.4 at /Users/indigoguerra/Documents/flutter
• Framework revision 1ad9baa8b9 (12 days ago), 2020-06-17 14:41:16 -0700
• Engine revision ee76268252
• Dart version 2.8.4
[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
• Android SDK at /Users/indigoguerra/Library/Android/sdk
• Platform android-29, build-tools 28.0.3
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 11.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 11.1, Build version 11A1027
• CocoaPods version 1.9.3
[✓] Android Studio (version 3.5)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 43.0.1
• Dart plugin version 191.8593
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
[✓] VS Code (version 1.45.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.11.0
[✓] Connected device (2 available)
• Android SDK built for x86 • emulator-5554 • android-x86 • Android 9 (API 28) (emulator)
• iPhone 11 Pro Max • B133739C-30C8-4C46-A545-7E94D7BAB5A4 • ios • com.apple.CoreSimulator.SimRuntime.iOS-13-1 (simulator)
• No issues found!
这是我的pubspec.yaml依赖项:
version: 1.0.0+1
environment:
sdk: ">=2.1.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
cloud_firestore: ^0.13.7
image: ^2.0.7
animator: 0.1.4
image_picker: ^0.6.0+2
google_sign_in: ^4.0.1+1
timeago: 2.0.17
cached_network_image:
firebase_auth: ^0.16.1
geolocator: 5.0.1
uuid: ^2.0.0
cupertino_icons: ^0.1.2
path_provider: ^0.5.0+1
firebase_messaging: ^4.0.0+1
firebase_storage: ^3.1.6
flutter_image_compress: ^0.6.8
image_cropper: ^1.2.2
flutter_svg:
这是我得到的错误:
*** First throw call stack:
(
0 CoreFoundation 0x00007fff23baa1ee __exceptionPreprocess + 350
1 libobjc.A.dylib 0x00007fff50864b20 objc_exception_throw + 48
2 Runner 0x00000001067317b5 _ZN8firebase9firestore4util16ObjcThrowHandlerENS1_13ExceptionTypeEPKcS4_iRKNSt3__112basic_stringIcNS5_11char_traitsIcEENS5_9allocatorIcEEEE + 581
3 Runner 0x0000000106730cf3 _ZN8firebase9firestore4util5ThrowENS1_13ExceptionTypeEPKcS4_iRKNSt3__112basic_stringIcNS5_11char_traitsIcEENS5_9allocatorIcEEEE + 67
4 Runner <…>
这是保存注释的函数:
saveComment(){
commentsReference.document(postId).collection("comments").add({
"username": currentUser.username,
"comment": commentTextEditingController.text,
"timestamp": DateTime.now(),
"url": currentUser.url,
"userId": currentUser.id,
});
bool isNotPostOwner = postOwnerId != currentUser.id;
if(isNotPostOwner) {
activityFeedReference.document(postOwnerId).collection("feedItems").add({
"type": "comment",
"commentDate": timestamp,
"postId": postId,
"userId": currentUser.id,
"username": currentUser.username,
"userProfileImg": currentUser.url,
"url": postImageUrl,
});
}
commentTextEditingController.clear();
}
有人可以帮我解决这个问题吗?
我想通了。这完全是我的错。 我有
CommentsPageState createState() => CommentsPageState(postId: postId, postOwnerId: postImageUrl, postImageUrl: postImageUrl);
而不是
CommentsPageState createState() => CommentsPageState(postId: postId, postOwnerId: postOwnerId, postImageUrl: postImageUrl);
所以它正在获取postImageUrl链接而不是postOwnerId