fluttercandies / flutter_scrollview_observer

A widget for observing data related to the child widgets being displayed in a ScrollView. Maintainer: @LinXunFeng
https://pub.dev/packages/scrollview_observer
MIT License
438 stars 47 forks source link

[Bug report] onObserve回调,监听数据不全 #70

Closed chensimin920511 closed 7 months ago

chensimin920511 commented 9 months ago

Version

1.19.0

Platforms

Android

Device Model

Galaxy A54(Android 13)

flutter info

[√] Flutter (Channel stable, 3.10.5, on Microsoft Windows [版本 10.0.19045.2364], locale zh-CN)
    • Flutter version 3.10.5 on channel stable at D:\FlutterSdk\flutter_windows_3.10.5-stable\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 796c8ef792 (7 months ago), 2023-06-13 15:51:02 -0700
    • Engine revision 45f6e00911
    • Dart version 3.0.5
    • DevTools version 2.23.1
    • Pub download mirror https://pub.flutter-io.cn
    • Flutter download mirror https://storage.flutter-io.cn

[√] Windows Version (Installed version of Windows is version 10 or higher)

[!] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
    • Android SDK at D:\AndroidSdk
    • Platform android-33, build-tools 33.0.2
    • Java binary at: D:\Program Files\Android Studio\jbr\bin\java
    • Android Studio at D:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    X Unable to determine bundled Java version.
    • Try updating or re-installing Android Studio.

[√] Android Studio (version 2022.3)
    • Android Studio at D:\Program Files\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-b2043.56-10027231)

[√] Connected device (4 available)
    • SM A5460 (mobile) • R5CW40T2LVH • android-arm64  • Android 13 (API 33)
    • Windows (desktop) • windows     • windows-x64    • Microsoft Windows [版本 10.0.19045.2364]
    • Chrome (web)      • chrome      • web-javascript • Google Chrome 120.0.6099.217
    • Edge (web)        • edge        • web-javascript • Microsoft Edge 113.0.1774.42

[√] Network resources
    • All expected network resources are available.

How to reproduce?

类似于一个手机国家区号选择的功能。左侧是200多条的区号数据,右侧是从A-Z的国家首字母列表。代码逻辑大致如下:

  1. 点击字母Z,并使用被包裹的ListView_controller对象,animTo( )接口,滑动到对应的垂直距离
  2. 同时在ListViewObserver_onObserve( )回调中,监听回调对象的index 此时,左侧列表已经滑动到了目标位置,200多条数据的末尾,但是onObserve( )回调中的数据极少。这个问题在缓慢滑动左侧列表时,是不会出现的,只有在调用ListView_controller.animTo( )接口时才会出现。 1705315420625

Logs

。。

Example code (optional)

。。

Contact

3581172209@qq.com

LinXunFeng commented 9 months ago

是否可以提供最小的可复现的示例代码?

chensimin920511 commented 9 months ago
  1. 附件是区域码文件,以及一些json对象

2.涉及其他的三方库: flutter_screenutil: ^5.8.4 lpinyin: ^2.0.3 provider: 6.0.5

  1. 数据解析 ///手机区域编码 final List<AreaInfo> _areaCodeList = []; String dataStr = await rootBundle.loadString('assets/areacode/code.txt'); area.AreaCodeEntity entity = area.AreaCodeEntity.fromJson(json.decode(dataStr)); List<area.Data> source = entity.data ?? []; for (area.Data data in source) { _areaCodeList.add(AreaInfo( name: data.name ?? "", pinyinFirstLetter: PinyinHelper.getFirstWordPinyin(data.name ?? "") .getFirstLowLetter(), enNameFirstLetter: (data.enName ?? "").getFirstLowLetter(), enName: data.enName ?? "", code: data.areaCode ?? "")); }

