Skip to content

[Bug report] scrollExtent 高度异常 #127

Closed
@944095635

Description

@944095635

Version

1.26.0

Platforms

dart

Device Model

any

flutter info

[√] Flutter (Channel stable, 3.29.3, on Microsoft Windows [版本 10.0.26100.3775], locale zh-CN) [493ms]
    • Flutter version 3.29.3 on channel stable at E:\Flutter\SDK
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision ea121f8859 (5 weeks ago), 2025-04-11 19:10:07 +0000
    • Engine revision cf56914b32
    • Dart version 3.7.2
    • DevTools version 2.42.3

[√] Windows Version (Windows 11 or higher, 24H2, 2009) [1,901ms]

[√] Android toolchain - develop for Android devices (Android SDK version 35.0.1) [2.8s]
    • Android SDK at E:\AndroidSDK
    • Platform android-35, build-tools 35.0.1
    • ANDROID_HOME = E:\AndroidSDK
    • Java binary at: E:\AndroidStudio\jbr\bin\java
      This is the JDK bundled with the latest Android Studio installation on this machine.
      To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
    • Java version OpenJDK Runtime Environment (build 21.0.6+-13368085-b895.109)
    • All Android licenses accepted.

[√] Connected device (3 available) [517ms]
    • IN2020 (mobile)   • 973b6 • android-arm64  • Android 15 (API 35)
    • Windows (desktop) • windows  • windows-x64    • Microsoft Windows [版本 10.0.26100.3775]
    • Edge (web)        • edge     • web-javascript • Microsoft Edge 135.0.3179.98

How to reproduce?

首次进入某个使用List的聊天页面,
增加日志信息,如下:

I/flutter (10266): scrollExtent:0.0
I/flutter (10266): viewportMainAxisExtent:807.1438571428571
I/flutter (10266): scrollExtent:319.42857142857144
I/flutter (10266): viewportMainAxisExtent:807.1438571428571

退出后再次进入页面,日志如下:

I/flutter (10266): scrollExtent:0.0
I/flutter (10266): viewportMainAxisExtent:807.1438571428571
I/flutter (10266): scrollExtent:1694.1203377902884
I/flutter (10266): viewportMainAxisExtent:807.1438571428571

因为 计算出错,导致 innerIsShrinkWrap 不匹配

具体日志位置:

C:\Users\XX\AppData\Local\Pub\Cache\hosted\pub.dev\scrollview_observer-1.26.0\lib\src\utils\src\chat\chat_scroll_observer.dart
observeSwitchShrinkWrap() {
    ambiguate(WidgetsBinding.instance)?.addPostFrameCallback((_) {
      final ctx = observerController.fetchSliverContext();
      if (ctx == null) return;
      final obj = ObserverUtils.findRenderObject(ctx);
      if (obj is! RenderSliver) return;
      final constraints = ObserverUtils.sliverConstraints(obj);
      if (constraints == null) return;
      final viewportMainAxisExtent = constraints.viewportMainAxisExtent;
      final scrollExtent = obj.geometry?.scrollExtent ?? 0;
      debugPrint("scrollExtent:" + scrollExtent.toString());
      debugPrint("viewportMainAxisExtent:" + viewportMainAxisExtent.toString());
      if (viewportMainAxisExtent >= scrollExtent) {
        if (innerIsShrinkWrap) return;
        innerIsShrinkWrap = true;
        observerController.reattach();
        toRebuildScrollViewCallback?.call();
      } else {
        if (!innerIsShrinkWrap) return;
        innerIsShrinkWrap = false;
        observerController.reattach();
        toRebuildScrollViewCallback?.call();
      }
    });

Logs

Example code (optional)

Contact

No response

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions