简体   繁体   English

Flutter ListView inside Card

[英]Flutter ListView inside Card

I would like to have a Screen which will have 3 Cards.我想要一个有 3 张卡片的屏幕。 One card would be CotrolWidget(Top with fixed height), Second will be the MeasurementsList(under Top, should fill vertically) and third will be ChartWidget(under Top, right from the MeasurementsList,should fill vertically).一张卡是 CotrolWidget(固定高度的顶部),第二张是 MeasurementsList(在 Top 下面,应该垂直填充),第三张是 ChartWidget(在 Top 下面,在 MeasurementsList 的右边,应该垂直填充)。

return Scaffold(
  appBar: AppBar(title: new Text('Measurements')),
  body: new Container(
      padding: EdgeInsets.all(8.0),
      decoration: BoxDecoration(color: Colors.black12),
      child: Column(
        mainAxisSize: MainAxisSize.max,
        children: <Widget>[
          Row(children: [ControlsWidget(device)]),
          Row(
            children: <Widget>[
              MeasurementList(device)
              ,
              ChartWidget(device)
            ],
          )
        ],
      )),
);

In the Measurements Card, I would like to have a ListView.在测量卡中,我想要一个 ListView。 But when I use Expaded, the ListView will extend the screen and the list is not scrollable但是当我使用 Expaded 时,ListView 会扩展屏幕并且列表不可滚动

Widget build(BuildContext context) {
return Expanded(
  flex: 1,
  child: Card(
    elevation: 4.0,
    child: ListView.builder(
      scrollDirection: Axis.horizontal,
      itemBuilder: (context, index) {
        return ListTile(title: Text(measurements[index]));
      },
      itemCount: measurements.length,
      shrinkWrap: true,
    ),
  ),
);

} }

So, how to create a Card with ListView inside?那么,如何创建一个里面有ListView的Card呢?

Try Using MediaQuery for height. 尝试使用MediaQuery获取高度。

MediaQueryData queryData; queryData = MediaQuery.of(context);

and then in height use 然后在高处使用

height: queryData.size.height - height_of_ControlsWidget

I too got the same problem, but I tired to use the Flexible Widget instead of expanded widget.我也遇到了同样的问题,但我厌倦了使用Flexible Widget而不是扩展的小部件。

check out this stack over link for better understanding. 通过链接查看此堆栈以获得更好的理解。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM