I'm trying to follow along this 2 year old Fluter tutorial on Udemy its based on a ride sharing app, but I've come to a halt. am receiving this error
The operator '[]' isn't defined for the type 'Object'. Try defining the operator '[]'.
My flutter sdk version is 2.11.0
User.fromSnapshot(DataSnapshot snapshot) {
id = snapshot.key;
phone = snapshot.value['phone'];//here is the error
email = snapshot.value['email'];//here is the error
fullName = snapshot.value['fullname'];//here is the error
//phone = snap
}
import 'package:firebase_database/firebase_database.dart';
class User {
String fullName;
String email;
String phone;
String id;
User({
this.fullName,
this.email,
this.phone,
this.id,
});
User.fromSnapshot(DataSnapshot snapshot) {
id = snapshot.key;
phone = snapshot.value['phone'];
email = snapshot.value['email'];
fullName = snapshot.value['fullname'];
//phone = snap
}
}
Change the type to Map<String, dynamic>
instead of DataSnapshot
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.