getter'length'在null上被调用。接收方null尝试调用``长度''列表。

时间:2020-07-16 21:58:40

标签: flutter

这是第一页

return StreamProvider<List<User>>.value(
  value: DatabaseServ().usersData,
  child: Profiledata(),
);

这是第二页


    final users = Provider.of<List<User>>(context);

    return Scaffold(
      appBar: AppBar(),
      body: ListView.builder(
        itemCount: users.length,
        itemBuilder: (context, index) {
          return ProfileDatau(
            user: users[index],
          );
        },
      ),
    );

这是第三页,用于显示用户数据

  final AuthService _auth = AuthService();
  final User user;

  ProfileDatau({this.user});

  @override
  Widget build(BuildContext context) {
    return Card(
      child: Column(
        children: <Widget>[
          // this container for icon of the profile

          Container(
            // this for the icon to change the image

            child: Container(
              margin: EdgeInsets.fromLTRB(100, 110, 20, 10),
              width: 50,
              height: 50,
              decoration: BoxDecoration(
                shape: BoxShape.circle,
                color: Colors.grey[500],
              ),
              child: FlatButton(
                padding: EdgeInsets.all(0),
                onPressed: () {
                  print('to change image');
                },
                child: Icon(
                  Icons.add,
                ),
              ),
            ),

            // this is for the image it self

            margin: EdgeInsets.fromLTRB(130, 35, 130, 35),
            width: 200,
            height: 150,
            decoration: BoxDecoration(
              shape: BoxShape.circle,
              image: DecorationImage(
                image: AssetImage('images/angel.png'),
                fit: BoxFit.fill,
              ),
            ),
          ),

          // this container for the filed under the image like name , information etc..

          FlatButton(
            padding: EdgeInsets.all(0),
            child: Container(
              height: 50,
              width: 400,
              decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(20),
                  color: Colors.grey[400]),
              margin: EdgeInsets.fromLTRB(10, 10, 10, 0),
              padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
              child: Center(
                child: Text(
                  user.name,
                  style: TextStyle(),
                ),
              ),
            ),
            onPressed: () {
              print('pressed');
            },
          ),
          Container(
            height: 50,
            width: 400,
            decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(20),
                color: Colors.grey[400]),
            margin: EdgeInsets.fromLTRB(10, 10, 10, 0),
            padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
            child: Center(
              child: Text(
                'hello there',
                style: TextStyle(),
              ),
            ),
          ),
          Container(
            height: 50,
            width: 400,
            decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(20),
                color: Colors.grey[400]),
            margin: EdgeInsets.fromLTRB(10, 10, 10, 0),
            padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
            child: Center(
              child: Text(
                'hello there',
                style: TextStyle(),
              ),
            ),
          ),
          Container(
            child: FlatButton(
              onPressed: () async {
                await _auth.signOut();
              },
              child: Icon(Icons.highlight_off),
            ),
          )
        ],
      ),
    );
  }
}

问题是当我导航到第一页时,它显示红色页面,然后正常显示数据 这给了我这个错误。


在构建Profiledata(脏,依赖项:[_ InheritedProviderScope <列表>],状态:_ProfiledataState#ed00b)时引发了以下NoSuchMethodError: getter'length'在null上被调用。 接收者:null 尝试致电:长度

0 个答案:

没有答案