Sunday, July 17, 2022

[FIXED] How to show custom warning when FutureBuilder snapshot data equals to 0 (zero)?

Issue

In my Flutter app body section I use FutureBuilder. If snapshot.hasData then I show the Data in body. My problem is that sometimes the snapshot data is 0 (zero). I need to use stack or similar to show user a warning with stating that “currently data is not available”. How do I do that?

body: new Center(
  child: new FutureBuilder(
      future: getCurrencyJsonData(),
      builder: (context, snaphot) {
        if (snaphot.hasData) {
          return new ListView(

Solution

Just add a if into your builder..

 if (snaphot.data.length == 0) {
     return new Stack(...);
 }


Answered By - Rémi Rousselet
Answer Checked By - Timothy Miller (PHPFixing Admin)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.