Flutter Cloud Firestore fails on calling getDocuments() on iOS - dart

I have an issue with fetching some data from Cloud Firestore in my flutter project. Code is as follows:
void test () async {
var data = await Firestore.instance.collection("markers").getDocuments();
print("${data.documents.length}");
}
However, on the console I get the following:
[VERBOSE-2:shell.cc(178)] Dart Error: Unhandled exception:
NoSuchMethodError: The method '[]' was called on null.
Receiver: null
Tried calling: []("documents")
#0 Object.noSuchMethod (dart:core/runtime/lib/object_patch.dart:50:5)
#1 new QuerySnapshot._ (file:///Users/jacobpyke/Development/flutter/v1/flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.9.6/lib/src/query_snapshot.dart:10:57)
#2 Query.getDocuments (file:///Users/jacobpyke/Development/flutter/v1/flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.9.6/lib/src/query.dart:100:26)
<asynchronous suspension>
#3 HomePage.test (package:KaffeeBar/screens/home/home_page.dart:39:63)
<asynchronous suspension>
#4 HomePage.build (package:KaffeeBar/screens/home/home_page.dart:45:5)
#5 StatelessElement.build (package:flutter/src/widgets/framework.dart:3788:28)
#6 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3735:15)
#7 Element.rebuild (package:flutter/src/widgets/fra<…>
It just struck me as a bit of a strange error. A screenshot of my firestore structure can be seen here: https://imgur.com/a/SeYYlGY
And yes there is data inside the Document, so it shouldnt be returning Null because of no data.
Any help appreciated!
EDIT: Furthermore, all throughout my app the Firestore seems to have stopped working. In some areas its still functions fine, however in some ottthers it returns null values
EDIT2: Seems I tried to compile the app on Android and it flat out doesnt compile due to the Firebase Plugins.
Note: /Users/jacobpyke/Development/flutter/v1/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_core-0.3.1+1/android/src/main/java/io/flutter/plugins/firebase/core/FirebaseCorePlugin.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: /Users/jacobpyke/Development/flutter/v1/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_messaging-4.0.0+1/android/src/main/java/io/flutter/plugins/firebasemessaging/FlutterFirebaseInstanceIDService.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
/Users/jacobpyke/Development/flutter/v1/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_performance-0.1.0+4/android/src/main/java/io/flutter/plugins/firebaseperformance/FirebasePerformancePlugin.java:71: error: cannot access zzf
trace.start();
^
class file for com.google.android.gms.internal.firebase-perf.zzf not found
Note: /Users/jacobpyke/Development/flutter/v1/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_performance-0.1.0+4/android/src/main/java/io/flutter/plugins/firebaseperformance/FirebasePerformancePlugin.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
EDIT 3: After Getting the App to compile, it works perfectly fine on android. So perhaps something wrong with the firebase GoogleInfo-Service.plst

Turns out this issue was a part of a bug within the Cloud Firestore plugin for Flutter. As such, This issue has been resolved as of update 0.9.7. In order to fix the issue, update the cloud firestore plugin in your pubspec.yaml file to cloud_firestore: ^0.9.7 and run flutter packages get Source can be found here

Related

calling Firebase.initializeApp() but still receive an error stating No Firebase App has been created, ONLY when using ios simulator

