Tizi Dev
Tizi Dev

Reputation: 311

Handle Null value from cloud firestore if Text is null or not filled by user

how to handle if text field return null and substitute with text for example " NOT AVAILABLE " I have this text field for example:

Text(
                                                  "${data['name']}",
                                                  style: TextStyle(
                                                      fontSize: 15,
                                                      fontWeight:
                                                          FontWeight.w300,
                                                      color: Colors.white),
                                                ),

in this case if collection from cloud firestore is null

Upvotes: 0

Views: 38

Answers (1)

Ruben Röhner
Ruben Röhner

Reputation: 601

You can do it like this:

Text(
    data.['name'] ?? "Not available",
     style: TextStyle(
         fontSize: 15,
         fontWeight: FontWeight.w300,
         color: Colors.white),
      ),
),

Upvotes: 2

Related Questions