且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

禁用ListView滚动

更新时间:2022-10-15 22:51:07

I think the best way to do this is to use a SingleChildScrollView:

This widget is useful when you have a single box that will normally be entirely visible, for example a clock face in a time picker, but you need to make sure it can be scrolled if the container gets too small in one axis (the scroll direction).

And instead of using a ListView just use a Column and place it inside of the SingleChildScrollView:

    SingleChildScrollView(
        child: Column(
            mainAxisSize: MainAxisSize.min,
            children: <Widget>[/**/],
        ),
    )

Or if you need to use ListView for some reason, you can use shrinkWrap with NeverScrollableScrollPhysics:

    SingleChildScrollView(
        child: ListView(
            shrinkWrap: true,
            physics: NeverScrollableScrollPhysics(),
            children: <Widget>[/**/],
        ),
    )