Home > Blockchain >  do not return the widget that has an empty container flutter
do not return the widget that has an empty container flutter

Time:10-14

I have a method that returns a list of widgets. each widget has a futurebuilder. if there is no data it returns an empty container. I don't want to return widgets that have an empty container in the method.

 List<Widget> _widgetList() {
    List<Widget> list = [
      widget1(),
       widget2(),
    ];

    return list;
  } 

CodePudding user response:

List<Widget>? widget1() {
//Your function 
  return null; // return List<Widget>?;
}

List<Widget> _widgetList() {
  List<Widget> list = [];
  List<Widget>? listWidget1 = widget1();
    List<Widget>? listWidget2 = widget2();

  if (listWidget1 != null) {
    list.addAll(listWidget1);
  }
  if (listWidget2 != null) {
    list.addAll(listWidget2);
  }
  return list;
}


CodePudding user response:

I did it as shown in the below link and it worked for me https://api.flutter.dev/flutter/widgets/FutureBuilder-class.html

  • Related