让Row中的Streambuilder不返回任何内容

问题描述 投票:0回答:1

我的 Flutter 应用程序中有一行包含三个按钮,其中一个是可选的。

可选按钮将通过 FutureBuilder 激活,FutureBuilder 检查服务是否已激活。

Futurebuilder 必须返回一些东西。所以一开始我只是返回一个空的 SizedBox() 但这也会在 Row 的 MainAxisAlignment 中获得一个位置。

有没有一种方法不返回任何内容,甚至有另一种方法来构建它?

示例:

Row(
  mainAxisAlignment: MainAxisAlignment.spaceAround,
  children: [
    ElevatedButton(),
    ElevatedButton(),
    FutureBuilder<bool>(
      future: isServiceActive(),
      builder: (context, serviceActive) {
        if (serviceActive) {
          return ElevatedButton(),
        } 
// Else it should return nothing. 
// A empty SizedBox would take a place in MainAxisAlignment
        return ;
      },
    ),
  ],
);
flutter flutter-futurebuilder
1个回答
0
投票

你可以使用

SizedBox.shrink()
我认为它对小部件对齐没有影响。

(serivceActive) ? ElevatedButton(): SizedBox.shrink();
© www.soinside.com 2019 - 2024. All rights reserved.