I have initialized Firebase in different ways.
1.
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(MyApp());
}
#override
void initState() {
super.initState();
Firebase.initializeApp().whenComplete(() {
print("completed");
setState(() {});
});
}
including using FirebaseOption and adding appId, apiKey, projectId, messgingSenderId(dummy id)
//Using a FutureBuilder
atm these libraries are present:
firebase_core: ^1.10.6
firebase_auth: ^3.3.7
cloud_firestore: ^3.1.8
firebase_database: ^9.0.6
firebase_core_platform_interface: ^4.2.4
GogleService-Info.plsit is under flutterProject>ios>Runner
added via Xcode
I'm using a mac
Podfile has platform: ios, '11.0'
printing snapshot.connectionState = waiting & done
I receive an error when trying to persist to the database
I'm using FireStore Database
when trying to persist to the database using the Andriod emulator, I do not receive an error. obj is persisted.
but when trying to persist the same obj using the ios simulator I receive this error:
[core/no-app] No Firebase App '[DEFAULT]' has been created - call Firebase.initializeApp()
When the exception was thrown, this was the stack:
#0 MethodChannelFirebase.app (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:159:5)
#1 Firebase.app (package:firebase_core/src/firebase.dart:55:41)
#2 FirebaseFirestore.instance (package:cloud_firestore/src/firestore.dart:27:21)
#3 _firestore (package:flutter_shopping_app_fraire/providers/products.dart:6:56)
#4 _firestore (package:flutter_shopping_app_fraire/providers/products.dart)
#5 Products.addProduct (package:flutter_shopping_app_fraire/providers/products.dart:71:5)
#6 _EditProductScreenState._saveForm (package:flutter_shopping_app_fraire/screens/edit_product_screen.dart:111:53)
#7 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:989:21)
#8 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:198:24)
#9 TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:608:11)
#10 BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:296:5)
#11 BaseTapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:230:7)
#12 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:563:9)
#13 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:94:12)
#14 PointerRouter._dispatchEventToRoutes.<anonymous closure> (package:flutter/src/gestures/pointer_router.dart:139:9)
#15 _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:539:8)
#16 PointerRouter._dispatchEventToRoutes (package:flutter/src/gestures/pointer_router.dart:137:18)
#17 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:123:7)
#18 GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:439:19)
#19 GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:419:22)
#20 RendererBinding.dispatchEvent (package:flutter/src/rendering/binding.dart:322:11)
#21 GestureBinding._handlePointerEventImmediately (package:flutter/src/gestures/binding.dart:374:7)
#22 GestureBinding.handlePointerEvent (package:flutter/src/gestures/binding.dart:338:5)
#23 GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:296:7)
#24 GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:279:7)
#28 _invoke1 (dart:ui/hooks.dart:170:10)
#29 PlatformDispatcher._dispatchPointerDataPacket (dart:ui/platform_dispatcher.dart:331:7)
#30 _dispatchPointerDataPacket (dart:ui/hooks.dart:94:31)
(elided 3 frames from dart:async)
Handler: "onTap"
Recognizer: TapGestureRecognizer#32df4
debugOwner: GestureDetector
state: possible
won arena
finalPosition: Offset(372.7, 95.0)
finalLocalPosition: Offset(30.7, 48.0)
button: 1
sent tap down
If you have followed all necessary implementation from google docs. Just do the following. I've faced the same issue. Adding options fixed mine.
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
Not sure exactly where I went wrong when implementing firebase/firestore into my flutter project(I was doing everything manually), but I got the ios simulator to connect with firestore database by registering my ios app using FlutterFire CLI.
so instead of manually creating a new firebase project, and registering my ios and android apps through my firebase console, I installed Firebase CLI to my project, then installed FlutterFire CLI and ran flutterfire configure, You go through a couple prompts. That created my project and also registered my apps.
It was really that simple and now both of my ios and andriod can reach the database.

Firebase iOS 6.30.0 SDK Crash - GPBCreateMessageWithAutocreator

After updating to the latest Firebase iOS SDK 6.30.0 with PerformanceMonitoring 3.3.0 using Cocoapods, I have started experiencing the following crash consistently across all iOS versions (iOS 9.0 - iOS 14.0), simulators/devices. The crash does not occur in the previous Firebase SDK 6.29.0 and below.
Thread 3 Queue : com.google.perf.FPREventsQueue (serial)
#0 0x000000010bae3080 in GPBCreateMessageWithAutocreator at /Users/ccaba/Projects/iOSAdswizzSDK/AdswizzSDK/AdswizzSDK/protobuf/GPBMessage.m:626
#1 0x000000010baa2b09 in GPBGetObjectIvarWithField at /Users/ccaba/Projects/iOSAdswizzSDK/AdswizzSDK/AdswizzSDK/protobuf/GPBUtilities.m:605
#2 0x000000010b949962 in FPRGetApplicationInfoMessage ()
#3 0x000000010b9496f3 in FPRGetPerfMetricMessage ()
#4 0x000000010b939477 in __22-[FPRClient logTrace:]_block_invoke ()
#5 0x000000010c379f11 in _dispatch_call_block_and_release ()
...
Sorry if this has already been addressed.
Starting with the 6.23.0 release, FirebaseProtobufBinary must also be included.
ref: https://github.com/firebase/firebase-ios-sdk/blob/master/Carthage.md
Starting with the 6.23.0 release, if you're using FirebaseMessaging, FirebasePerformance, FirebaserRemoteConfig, FirebaseABTesting, FirebaseInAppMessaging, or FirebaseML, FirebaseProtobufBinary must also be included.

mediaDevices.enumerateDevices() Generates Runtime Error in Browser

