【问题标题】:Flutter cannot drag pageview verticallyFlutter 无法垂直拖动 pageview
【发布时间】:2019-10-22 00:32:58
【问题描述】:

我正在学习 Flutter,所以如果我的问题是一个愚蠢的问题,请不要向我扔石头 :p :D

首先,下面的一些图片你可能很熟悉,我只是使用这个来自 github 的应用程序来测试理论。来源:https://www.youtube.com/watch?v=sgfMdhV4HQI&t=370s

我的问题:

我正在使用综合浏览量在两个页面之间导航,一个具有一些可拖动容器,另一个页面具有一些代表不同主题的更多可拖动容器。

如果我定义 scrollDirection: Axis.horizo​​ntal, 它可以正常工作。但我想垂直拖动它。

如果我定义 scrollDirection: Axis.vertical, 我意识到,我只有一小部分屏幕可以拖动页面。

据我了解,可能与容器有关。

  • 如何在触摸屏幕上任意位置的同时垂直拖动?

注意:我还测试了 SliverToBoxAdapter 类,但没有得到很好的结果。

我的 git repro https://github.com/engineerRFR/flutter-mytest

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

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Netflix UI Redesign',
      debugShowCheckedModeBanner: false,
      home: PageView(
          children: <Widget>[
            Container(
              color: Colors.pink,
              child: HomeScreen(),
            ),
            Container(
              color: Colors.cyan,
              child: photoGallery(),
            ),
            Container(
              color: Colors.deepPurple,
            ),
          ],
        scrollDirection: Axis.horizontal,
        onPageChanged: (num) {
          print("Page number : " + num.toString());
        },
      ),
    );
  }
}


 photoGallery (){
  return PageView(
    scrollDirection: Axis.vertical,
    children: <Widget>[
      Container(
        color: Colors.amber,

      )

,

【问题讨论】:

  • 我创建了同一个项目,它使用您提供的代码开箱即用,我能够从页面上的任何位置拖动和滚动。也许您从 Github 中提取的应用程序中还有其他影响触摸/手势的东西?
  • 你好 Dusk,我也是从 git 下载的,并添加了 pageView 和 photoGallery() 以显示在第二个屏幕上。
  • 能分享一下git项目吗?
  • 今晚我将创建 git。 :)

标签: flutter dart


【解决方案1】:

参考我们的 cmets,正如我所怀疑的,这个问题的根源不是您的 PageView

如果您检查您的home_screen.dart,则您的Scaffold(第121 行)的bodyListView。如果你把它改成Column,一切都开始如你所愿!

那是因为ListView 消耗了所有的垂直滚动并且事件不会到达外部PageView

【讨论】:

  • 就这个?!我有很多东西要学! :D 非常感谢 Dusk,它成功了!
  • @Richardd 没问题 :) 很高兴能帮上忙!
猜你喜欢
  • 1970-01-01
  • 2020-02-04
  • 1970-01-01
  • 2013-08-02
  • 2020-02-14
  • 2012-11-19
  • 1970-01-01
  • 1970-01-01
  • 2021-10-28
相关资源
最近更新 更多