flutter(二十)flutter ScrollView 滑动

1,106 阅读1分钟
原文链接: blog.csdn.net

SingleChildScrollView

ScrollView 是一个抽象类 不可以直接实例化

SingleChildScrollView类似于开发中常用的ScrollView

SingleChildScrollView

竖直滑动

 
  Widget buildScrollView() {

    return  SingleChildScrollView(
        //滑动的方向 Axis.vertical为垂直方向滑动,Axis.horizontal 为水平方向
        scrollDirection: Axis.vertical,
        //true 滑动到底部
        reverse: false,
        padding: EdgeInsets.all(0.0),
        ////滑动到底部回弹效果
        physics: BouncingScrollPhysics(),
        child: Center(
          child: Column(
            children: <Widget>[
              Container(color: Colors.white ,margin: EdgeInsets.only(top: 10),height: 440,),
              Container(color: Colors.green ,margin: EdgeInsets.only(top: 10),height: 540,),
            ],
          ),
        ),
    );
  }

水平方向滑动


  Widget buildScrollview() {

    return  SingleChildScrollView(
        //滑动的方向 Axis.vertical为垂直方向滑动,Axis.horizontal 为水平方向
        scrollDirection: Axis.horizontal,
        //true 滑动到底部
        reverse: false,
        padding: EdgeInsets.all(0.0),
        //滑动到底部回弹效果
        physics: BouncingScrollPhysics(),
        child: Center(
          child: Row(
            children: <Widget>[
              Container(color: Colors.white ,margin: EdgeInsets.only(top: 10),width: 440,height: 200,),
              Container(color: Colors.green ,margin: EdgeInsets.only(top: 10),width: 540,height: 200,),
            ],
          ),
        ),
    );
  }