Flutter 滚动页面视图

Flutter 滚动页面视图,flutter,flutter-web,Flutter,Flutter Web,我想使用带有垂直轴的页面视图,并使用鼠标滚动在页面之间移动,但当我使用鼠标滚动时,页面不会滚动。。。仅当我单击并向上/向下滑动时,页面才会滚动 有办法吗 我想保留属性pageSnapping:true 问题是: 当我尝试用鼠标滚动页面时,它不会改变,它只是回到初始偏移量。 但当我点击并刷卡时 类主体扩展StatefulWidget{ @凌驾 _BodyState createState(); } 类_BodyState扩展了状态{ PageController _controller=Page

我想使用带有垂直轴的
页面视图
,并使用鼠标滚动在页面之间移动,但当我使用鼠标滚动时,页面不会滚动。。。仅当我单击并向上/向下滑动时,页面才会滚动

有办法吗

我想保留属性
pageSnapping:true

问题是:

当我尝试用鼠标滚动页面时,它不会改变,它只是回到初始偏移量。 但当我点击并刷卡时

类主体扩展StatefulWidget{
@凌驾
_BodyState createState();
}
类_BodyState扩展了状态{
PageController _controller=PageController(keepPage:true);
@凌驾
void initState(){
super.initState();
}
@凌驾
小部件构建(构建上下文){
返回脚手架(
主体:容器(
高度:尺寸。尺寸。高度,
宽度:大小。大小。宽度,
子:堆栈(
儿童:[
页面浏览(
滚动方向:轴垂直,
控制器:_控制器,
儿童:[
容器(颜色:颜色。红色),
容器(颜色:颜色。蓝色),
容器(颜色:颜色。橙色),
],
),
],
),
),
);
}
}

要使内容可滚动,通常可以在
SingleChildScrollView()
中包装小部件(>>右键单击要使其可滚动的小部件>>重构>>使用小部件包装),要使用鼠标滚动,必须通过设置
物理学:永不滚动滚动物理学()
。 然后,您必须手动截取鼠标在
侦听器中的滚动。如果还想通过滑动恢复页面浏览经典动作,则必须使用
手势检测器
。 下面是一个示例代码:

class _HomepageState extends State<Homepage> {
  final PageController pageController = PageController();
  // this is like a lock that prevent update the PageView multiple times while is 
  // scrolling
  bool pageIsScrolling = false;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
          child: GestureDetector(
        // to detect swipe
        onPanUpdate: (details) {
          _onScroll(details.delta.dy * -1);
        },
        child: Listener(
          // to detect scroll
          onPointerSignal: (pointerSignal) {
            if (pointerSignal is PointerScrollEvent) {
              _onScroll(pointerSignal.scrollDelta.dy);
            }
          },
          child: PageView(
            scrollDirection: Axis.vertical,
            controller: pageController,
            physics: NeverScrollableScrollPhysics(),
            pageSnapping: true,
            children: [
               Container(color: Colors.red),
               Container(color: Colors.blue),
               Container(color: Colors.orange),
            ],
          ),
        ),
      )),
    );
  }

  void _onScroll(double offset) {
    if (pageIsScrolling == false) {
      pageIsScrolling = true;
      if (offset > 0) {
        pageController
            .nextPage(
                duration: Duration(milliseconds: 300),
                curve: Curves.easeInOut)
            .then((value) => pageIsScrolling = false);

        print('scroll down');
      } else {
        pageController
            .previousPage(
                duration: Duration(milliseconds: 300),
                curve: Curves.easeInOut)
            .then((value) => pageIsScrolling = false);
        print('scroll up');
      }
    }
  }
}
class\u HomepageState扩展状态{
final PageController PageController=PageController();
//这就像一个锁,防止在运行时多次更新页面视图
//滚动
bool-pagescrolling=false;
@凌驾
小部件构建(构建上下文){
返回脚手架(
正文:安全区(
儿童:手势检测器(
//检测刷卡
onPanUpdate:(详细信息){
_onScroll(details.delta.dy*-1);
},
孩子:听众(
//检测滚动
onPointerSignal:(pointerSignal){
if(pointerSignal是PointerScrollEvent){
_onScroll(pointerSignal.scrolldta.dy);
}
},
子:页面视图(
滚动方向:轴垂直,
控制器:页面控制器,
物理学:NeverscrollableScroll物理学(),
页面捕捉:对,
儿童:[
容器(颜色:颜色。红色),
容器(颜色:颜色。蓝色),
容器(颜色:颜色。橙色),
],
),
),
)),
);
}
void _onScroll(双偏移){
如果(PageIsCrolling==false){
PageIsCrolling=true;
如果(偏移量>0){
页面控制器
.下一页(
持续时间:持续时间(毫秒:300),
曲线:曲线。easeInOut)
。然后((值)=>PageIsCrolling=false);
打印(“向下滚动”);
}否则{
页面控制器
.上一页(
持续时间:持续时间(毫秒:300),
曲线:曲线。easeInOut)
。然后((值)=>PageIsCrolling=false);
打印(“向上滚动”);
}
}
}
}
感谢卢卡

我只是修改了整件事来做同样的事情,问这个问题的目的是什么

  Listener(
                onPointerMove: (pointerMove) {
                  if (pointerMove is PointerMoveEvent) {
                    _onScroll(pointerMove.delta.dy * -1);
                    print(pointerMove.delta.dy);
                  }
                },
                onPointerSignal: (pointerSignal) {
                  if (pointerSignal is PointerScrollEvent) {
                    _onScroll(pointerSignal.scrollDelta.dy);
                    print(pointerSignal.scrollDelta.dy);
                  }
                },
                child: SingleChildScrollView(
                  child: Container(
                    constraints: BoxConstraints(
                        minHeight: SizeConfig.screenHeight * .9),
                    width: SizeConfig.screenWidth,
                    height: SizeConfig.screenWidth / 2,
                    decoration: BoxDecoration(
                        image: DecorationImage(
                            alignment: Alignment.centerRight,
                            image: AssetImage(
                                'assets/images/background_circles.png'))),
                    child: PageView(
                      controller: _pageController,
                      physics: NeverScrollableScrollPhysics(),
                      pageSnapping: true,
                      scrollDirection: Axis.vertical,
                      children: [

我知道这个小部件,但是
PageView()
已经可以滚动了。。。我的卷轴有问题。对不起,我只是个初学者,不知道。酷!我等会儿再试试,不行!
  Listener(
                onPointerMove: (pointerMove) {
                  if (pointerMove is PointerMoveEvent) {
                    _onScroll(pointerMove.delta.dy * -1);
                    print(pointerMove.delta.dy);
                  }
                },
                onPointerSignal: (pointerSignal) {
                  if (pointerSignal is PointerScrollEvent) {
                    _onScroll(pointerSignal.scrollDelta.dy);
                    print(pointerSignal.scrollDelta.dy);
                  }
                },
                child: SingleChildScrollView(
                  child: Container(
                    constraints: BoxConstraints(
                        minHeight: SizeConfig.screenHeight * .9),
                    width: SizeConfig.screenWidth,
                    height: SizeConfig.screenWidth / 2,
                    decoration: BoxDecoration(
                        image: DecorationImage(
                            alignment: Alignment.centerRight,
                            image: AssetImage(
                                'assets/images/background_circles.png'))),
                    child: PageView(
                      controller: _pageController,
                      physics: NeverScrollableScrollPhysics(),
                      pageSnapping: true,
                      scrollDirection: Axis.vertical,
                      children: [