The scroll widget that Flutter provides is similar to the ScrollView in Android.

attribute
  • This.scrolldirection = Axis. Vertical,// The direction of the scroll, vertical or horizontal
  • This. Reverse = false,// Whether to reverse. If reverse is true, look at the bottom first.
  • This padding, / / padding
  • Bool primary,// Whether to use default controller
  • this.physics,
  • This. controller,// Can control the initial offset
  • this.child

Vertical direction:

class _MyHomePageState extends State<MyHomePage> { @override Widget build(BuildContext context) { List<String> list = <String>[]; for (var i = 0; i < 150; i++) { list.add(i.toString()); } return Scaffold( appBar: AppBar( title: Text(widget.title), ), body: SingleChildScrollView( scrollDirection: Axis.vertical, reverse: true, padding: EdgeInsets.all(20), primary: false, child: Center( child: Column( children: list .map((item) => Text( item, style: TextStyle(fontSize: 16), )) .toList(), ), ), controller: ScrollController(initialScrollOffset: 120,keepScrollOffset: true), ), ); }}Copy the code

Horizontal direction:

class _MyHomePageState extends State<MyHomePage> { @override Widget build(BuildContext context) { List<String> list = <String>[]; for (var i = 0; i < 150; i++) { list.add(i.toString()); } return Scaffold( appBar: AppBar( title: Text(widget.title), ), body: SingleChildScrollView( scrollDirection: Axis.horizontal, reverse: true, padding: EdgeInsets.all(20), primary: false, child: Center( child: Row( children: list .map((item) => Text( item, style: TextStyle(fontSize: 16), )) .toList(), ), ), controller: ScrollController(initialScrollOffset: 120,keepScrollOffset: true), ), ); }}Copy the code