Detecting Connection State Called Twice
What you're seeing is the expected behavior.
The .info/connected
flag determines whether the app/client is connected to the Firebase Database backend. While this of course requires that you have an internet connection, there is more to it than that. That's why it is possible for .info/connected
to be false
even though you have a working internet connection.
This is especially true when you start the app. It takes a few moments after the app starts before the Firebase client is connected to its database server, so usually the .info/connected
value starts as false
and then becomes true
. Sometimes it even toggles a few times before settling.
Also see:
- How to handle internet connection status Firebase
- Firebase connection state listener returns false in javascript
My function always returns false the first time
Your method testLogin
is incorrect. Method dataTaskWithRequest
is asynchronous. You need to create two callbacks success
and failure
(closures). Which will be called if request completes. Look at this https://github.com/Alamofire/Alamofire.
Flutter StreamBuilder connectionState problem with firestore
connectionState is never equal to true because it's simply not a boolean value.
As you noticed, it's an ConnectionState enum value, so if you want to check a connectionState of AsyncSnapshot, you have to compare it to a ConnectionsState enum value. So for example if you want to know whether stream has loaded you need to check if state is different than waiting: (you have observed it by yourself with print statements)
if(streamSnapshot1.connectionState
!= ConnectionState.waiting) {
//stream has loaded some first values
}
Related Topics
Xcode Failed to Resolve Dependency Firebase - Googleappmeasurement Does Not Match Requirement
How to Get .Adjustsfontsizetofitwidth to Function Properly
How to Assign a Generic Function to a Variable
Avaudioconverter with Avaudioconverterinputblock Stutters Audio After Processing
Why How to Make Same-Type Requirement in Swift with Generics? Is There Any Way
Navigation Bar Items After Push from Swiftui to UIkit
Nstoolbarflexiblespaceitem Is Constraint to Nssplitviewitem in Swift
Naming Convention for Private Properties
Swift Difference Between Double and Float64
How to Find Realm File Location of a MAC App
How to Access The Firebase Topics a User Is Subscribed To
Mapping Swift Combine Future to Another Future
How to Disable The Automatic Activation of an Arcoachingoverlayview
Pfobject Unable to Be Cast to Custom Subclass
Show and Hide Window Instead of Terminating App on Close Click in Cocoa App