列中扩展列表视图上方的问题呈现小部件

时间:2019-08-01 15:05:21

标签: flutter dart flutter-layout

我试图呈现一个列(在CupertinoPageScaffold内部),其中该列在展开的列表视图之前和之后(在子级中)具有小部件。呈现在列表视图之后的小部件,但不呈现在列表视图之前的小部件。 Link to image with rendered screen

class TestWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        Container(
          constraints: BoxConstraints(
            minHeight: 50.0,
          ),
          child: Center(
            child: Text(
              'Top label',
              style: TextStyle(
                  fontSize: 22.0,
                  fontWeight: FontWeight.bold,
                  color: Colors.teal),
            ),
          ),
        ),
        Expanded(
          child: ListView.separated(
            itemCount: 20,
            separatorBuilder: (context, index) {
              return Divider();
            },
            itemBuilder: (context, index) {
              return Material(
                child: ListTile(
                  leading: CircleAvatar(),
                  title: Text('Test title'),
                ),
              );
            },
          ),
        ),
        Container(
          constraints: BoxConstraints(
            minHeight: 50.0,
          ),
          child: Center(
            child: Text(
              'Bottom label',
              style: TextStyle(
                  fontSize: 22.0,
                  fontWeight: FontWeight.bold,
                  color: Colors.teal),
            ),
          ),
        ),
      ],
    );
  }
}

1 个答案:

答案 0 :(得分:1)

只需在TestWidget内添加SafeArea即可。


SafeArea(
 child: TestWidget()
);