------------------ 原始邮件 ------------------ 发件人: "fluttercandies/flutter_scrollview_observer" @.>; 发送时间: 2024年1月15日(星期一) 晚上7:27 @.>; @.**@.>; 主题: Re: [fluttercandies/flutter_scrollview_observer] [Bug report] onObserve回调,监听数据不全 (Issue #70)

是否可以提供最小的可复现的示例代码?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

LinXunFeng commented 9 months ago

额,没有可以直接运行的小项目吗?

chensimin920511 commented 9 months ago

小demo晚点给你做一个

------------------ 原始邮件 ------------------ 发件人: "fluttercandies/flutter_scrollview_observer" @.>; 发送时间: 2024年1月15日(星期一) 晚上8:28 @.>; @.**@.>; 主题: Re: [fluttercandies/flutter_scrollview_observer] [Bug report] onObserve回调,监听数据不全 (Issue #70)

额,没有可以直接运行的小项目吗?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

chensimin920511 commented 9 months ago
  1. 点击主页+,进入选择页面 2.点击右侧底部Z 3.左侧跟随滑动到Z

日志如下: I/flutter (28803): onVerticalDragDown: 25, z I/flutter (28803): Observe: a,阿富汗,AreaItemType.item I/flutter (28803): Observe: b,白俄罗斯,AreaItemType.item @.***MainActivity: ViewPostIme pointer 1 I/flutter (28803): onTapDown:  I/flutter (28803): onVerticalDragCancel I/flutter (28803): onTapUp:  I/flutter (28803): Observe: n,尼加拉瓜,AreaItemType.item

左侧列表滑动observer()只回调了a,b,n

------------------ 原始邮件 ------------------ 发件人: "fluttercandies/flutter_scrollview_observer" @.>; 发送时间: 2024年1月15日(星期一) 晚上8:28 @.>; @.**@.>; 主题: Re: [fluttercandies/flutter_scrollview_observer] [Bug report] onObserve回调,监听数据不全 (Issue #70)

额,没有可以直接运行的小项目吗?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

LinXunFeng commented 9 months ago
  1. 点击主页+,进入选择页面 2.点击右侧底部Z 3.左侧跟随滑动到Z 日志如下: I/flutter (28803): onVerticalDragDown: 25, z I/flutter (28803): Observe: a,阿富汗,AreaItemType.item I/flutter (28803): Observe: b,白俄罗斯,AreaItemType.item @.MainActivity: ViewPostIme pointer 1 I/flutter (28803): onTapDown:  I/flutter (28803): onVerticalDragCancel I/flutter (28803): onTapUp:  I/flutter (28803): Observe: n,尼加拉瓜,AreaItemType.item 左侧列表滑动observer()只回调了a,b,n ------------------ 原始邮件 ------------------ 发件人: "fluttercandies/flutter_scrollview_observer" @.>; 发送时间: 2024年1月15日(星期一) 晚上8:28 @.>; @*.**@*.>; 主题: Re: [fluttercandies/flutter_scrollview_observer] [Bug report] onObserve回调,监听数据不全 (Issue #70) 额,没有可以直接运行的小项目吗? — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.>

是不是忘记传 demo 了?

LinXunFeng commented 8 months ago

因太久没有回复,先关闭了,有补充时可随时重新打开

chensimin920511 commented 8 months ago

1708485037691 附加里是有demo的哈。自己复现一下也很简单的,必现

LinXunFeng commented 8 months ago

1708485037691 附加里是有demo的哈。自己复现一下也很简单的,必现

@chensimin920511 我这边没看到附件,需要你将该附件在该 issue 的评论对话框里上传一下

LinXunFeng commented 8 months ago

@chensimin920511 我这边没看到附件,需要麻烦你将该附件在当前 issue 的评论对话框里上传一下 (会不会引用了内容后,你那边会收不到呢?)

chensimin920511 commented 8 months ago

scolltest.zip 把后缀.zip改成.7z。附件不支持.7z哈

LinXunFeng commented 8 months ago

https://github.com/fluttercandies/flutter_scrollview_observer/assets/19367531/41e5913e-3739-466a-8662-a8e622748b97

但是onObserve( )回调中的数据极少,你这句话我没太理解,是指上面录屏中打印的 b c i m... 中间少了的 d e f g h

如果是的话,那是正常的,scrollview_observer 的内部是靠监听 ScrollNotification,你用 NotificationListener 监听后打印 pixel 就能理解了

Widget _buildListLeft(List<AreaInfo> source) {
  Widget resultWidget = Container(
    margin: EdgeInsets.only(top: marginTop, left: 25.w, right: 25.w),
    child: ListViewObserver(
      onObserve: (model) {
        int? index = model.firstChild?.index;
        if (index != null) {
          ///例如:处理A B滑动临界点的问题
          index++;
          if (index >= source.length) {
            index = source.length - 1;
          }
          print(
              "Observe: ${areaList[index].getKeyLetter()},${areaList[index].name},${areaList[index].type}");
          _model.scrollKey =
              letterList.indexOf(areaList[index].getKeyLetter());
        }
      },
      child: ListView.builder(
          itemCount: source.length,
          controller: _controller,
          itemBuilder: (context, index) => _buildAreaItem(source[index])),
    ),
  );
  resultWidget = NotificationListener<ScrollNotification>(
    child: resultWidget,
    onNotification: (notification) {
      print('notification -- $notification - ${notification.metrics.pixels}');
      return false;
    },
  );
  return resultWidget;
}
flutter: notification -- ScrollStartNotification(depth: 0 (local), FixedScrollMetrics(0.0..[843.4]..20756.9)) - 0.0
flutter: notification -- ScrollUpdateNotification(depth: 0 (local), FixedScrollMetrics(833.0..[843.4]..19923.9), scrollDelta: 833.0410666666668) - 833.0410666666668
flutter: notification -- ScrollUpdateNotification(depth: 0 (local), FixedScrollMetrics(2579.2..[843.4]..18177.7), scrollDelta: 1746.1117661458334) - 2579.1528328125
flutter: notification -- ScrollUpdateNotification(depth: 0 (local), FixedScrollMetrics(6697.8..[843.4]..14059.1), scrollDelta: 4118.651315625) - 6697.804148437501
flutter: notification -- ScrollUpdateNotification(depth: 0 (local), FixedScrollMetrics(10750.5..[843.4]..10006.4), scrollDelta: 4052.64788034668) - 10750.45202878418
flutter: notification -- ScrollUpdateNotification(depth: 0 (local), FixedScrollMetrics(11430.6..[843.4]..9326.3), scrollDelta: 680.1948116455078) - 11430.646840429688
flutter: notification -- ScrollUpdateNotification(depth: 0 (local), FixedScrollMetrics(11577.3..[843.4]..9179.6), scrollDelta: 146.64604136556045) - 11577.292881795249
flutter: notification -- ScrollUpdateNotification(depth: 0 (local), FixedScrollMetrics(11621.7..[843.4]..9135.2), scrollDelta: 44.4225815130867) - 11621.715463308336
flutter: notification -- ScrollUpdateNotification(depth: 0 (local), FixedScrollMetrics(11621.7..[843.4]..9135.2), scrollDelta: 0.001870024998424924) - 11621.717333333334
flutter: notification -- ScrollEndNotification(depth: 0 (local), FixedScrollMetrics(11621.7..[843.4]..9135.2)) - 11621.717333333334

监听的滚动通知发多少次,scrollview_observer 就观察多少次