如何使容器填充一行中的可用垂直空间?

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

有人可以帮我吗?

我正在努力弄清楚如何使彩色容器扩展以匹配其行中最高的容器的高度。

目前,它们没有固定的高度/宽度,并包装在Expanded小部件中以获取其动态大小。

如果可能,我想保持其响应大小。一旦屏幕足够小,我已经有一种方法可以切换到列而不是行。一旦进入列,我就可以使用width: double.infinity,因为没有水平滚动。

Row with Containers

这是所使用代码的示例(很抱歉!太多了!):

class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Scrollbar(
        child: CustomScrollView(
          slivers: <Widget>[
            SliverNavBar(),
            SliverList(
              delegate: SliverChildListDelegate(
                [
                  Row(
                    crossAxisAlignment: CrossAxisAlignment.start,
                      children: _homePageContent(),
                     );
                  Footer()
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}
_homePageContent() {
  return <Widget>[
    _HomePageInfoBox(
      backgroundColor: accentColor,
      title: 'THIS IS A TITLE',
      body:
          'Lorem ipsum...',
    ),
    _HomePageInfoBox(
      backgroundColor: primaryColorDark,
      title: 'THIS IS A TITLE',
      body:
          'Lorem ipsum....',
    ),
    _HomePageInfoBox(
      backgroundColor: primaryColor,
      title: 'THIS IS A TITLE',
      body:
          'Lorem ipsum...',
    ),
  ];
}
class _HomePageInfoBox extends StatelessWidget {
  const _HomePageInfoBox({
    Key key,
    @required this.title,
    @required this.body,
    @required this.backgroundColor,
  }) : super(key: key);

  final String title;
  final String body;
  final Color backgroundColor;

  @override
  Widget build(BuildContext context) {
    return Expanded(
      Container(
      color: backgroundColor,
      child: Padding(
        padding: const EdgeInsets.all(50),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisAlignment: MainAxisAlignment.start,
          children: <Widget>[
            Text(
              title,
              style: TextStyle(
                  color: primaryTextColor,
                  fontSize: 25,
                  fontFamily: 'CoffeeAndTea'),
            ),
            SizedBox(height: 10),
            Text(
              body,
              style: TextStyle(
                  color: primaryTextColor,
                  fontSize: 24,
                  height: 1.4,
                  fontFamily: 'ElegantSans'),
            ),
            SizedBox(height: 20),
            Text(
              "Let's Go!",
              style: TextStyle(
                  color: Colors.white, fontFamily: 'CreamCake', fontSize: 30),
              textAlign: TextAlign.center,
            ),
          ],
        ),
       ),
     ),
    );
  }
}

有人可以帮我吗?我正在努力弄清楚如何使彩色容器能够扩展以匹配其行中最高的容器的高度。当前它们没有固定的高度/宽度...

flutter dart flutter-layout flutter-web
2个回答
1
投票

使用IntrinsicHeight小部件将行项目的高度调整为最大一排项目:


1
投票

Text包裹您的身体Expanded小部件。由于您的父级WidgetColumn,因此Expanded将为该小部件提供所有可用的垂直空间。

© www.soinside.com 2019 - 2024. All rights reserved.