title: The operator '[]' isn't defined for the type 'Object'. Try defining the operator '[]'. Error when trying to get data from Firestore
body: <p>I am trying to retrieve data from a document stored in Firestore. I've tried several times to find a way to fix this error but haven't been able to find something useful.</p>
  <p>Here's my code.</p>
  <pre><code>import 'package:cloud_firestore/cloud_firestore.dart';
  import 'package:flutter/material.dart';
  
  class GetUserName extends StatelessWidget {
    final String documentId;
  
    GetUserName(this.documentId);
  
    @override
    Widget build(BuildContext context) {
      CollectionReference users = FirebaseFirestore.instance.collection('Drivers');
  
      return FutureBuilder&lt;DocumentSnapshot&gt;(
        future: users.doc(documentId).get(),
        builder:
            (BuildContext context, AsyncSnapshot&lt;DocumentSnapshot&gt; snapshot) {
  
          if (snapshot.hasError) {
            return Text(&quot;Something went wrong&quot;);
          }
  
          if (snapshot.hasData &amp;&amp; !snapshot.data!.exists) {
            return Text(&quot;Document does not exist&quot;);
          }
  
          if (snapshot.connectionState == ConnectionState.done) {
            Object? data = snapshot.data!.data();
            return Text(data!['username']);
          }
  
          return Text(&quot;loading&quot;);
        },
      );
    }
  }
  </code></pre>
  <p>The error happens when I try to retrieve 'username' from data.</p>
  <p>Thanks for your help</p>