当孩子listView到达flutter时,是否有任何方法可以滚动父列表视图?

问题描述 投票:0回答:2
LLET说我有一个可滚动页面,在此页面内,我还有另一个可滚动列表视图(垂直),所以我希望当孩子列表视图到达end时,可滚动页面开始移至它的结尾。同样,当Child ListView到达顶部时,可滚动页面开始移至顶部。如何做到?

这里是我的代码

Widget FreshProductsShow(double pageHeight, double pageWidth) { return Container( height: pageHeight / 1.3, width: pageWidth, child: ListView.builder( itemCount: 10, itemBuilder: (context, index) { return Card( child: Container( width: pageWidth, // height: pageHeight / 7, decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(10)), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, textDirection: TextDirection.rtl, children: [ Image.asset( "images/peper.png", width: pageWidth / 4, height: pageHeight / 8, ), Padding( padding: EdgeInsets.only(left: pageWidth / 6.3), child: Column( children: [ Padding( padding: EdgeInsets.only( left: pageWidth / 10, top: pageHeight / 45), child: AutoSizeText( "peper", style: TextStyle( fontSize: pageHeight / 48, fontWeight: FontWeight.bold, color: Color(0xff54595F)), ), ), ], ), ) ], ), alignment: Alignment.centerRight, ), elevation: 5, ); }, scrollDirection: Axis.vertical, ), ); }
    
android flutter dart listview scroll
2个回答
1
投票
要找到必须使用滚动通知侦听器的滚动位置,然后使用

NotificationListener

我们可以控制每个可滚动窗口小部件的滚动位置。
在这里,您的函数将转换为状态方面的函数,如果我正确地获得了逻辑,则实现了逻辑:
ScrollController

是的,如果使用仿真,如果子窗口小部件在顶部或底部。
在这里是创建自定义物理的示例代码:

1
投票

贝洛是要在父窗口中实现的示例代码-

import 'package:flutter/material.dart';

class CustomScrollPhysics extends ClampingScrollPhysics {
  final Function outerController;
  bool isMinCheck = false;
  CustomScrollPhysics({required this.outerController, ScrollPhysics? parent})
    : super(parent: parent);

  @override
  CustomScrollPhysics applyTo(ScrollPhysics? ancestor) {
    return CustomScrollPhysics(
      outerController: outerController,
      parent: buildParent(ancestor)!,
    );
  }

  @override
  Simulation? createBallisticSimulation(
    ScrollMetrics position,
    double velocity,
  ) {
    if (position.pixels >= position.maxScrollExtent && velocity >= 0.0) {
      outerController(velocity, false);
    } else if (position.pixels == position.minScrollExtent && isMinCheck) {
      outerController(velocity, true);
    } else {
      isMinCheck = true;
    }
    return super.createBallisticSimulation(position, velocity);
  }
}

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.