0

this is the first page

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

this is the second page


    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],
          );
        },
      ),
    );

this the third page and it's to show the data of user

  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),
            ),
          )
        ],
      ),
    );
  }
}

the problem is when i navigate to the first page it show me red page then shows me the data normally and it gives me this error .


The following NoSuchMethodError was thrown building Profiledata(dirty, dependencies: [_InheritedProviderScope<List>], state: _ProfiledataState#ed00b): The getter 'length' was called on null. Receiver: null Tried calling: length

JideGuru
  • 7,102
  • 6
  • 26
  • 48

1 Answers1

0

Sometimes it takes time to fetch data. Change your second page code like below

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

return Scaffold(
  appBar: AppBar(),
  body: (users.length > 0) ?  ListView.builder(
    itemCount: users.length,
    itemBuilder: (context, index) {
      return ProfileDatau(
        user: users[index],
      );
    },
  ) : CircularProgressIndicator();
);
Fahmida
  • 1,050
  • 8
  • 19