dart 没有为类型“Object”定义运算符“[]”,请尝试定义运算符“[]”

xkftehaa  于 2022-12-16  发布在  其他
关注(0)|答案(1)|浏览(140)

我试图沿着这个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
  }
}
von4xj4u

von4xj4u1#

将类型更改为Map<String, dynamic>,而不是DataSnapshot

相关问题