我可以从我的应用程序中成功读取和写入云 Firestore 数据库。但是,当在 iOS 模拟器(或真实设备)上运行时,我无法通过 Riverpod 或标准 StreamBuilder 监听流以实时更改文档。收听流时不会引发错误或异常。流存在,只是其中没有数据。在 Android 模拟器上运行时不存在此问题。
流提供者
final athletePosStreamProvider = StreamProvider<GPSPoint>((ref) {
final _fsDB = FirebaseFirestore.instance;
print('Provider is active');
return _fsDB.collection('Athlete1').doc('currentPosition').snapshots().map((document) {
print('stream data found');
return GPSPoint.fromFSMap(document.data());
});
});
流听:
final athletePos = Provider<GPSPoint>((ref) {
GPSPoint _curPos;
print('athletePos is active');
Stream _docStream = FirebaseFirestore.instance.collection('Athlete1').doc('currentPosition').snapshots();
if (_docStream.isBroadcast == true) {
print('Stream is broadcasting');
}
_docStream.listen((event) {
print('athletePos stream event received');
_curPos = GPSPoint.fromFSMap(event.data());
});
return _curPos;
});
在这两种情况下,第一个 print 语句都会触发,但第二个 print 语句永远不会在 iOS 上触发。它将在 Android 上正常工作。
pubspec.yaml
cloud_firestore: ^0.14.3+1
flutter_riverpod: ^0.12.1
扑医生
[✓] Flutter (Channel beta, 1.24.0-10.2.pre, on Mac OS X 10.15.7 19H15 darwin-x64, locale en-US)
• Flutter version 1.24.0-10.2.pre at /Users/sgalway/development/flutter
• Framework revision 022b333a08 (11 days ago), 2020-11-18 11:35:09 -0800
• Engine revision 07c1eed46b
• Dart version 2.12.0 (build 2.12.0-29.10.beta)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at /Users/sgalway/Library/Android/sdk
• Platform android-29, build-tools 29.0.2
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 12.2)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 12.2, Build version 12B45b
• CocoaPods version 1.10.0
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 4.0)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 48.1.2
• Dart plugin version 193.7361
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
[✓] IntelliJ IDEA Community Edition (version 2020.1.2)
• IntelliJ at /Applications/IntelliJ IDEA CE.app
• Flutter plugin version 47.1.3
• Dart plugin version 201.7846.93
[✓] VS Code (version 1.51.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.16.0
[✓] Connected device (3 available)
• iPhone 11 Pro (mobile) • 21B0C3BA-D8B9-4AF2-81A5-FC8176E49F24 • ios •
com.apple.CoreSimulator.SimRuntime.iOS-14-2 (simulator)
• Web Server (web) • web-server • web-javascript • Flutter Tools
• Chrome (web) • chrome • web-javascript • Google Chrome 86.0.4240.198
• No issues found!