skip to Main Content
appBar: AppBar(
    title: StreamBuilder<DocumentSnapshot>(
        stream:  _firestore.collection('users').doc(userMap['uid']).snapshots(),
        builder: (context, snapshot){
          if (snapshot.data != null){
            return Container(
              child: Column(
                children: [
                  Text(userMap['name']),
                  Text(
                    snapshot.data!.data()['status'],
                    style: TextStyle(fontSize: 14),
                  )
                ],
              ),
            );
          }else{
            return Container();
          }
        }

I try to check the status of the user and show in the appbar if the user is online or offline, I already create a variable for that and It’s work proprely but when I want to show the status in the appbar I have this error.

snapshot.data!.data()['status'],

the error is on this line
if somoene can help that will be cool.

2

Answers


  1. do it like this and put the whole object in a set of parenthesis:

    (snapshot.data!.data())['status'],
    
    Login or Signup to reply.
  2. Try this:
    (snapshot.data!.data() as Map<String, dynamic>)['status'],

    Dart doesn’t know which type of object it is getting.

    See reference:
    The operator '[]' isn't defined for the class 'Object'. Dart

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search