使用 If Condition return 语句的 ListView Builder 需要空白 space

ListView Builder using If Condition return statement needed for blank space

ListView 看起来像我希望的那样,但我还没有找到让我在那里结束它的 else 语句的选项。现在我可以在那里放一个文本小部件,但是当用户垂直滚动时它会继续生成这些无限次。我希望能够在 singleChildScrollView 之后停止 ListView。

已尝试使用空容器,SizedBox.shrink。以及高度和宽度为 0.0.

的 SizedBox
 child: ListView.builder(itemBuilder: (context, index) {
            if (index == 0) {
              return Container(
                margin: EdgeInsets.all(20.0),
                alignment: Alignment.center,
                child: Image.file(photos[0].name),
              );
            }
            else if (index == 1) {
              var singleChildScrollView = SingleChildScrollView(
                child: Row(
                  children: pics,
                ),
                scrollDirection: Axis.horizontal,
              );
              return singleChildScrollView;
            }
            else {
              return Text('empty space');
            }
          }),

尝试向列表视图添加一个 itemCount,例如:

child: ListView.builder(
            itemCount: 3, 
            itemBuilder: (context, index) {
            if (index == 0) {
              return Container(
                margin: EdgeInsets.all(20.0),
                alignment: Alignment.center,
                child: Image.file(photos[0].name),
              );
            }
            else if (index == 1) {
              var singleChildScrollView = SingleChildScrollView(
                child: Row(
                  children: pics,
                ),
                scrollDirection: Axis.horizontal,
              );
              return singleChildScrollView;
            }
            else {
              return Text('empty space');
            }
          }),

更改为:

child: ListView.builder(
            itemCount: 3,
            itemBuilder: (context, index) {
            if (index == 0) {
              return Container(
                margin: EdgeInsets.all(20.0),
                alignment: Alignment.center,
                child: Image.file(photos[0].name),
              );
            }
            else if (index == 1) {
              var singleChildScrollView = SingleChildScrollView(
                child: Row(
                  children: pics,
                ),
                scrollDirection: Axis.horizontal,
              );
              return singleChildScrollView;
            }
            else {
              return Text('empty space');
            }            
          }),