简体   繁体   中英

_TypeError (type 'Null' is not a subtype of type 'String') firebase firestore

I am trying to retrieve data from my cloud firestore but it keeps returning a type error. This is the code for firestore

    await firestore
    .collection('users')
    .where("email", isEqualTo: _search.text)
    .get()
    .then((value) {
  if (value.docs.isNotEmpty) {
    setState(() {
      userMap = value.docs[0].data();
      isLoading = false;
    });
  }

This is where the error "_TypeError (type 'Null' is not a subtype of type 'String')" occurs

                      ListTile(
                    onTap: () {},
                    title: Text(
                      userMap["name"],
                      style: const TextStyle(fontWeight: FontWeight.bold),
                    ),
                    subtitle: Text(userMap["email"])

Text widget doesnt accept null value, you can provide default value on null cases like

Text(userMap["name"]??"got NUll",)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM