PageView 是一个滑动视图列表,它也是继承至 CustomScrollView 的。
PageView({ Key key, this.scrollDirection = Axis.horizontal, this.reverse = false, PageController controller, this.physics, this.pageSnapping = true, this.onPageChanged, List<Widget> children = const <Widget>[], this.dragStartBehavior = DragStartBehavior.start, }) : controller = controller ?? _defaultPageController, childrenDelegate = SliverChildListDelegate(children), super(key: key);
typedef IndexedWidgetBuilder = Widget Function(BuildContext context, int index);
* @required IndexedWidgetBuilder itemBuilder : 构建子控件
* typedef IndexedWidgetBuilder = Widget Function(BuildContext context, int index); 构建子控件的数目
PageView.builder({ Key key, this.scrollDirection = Axis.horizontal, this.reverse = false, PageController controller, this.physics, this.pageSnapping = true, this.onPageChanged, @required IndexedWidgetBuilder itemBuilder, int itemCount, this.dragStartBehavior = DragStartBehavior.start, }) : controller = controller ?? _defaultPageController, childrenDelegate = SliverChildBuilderDelegate(itemBuilder, childCount: itemCount), super(key: key);
* final SliverChildDelegate childrenDelegate;使用代理的方式构建子类列表
PageView.custom({ Key key,
this.scrollDirection = Axis.horizontal, this.reverse = false, PageController controller, this.physics, this.pageSnapping = true, this.onPageChanged, @required this.childrenDelegate, this.dragStartBehavior = DragStartBehavior.start, }) : assert(childrenDelegate != null), controller = controller ?? _defaultPageController, super(key: key);
import ‘package:flutter/material.dart‘; void main() => runApp(MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( title: ‘Flutter Demo‘, theme: ThemeData( primarySwatch: Colors.blue, ), home: new MyPageHome(title: ‘pageViewDemo‘,), ); } } class MyPageHome extends StatefulWidget { //属性 String title; //构造函数 MyPageHome({Key key,this.title}):super(key:key); @override State<StatefulWidget> createState() { // TODO: implement createState return new MyPageHomeState(); } } class MyPageHomeState extends State<MyPageHome> { @override Widget build(BuildContext context) { return new Scaffold( appBar: new AppBar( title: new Text(widget.title) ), body: new Center( child: new Container( width: 200, height: 200, child: new PageView( children: <Widget>[ Image.network(‘https://ws1.sinaimg.cn/large/0065oQSqgy1fwgzx8n1syj30sg15h7ew.jpg‘), Image.network(‘https://ws1.sinaimg.cn/large/0065oQSqly1fw8wzdua6rj30sg0yc7gp.jpg‘), Image.network(‘https://ws1.sinaimg.cn/large/0065oQSqly1fw0vdlg6xcj30j60mzdk7.jpg‘), Image.network(‘https://ws1.sinaimg.cn/large/0065oQSqly1fuo54a6p0uj30sg0zdqnf.jpg‘), ], ), ), ), ); } }
【Flutter学习】基本组件之基本滑动PageView组件
原文:https://www.cnblogs.com/lxlx1798/p/11181295.html