Closed ciganovic-milan closed 1 month ago
I can also reproduce the behavior as reported. The issue also occurs if I delete text in TextField bit by bit as in the following video:
@huycozy Thanks for the swift reply Huy, I've also managed to reproduce it while just pasting the text into the textfield, although every so often.
My guess is that you'd want to check ScrollMetricsNotification.depth to make sure you are processing the notifications of the correct scrollable. Assuming you want to only listen notifications from the ListView, you want to make sure that the NotificationListener only processes notifications with a depth of 0 and ignores all others. In your current example, the listener likely also sees notifications from the scrollable that's build into the text field. See also: https://main-api.flutter.dev/flutter/widgets/ViewportNotificationMixin/depth.html
Does the problem go away if you include such a depth guard?
NotificationListener<ScrollMetricsNotification>(
onNotification: (state) {
if (state.depth != 0) return; // add this
setState(() {
_isScrollable = state.metrics.minScrollExtent !=
state.metrics.maxScrollExtent;
});
return true;
},
@goderbauer oh, what a nice find! Thank you very much Micheal and Huy, that indeed fixes the issue!
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v
and a minimal reproduction of the issue.
Steps to reproduce
TextField
NotificationListener
returnsmaxScrollExtent = 0
Expected results
TextField
NotificationListener
returns correctmaxScrollExtend
Actual results
The
NotificationListener
keeps bubbling up every time we close or show the keyboard, I'm not sure why is this even sending the notification updates?The maxScroll extend is 0 when the screen goes red in the example, meaning the view is not scrollable? š¤
Code sample
Code sample
```dart import 'package:flutter/material.dart'; class NotificationListenerExample extends StatefulWidget { const NotificationListenerExample({super.key}); @override StateScreenshots or Video
Screenshots / Video demonstration
Logs
Logs
```console [Paste your logs here] ```Flutter Doctor output
Doctor output
```console [ā] Flutter (Channel stable, 3.22.2, on macOS 14.5 23F79 darwin-arm64, locale en-RS) ā¢ Flutter version 3.22.2 on channel stable at /Users/user/flutter ā¢ Upstream repository https://github.com/flutter/flutter.git ā¢ Framework revision 761747bfc5 (6 weeks ago), 2024-06-05 22:15:13 +0200 ā¢ Engine revision edd8546116 ā¢ Dart version 3.4.3 ā¢ DevTools version 2.34.3 [ā] Android toolchain - develop for Android devices (Android SDK version 34.0.0) ā¢ Android SDK at /Users/user/Library/Android/sdk ā¢ Platform android-34, build-tools 34.0.0 ā¢ Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java ā¢ Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11572160) ā¢ All Android licenses accepted. [ā] Xcode - develop for iOS and macOS (Xcode 15.4) ā¢ Xcode at /Applications/Xcode.app/Contents/Developer ā¢ Build 15F31d ā¢ CocoaPods version 1.15.2 [ā] Chrome - develop for the web ā¢ Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [ā] Android Studio (version 2023.3) ā¢ Android Studio at /Applications/Android Studio.app/Contents ā¢ 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.10+0-17.0.10b1087.21-11572160) [ā] Connected device (3 available) ā¢ macOS (desktop) ā¢ macos ā¢ darwin-arm64 ā¢ macOS 14.5 23F79 darwin-arm64 ā¢ Mac Designed for iPad (desktop) ā¢ mac-designed-for-ipad ā¢ darwin ā¢ macOS 14.5 23F79 darwin-arm64 ā¢ Chrome (web) ā¢ chrome ā¢ web-javascript ā¢ Google Chrome 126.0.6478.127 [ā] Network resources ā¢ All expected network resources are available. ā¢ No issues found! ```