Reputation: 1
After updating my flutter plugin i had to update my code because I was receiving error like this 'Firestore' is deprecated and shouldn't be used. Class Firestore is deprecated, use 'FirebaseFirestore' instead..
I followed the warnings and update my code but now one my streamBuilders is not working I don't know why.
here my code
class PickupLayout extends StatelessWidget {
final Widget scaffold;
final CallMethods callMethods = CallMethods();
PickupLayout({
@required this.scaffold,
});
@override
Widget build(BuildContext context) {
final UserProvider userProvider = Provider.of<UserProvider>(context);
return (userProvider != null && userProvider.getUser != null)
? StreamBuilder<DocumentSnapshot>(
stream: callMethods.callStream(uid: userProvider.getUser.uid),
builder: (context, snapshot) {
if (snapshot.hasData && snapshot.data.data != null) {
Call call = Call.fromMap(snapshot.data.data());
if (!call.hasDialled) {
return PickupScreen(call: call);
}
}
return scaffold;
},
)
: Scaffold(
body: Center(
child: CircularProgressIndicator(),
),
);
}
}
here is the error
════════ Exception caught by widgets library ═══════════════════════════════════
The following NoSuchMethodError was thrown building StreamBuilder<DocumentSnapshot>(dirty, state: _StreamBuilderBaseState<DocumentSnapshot, AsyncSnapshot<DocumentSnapshot>>#a2802):
The method '[]' was called on null.
Receiver: null
Tried calling: []("caller_id")
The relevant error-causing widget was
StreamBuilder<DocumentSnapshot>
package:vdb_tinus_app/…/pickup/pickup_layout.dart:22
When the exception was thrown, this was the stack
#0 Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
#1 new Call.fromMap
package:vdb_tinus_app/…/models/call.dart:37
#2 PickupLayout.build.<anonymous closure>
package:vdb_tinus_app/…/pickup/pickup_layout.dart:26
#3 StreamBuilder.build
package:flutter/…/widgets/async.dart:525
#4 _StreamBuilderBaseState.build
This the line with error according to log before updating my cloud firestore plung in it used to look like this if (snapshot.hasData && snapshot.data.data != null) { Call call = Call.fromMap(snapshot.data.data);
after updating i had to change it to this if (snapshot.hasData && snapshot.data.data != null) { Call call = Call.fromMap(snapshot.data.data());
Upvotes: 0
Views: 528
Reputation: 1343
In this part;
if (snapshot.hasData && snapshot.data.data != null) {
Call call = Call.fromMap(snapshot.data.data());
if (!call.hasDialled) {
return PickupScreen(call: call);
}
}
you should use this part like that;
if (snapshot.hasData && snapshot.data.data() != null) {
Apart from this project, You shouldn't try to make an video calling app if you are new to flutter. I know that you take this code from a video
Upvotes: 0
Reputation: 5190
In this line, if (snapshot.hasData && snapshot.data.data != null) {
, you are checking whether DocumentSnapshot.data
is null. Since it is a function (therefore, an object), your comparison never evaluates as false
.
In the next line, snapshot.data.data()
, you are calling the above function, whose return value might very well be null
.
Upvotes: 1