具有水平,非填充子项的PageView

Luk*_*uke 8 flutter

看起来PageView总是会根据滚动轴来填充.什么是迎合"窥视"的最佳方法PageView

我尝试PageView.custom使用标准实现一个,SliverChildListDelegate但我猜测不允许任意/自定义大小.我打算开始做一些自定义的事情,但决定在这里问一个好的开始.

请参阅下图,了解我正在努力实现的目标.

在此输入图像描述

Eri*_*del 6

我的理解是,当前的PageView无法做到这一点,我已将其变成一个问题:https : //github.com/flutter/flutter/issues/8408


Bla*_*nka 5

此功能已在2017年3月3日添加。在@EricSeidel的请求之后

这可以通过PageViewcontroller属性来实现。

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)

我想不出一种更好的方法来增加页面之间的边距,以及如何避免在上一页和下一页之后留出空间。

在此处输入图片说明