Flutter DragableScrollableSheet不';t拖动时,不给出图纸的当前位置

Flutter DragableScrollableSheet不';t拖动时,不给出图纸的当前位置,flutter,Flutter,在flutter中,我们有一个小部件DraggableScrollableSheet。现在,我需要拖动子对象时的当前位置或当前大小。目前无法获得该值。它在其生成器方法中提供了一个ScrollController,但这是用于列表滚动而不是拖动列表时的。那么,有没有其他方法可以跟踪列表的当前拖动位置 我尝试添加NotificationListener,但这只提供DragStartNotification和dragendnotification,而dragupdate则没有: DraggableScr

在flutter中,我们有一个小部件DraggableScrollableSheet。现在,我需要拖动子对象时的当前位置或当前大小。目前无法获得该值。它在其生成器方法中提供了一个ScrollController,但这是用于列表滚动而不是拖动列表时的。那么,有没有其他方法可以跟踪列表的当前拖动位置

我尝试添加NotificationListener,但这只提供DragStartNotification和dragendnotification,而dragupdate则没有:

DraggableScrollableSheet(
          initialChildSize: .70,
          minChildSize: .70,
          builder:
              (BuildContext context, ScrollController scrollcontroller) {
            return NotificationListener(
              onNotification: (notification) {
                print("$notification");
              },
              child: Container(
                child: ListView.builder(
                    controller: scrollcontroller,
                    itemCount: widget.songs.length,
                    itemBuilder: (BuildContext context, int index) {
                      return buildSongRow(widget.songs[index]);
                    }),
              ),
            );
          }),

我找到了解决办法。颤振团队更新了颤振v1.7.3中的ScrollableDragableSheet类。他们添加了一个名为DragableScrollableNotification的类,您可以在拖动时侦听该类以获取子对象的当前扩展

NotificationListener<DraggableScrollableNotification>(
      onNotification: (notification) {

        print("${notification.extent}");
      },
      child: DraggableScrollableSheet(
          initialChildSize: .70,
          minChildSize: .70,
          builder:
              (BuildContext context, ScrollController scrollcontroller) {
            return Container(
              child: ListView.builder(
                  controller: scrollcontroller,
                  itemCount: widget.songs.length,
                  itemBuilder: (BuildContext context, int index) {
                    return buildSongRow(widget.songs[index]);
                  }),
            );
          }),
    )
NotificationListener(
通知:(通知){
打印(“${notification.extent}”);
},
子项:DragableScrollableSheet(
初始大小:.70,
minChildSize:.70,
建设者:
(BuildContext上下文,ScrollController ScrollController){
返回容器(
子项:ListView.builder(
控制器:滚动控制器,
itemCount:widget.songs.length,
itemBuilder:(构建上下文,int索引){
返回buildSongRow(widget.songs[index]);
}),
);
}),
)
在上面的示例中,通知。拖动时,“范围”将为您提供子对象的当前范围(位置)

NotificationListener<DraggableScrollableNotification>(
      onNotification: (notification) {

        print("${notification.extent}");
      },
      child: DraggableScrollableSheet(
          initialChildSize: .70,
          minChildSize: .70,
          builder:
              (BuildContext context, ScrollController scrollcontroller) {
            return Container(
              child: ListView.builder(
                  controller: scrollcontroller,
                  itemCount: widget.songs.length,
                  itemBuilder: (BuildContext context, int index) {
                    return buildSongRow(widget.songs[index]);
                  }),
            );
          }),
    )
注意:这当前在主通道中,不在稳定通道中 频道通过运行颤振主通道,切换到主通道 然后进行颤振升级,使其暂时生效


为了方便起见,要获得介于0.0和1.0之间的值,请尝试以下操作:
final dragRatio=(notification.extent-notification.minExtent)/(notification.maxExtent-notification.minExtent)