看起来PageView总是会根据滚动轴来填充.什么是迎合"窥视"的最佳方法PageView?
我尝试PageView.custom使用标准实现一个,SliverChildListDelegate但我猜测不允许任意/自定义大小.我打算开始做一些自定义的事情,但决定在这里问一个好的开始.
请参阅下图,了解我正在努力实现的目标.
此功能已在2017年3月3日添加。在@EricSeidel的请求之后。
这可以通过PageView的controller属性来实现。
controller: PageController(
initialPage: 1,
viewportFraction: 0.8,
),
Run Code Online (Sandbox Code Playgroud)
PageController.viewportFraction可以窥视上一个和下一个。 启动应用程序时显示中间页面的PageController.initialPage。
import 'package:flutter/material.dart';
void main() => runApp(LimeApp());
class LimeApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Lime',
home: MainPage(),
);
}
}
class MainPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
margin: EdgeInsets.symmetric(
vertical: 50.0,
),
child: PageView(
controller: PageController(
initialPage: 1,
viewportFraction: 0.8,
),
children: [
Container(margin: EdgeInsets.symmetric(horizontal: 10.0,), color: Colors.redAccent),
Container(margin: EdgeInsets.symmetric(horizontal: 10.0,), color: Colors.purpleAccent),
Container(margin: EdgeInsets.symmetric(horizontal: 10.0,), color: Colors.greenAccent)
],
),
),
);
}
}
Run Code Online (Sandbox Code Playgroud)
我想不出一种更好的方法来增加页面之间的边距,以及如何避免在上一页和下一页之后留出空间。
| 归档时间: |
|
| 查看次数: |
3676 次 |
| 最近记录: |