I am attempting to capture audio from an input source via a web app in a browser using the Dart 2.7.0 SDK. I want to be able to identify the available audio sources on the system so that a user could select among them (rather than relying exclusively on the default source):
captureAudio() async{
List<MediaDeviceInfo> sources = await window.navigator.mediaDevices.enumerateDevices();
// Do more stuff here
// Note that there are numerous differences in media APIs between those listed
// for Dart and the JavaScript APIs shown on MDN. Those differences may or may not
// have any effect on this error
}
The line of code above compiles successfully but is generating an error in Chrome 79.0.3945.88 served from Webdev in Webstorm 2019.3.1 whether in debug mode or not (note: MDN shows that the corresponding JS method call should work in Chrome):
Uncaught (in promise) Error: Type 'List<dynamic>' should be 'List<MediaDeviceInfo>' to implement expected type 'FutureOr<List<MediaDeviceInfo>>'.
DartError dart_sdk.js:5172
throw_ dart_sdk.js:3880
castError dart_sdk.js:3840
cast dart_sdk.js:4159
check_FutureOr dart_sdk.js:27380
(anonymous function) dart_sdk.js:52085
Async call from Promise.then
promiseToFuture dart_sdk.js:52087
[dartx.enumerateDevices] dart_sdk.js:79203
captureAudio capturewebaudio.dart:51
runBody dart_sdk.js:32202
_async dart_sdk.js:32230
captureAudio capturewebaudio.dart:50
(anonymous function) capturewebaudio.dart:40
_checkAndCall dart_sdk.js:4084
dcall dart_sdk.js:4089
(anonymous function) dart_sdk.js:97072
Dart documentation on this topic is essentially non-existent, and given the variations in Dart and JS APIs, I'm not sure what the resolution is to this problem.
This appears to be a bug in the Dart SDK. See bug 39627 on the Dart SDK issues list. The fix is moving through the dev process.

Error: global.nativeTraceBeginSection is not a function

I didnt change anything but suddenly I got this error in my xproject and the app got stuck and thing the when I do simulator through my Xcode is working but not with physical device.
the full log is here:
'Failed to print error: ', 'global.nativeTraceBeginSection is not a function. (In \'global.nativeTraceBeginSection(TRACE_TAG_REACT_APPS, profileName, args)\', \'global.nativeTraceBeginSection\' is undefined)'
WARNING: Logging before InitGoogleLogging() is written to STDERR
E0910 19:37:09.077337 1871998976 JSCHelpers.cpp:137] Got JS Exception: Exception calling object as function: global.nativeTraceEndSection is not a function. (In 'global.nativeTraceEndSection(TRACE_TAG_REACT_APPS)', 'global.nativeTraceEndSection' is undefined) (<unknown file>:2303)
E0910 19:37:09.077525 1871998976 JSCHelpers.cpp:143] Got JS Stack: endEvent#http://192.168.1.27.xip.io:8081/index.bundle?platform=ios&dev=true&minify=false:2303:35
__callFunction#http://192.168.1.27.xip.io:8081/index.bundle?platform=ios&dev=true&minify=false:2098:24
http://192.168.1.27.xip.io:8081/index.bundle?platform=ios&dev=true&minify=false:1927:29
__guard#http://192.168.1.27.xip.io:8081/index.bundle?platform=ios&dev=true&minify=false:2068:11
callFunctionReturnFlushedQueue#http://192.168.1.27.xip.io:8081/index.bundle?platform=ios&dev=true&minify=false:1926:19
callFunctionReturnFlushedQueue#[native code]
2018-09-10 19:37:09.079 [fatal][tid:com.facebook.react.JavaScript] Error calling Systrace.setEnabled
Unhandled JS Exception: Exception calling object as function: global.nativeTraceEndSection is not a function. (In 'global.nativeTraceEndSection(TRACE_TAG_REACT_APPS)', 'global.nativeTraceEndSection' is undefined) (<unknown file>:2303)
2018-09-10 19:37:09.082 [error][tid:com.facebook.react.JavaScript] global.nativeTraceBeginSection is not a function. (In 'global.nativeTraceBeginSection(TRACE_TAG_REACT_APPS, profileName, args)', 'global.nativeTraceBeginSection' is undefined)
2018-09-10 19:37:09.083 [info][tid:com.facebook.react.JavaScript] 'Failed to print error: ', 'Can\'t find variable: regeneratorRuntime'
E0910 19:37:09.086755 1871998976 JSCHelpers.cpp:137] Got JS Exception: Exception calling object as function: global.nativeTraceBeginSection is not a function. (In 'global.nativeTraceBeginSection(TRACE_TAG_REACT_APPS, profileName, args)', 'global.nativeTraceBeginSection' is undefined) (<unknown file>:2298)
E0910 19:37:09.086828 1871998976 JSCHelpers.cpp:143] Got JS Stack: beginEvent#http://192.168.1.27.xip.io:8081/index.bundle?platform=ios&dev=true&minify=false:2298:37
__invokeCallback#http://192.168.1.27.xip.io:8081/index.bundle?platform=ios&dev=true&minify=false:2125:28
http://192.168.1.27.xip.io:8081/index.bundle?platform=ios&dev=true&minify=false:1950:32
__guard#http://192.168.1.27.xip.io:8081/index.bundle?platform=ios&dev=true&minify=false:2068:11
invokeCallbackAndReturnFlushedQueue#http://192.168.1.27.xip.io:8081/index.bundle?platform=ios&dev=true&minify=false:1949:19
invokeCallbackAndReturnFlushedQueue#[native code]
(lldb)
I have been trying to find solution, didn't succeed with any of them.
this error shows on my Xcode logged and not on my screen of the phone
Thank you so much for the help!!
I had the same issue because I unintentionally enabled Start Systrace and since it is a known react native issue... I was getting the error.
What worked for me was just disabling Start Systrace and restarting the project. How I do that?
Command ⌘ + D
Press Disable Start Systrace, that's it!
This is a known, unresolved React Native issue. There are a few workarounds in the GitHub issue, including:
Delete, and then reinstall the app from Xcode or react-native run-ios
Revert to the old bridge (instructions)
See https://github.com/facebook/react-native/issues/15003 for more details.

