首页 > 解决方案 > 如何在颤动中实现“instagram 相机”滚动?

问题描述

我正在尝试在 PageView 中使用 ScrollView 来实现这种效果:

https://ibb.co/dMd3TZL

但是当我滚动到第二页时,我被卡住了,我不能再回去了。

示例代码:

    import 'package:flutter/material.dart';

    void main() => runApp(MyApp());

    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'Flutter Demo',
          debugShowCheckedModeBanner: false,
          theme: ThemeData(
            primarySwatch: Colors.blue,
          ),
          home: Scaffold(
            appBar: AppBar(
              title: Text("Demo"),
            ),
            body: PageView(
              scrollDirection: Axis.vertical,
              children:[
                Container(color: Colors.red),
                ListView(
                  children:[
                    Container(color: Colors.yellow, height:300),
                    Container(color: Colors.green, height:300),
                  ]
                )
              ],
            ),
          ),
        );
      }
    }

当 ScrollView 到达末尾时,如何将 onDrag 事件发送到 PageView?

标签: flutterflutter-layout

解决方案


listview 不适用于 pageviewer,因此请使用 wrap Widget 而不是 listview,如下所示,

PageView(
    scrollDirection: Axis.vertical,
    children:[
      Container(color: Colors.red),
      Wrap(
          children:[
            Container(color: Colors.yellow, height:300),
            Container(color: Colors.green, height:300),
          ]
      )

    ],
  ),

推荐阅读