我试图沿着这个2岁的Flutter教程Udemy它的基础上乘坐共享应用程序,但我已经停了下来。我收到这个错误
没有为类型“Object”定义运算符“[]”。请尝试定义运算符“[]”。
我的flutter sdk版本是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
}
}
1条答案
按热度按时间von4xj4u1#
将类型更改为
Map<String, dynamic>
,而不是DataSnapshot