dart 不带自动换行的浮动内联框

aurhwmvo  于 2023-02-20  发布在  其他
关注(0)|答案(1)|浏览(109)

我正在开发一个底部有菜单的应用程序,这是结果:

我写了下面的代码:

return Row(
  children: menuItems
      .asMap()
      .entries
      .map(
        (x) => Expanded(
          child: Container(
            decoration: const BoxDecoration(
              color: HGVColors.grey,
            ),
            child: InkWell(
              onTap: () => setTitle(x.key),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  SvgPicture.asset(
                    "assets/images/${x.value.icon}.svg",
                    height: 25,
                    color: getColor(x.key == currentIndex),
                  ),
                  Text(
                    x.value.label,
                    style: TextStyle(
                      color: getColor(x.key == currentIndex),
                    ),
                  ),
                ],
              ),
            ),
          ),
        ),
      )
      .toList(),
);

但是,预期结果如下:

我该怎么做才能使 * Konventionen * 不换行到新行,而是拉伸它的容器?

a2mppw5e

a2mppw5e1#

我找到了解决办法:

return Container(
      decoration: const BoxDecoration(
        color: HGVColors.grey,
      ),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        children: menuItems
            .asMap()
            .entries
            .map(
              (x) => InkWell(
                onTap: () => setTitle(x.key),
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    SvgPicture.asset(
                      "assets/images/${x.value.icon}.svg",
                      height: 25,
                      color: getColor(x.key == currentIndex),
                    ),
                    child: Text(
                      x.value.label,
                      style: TextStyle(
                        color: getColor(x.key == currentIndex),
                      ),                      
                    ),
                  ],
                ),
              ),
            )
            .toList(),
      ),
    );

密钥是mainAxisAlignment: MainAxisAlignment.spaceEvenly

相关问题