Native registration to Azure hub always crashes the first time the app is launched

I've made a iOS 7.0 app that use push-notifications and the Azure Mobile services framework. All is good, but I've seen that when I clear my app (e.g., remove it from my phone to force a "first launch" use-case), the app crashes from what I assume is a bug/crash within the Azure framework?
Basically, I'm running the following code-snippet;
//Proceed and register
SBNotificationHub* hub = [[SBNotificationHub alloc] initWithConnectionString:notificationConnectionString
notificationHubPath:notificationHub];
DDLogInfo(#"Hub object = %#", hub);
//Register with native hub...
NSError* error = nil;
if (![hub registerNativeWithDeviceToken:deviceToken tags:nil error:&error])
{
//False
DDLogInfo(#"Failed to register with native hub...");
if (error)
DDLogError(#"Found error; %#", error.localizedDescription);
}
... and when registerNativeWithDeviceToken: is executed, my app crashes with the following exception;
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** setObjectForKey: key cannot be nil'
Enabling breakpoint exceptions show the following trace, indicating that it's the SBLocalStorage class, part of the Azure framework, that try to put nil in a NSDictionary;
Thread 4, Queue : NSManagedObjectContext Queue
#0 0x3bc7e1f0 in __pthread_kill ()
#9 0x30e6e1be in -[__NSDictionaryM setObject:forKey:] ()
#10 0x0022afa8 in -[SBLocalStorage updateWithRegistrationName:registration:] at /Users/admin/Desktop/Main/enlist/WindowsAzureMessaging/WindowsAzureMessaging/Helpers/SBLocalStorage.m:89
#11 0x0022ae4c in -[SBLocalStorage updateWithRegistration:] at /Users/admin/Desktop/Main/enlist/WindowsAzureMessaging/WindowsAzureMessaging/Helpers/SBLocalStorage.m:70
#12 0x00227d76 in -[SBNotificationHub retrieveAllRegistrationsWithDeviceToken:error:] at /Users/admin/Desktop/Main/enlist/WindowsAzureMessaging/WindowsAzureMessaging/SBNotificationHub.m:700
#13 0x00227202 in -[SBNotificationHub registerNativeWithDeviceToken:tags:error:] at /Users/admin/Desktop/Main/enlist/WindowsAzureMessaging/WindowsAzureMessaging/SBNotificationHub.m:458
#14 0x000b6788 in -[BackendCommunicator registerPushNotificationsForDeviceToken:] at /Users/markus/Xcode/MyApp/myApp/BackendCommunicator.m:1632
But, regardless, has anyone else seen this? And moreover, why does it work all consecutive launches, BUT NOT the first?
Best,
/Markus
I tried to reproduce the issue you described, but for me SDK works OK at this scenario. However I found and fixed serious bug.
Latest version is available on Git Hub, I've also uploaded ready-to-use binaries for your convenience: https://github.com/Azure/azure-notificationhubs/tree/master/iOS/bin.
So I would suggest you to try if it works after last fixes.

Resources