Updating PrimaryScrollController for Desktop#102099
Conversation
There was a problem hiding this comment.
These integration tests are run on mobile and desktop platforms, so I have added primary: true so they all inherit the PrimaryScrollController as they did so automatically prior to this change.
There was a problem hiding this comment.
Why is this important, though? Would anything break if we don't do this? Does this mean we are breaking users as well and they need to go in to make this change in their apps?
There was a problem hiding this comment.
Only on desktop, which is the point of this change.
The automatic attachment of the PrimaryScrollController will no longer happen on desktop. Thee integration test expect that behavior across all of the platforms. The tests could be refactored for each platform, but that seemed outside of the scope for this change.
There was a problem hiding this comment.
Without this, the test will fail when run configured to desktop, because it is no longer automatic.
There was a problem hiding this comment.
I do not like this name, but have not thought of something else yet.
There was a problem hiding this comment.
+1 - brainstorming some other suggestions:
enabledPlatforms- can you do anything with this of running on a platform that's not part of this set?inheritOnPlatforms
... naming is hard.
There was a problem hiding this comment.
It is tricky because it can be inherited on any platform, this is specific to the automatic inheritance.
There was a problem hiding this comment.
can you do anything with this of running on a platform that's not part of this set?
I am not sure I understand this question
There was a problem hiding this comment.
Why is this important, though? Would anything break if we don't do this? Does this mean we are breaking users as well and they need to go in to make this change in their apps?
dev/integration_tests/flutter_gallery/lib/demo/material/elevation_demo.dart
Outdated
Show resolved
Hide resolved
dev/integration_tests/flutter_gallery/lib/demo/typography_demo.dart
Outdated
Show resolved
Hide resolved
packages/flutter/lib/src/widgets/primary_scroll_controller.dart
Outdated
Show resolved
Hide resolved
| && Scrollable.of(primaryScrollController.position.context.notificationContext!) != null; | ||
| } | ||
| final ScrollController? primaryScrollController = PrimaryScrollController.of(focus.context!); | ||
| return primaryScrollController != null && primaryScrollController.hasClients; |
There was a problem hiding this comment.
for my own understanding: why were you able to simplify this so much?
There was a problem hiding this comment.
I moved much of this logic to the invoke method. Accessing the position here would throw an error (the bug we are fixing), but the error did not make sense in the stack trace that would result from throwing here.
By throwing from invoke, I thought it would make more sense.
| /// | ||
| /// If a [ScrollController] has already been provided to | ||
| /// [ScrollView.controller], or [ScrollView.primary] is false, this is | ||
| /// disregarded. |
There was a problem hiding this comment.
Added more docs, let me know what you think.
| && Scrollable.of(primaryScrollController.position.context.notificationContext!) != null; | ||
| } | ||
| final ScrollController? primaryScrollController = PrimaryScrollController.of(focus.context!); | ||
| return primaryScrollController != null && primaryScrollController.hasClients; |
There was a problem hiding this comment.
I moved much of this logic to the invoke method. Accessing the position here would throw an error (the bug we are fixing), but the error did not make sense in the stack trace that would result from throwing here.
By throwing from invoke, I thought it would make more sense.
| && Scrollable.of(primaryScrollController.position.context.notificationContext!) == null) { | ||
| return; | ||
| } | ||
| state = Scrollable.of(primaryScrollController.position.context.notificationContext!); |
There was a problem hiding this comment.
This is where I relocated some of the logic from isEnabled, after we know it is safe to access the position.
| }()); | ||
|
|
||
| if (primaryScrollController!.position.context.notificationContext == null | ||
| && Scrollable.of(primaryScrollController.position.context.notificationContext!) == null) { |
There was a problem hiding this comment.
nit: indentation is off here (condition continuation and body should not have same indentation level). I think I would just indent this line by 2 more spaces...
|
This pull request is not suitable for automatic merging in its current state.
|
This updates the PrimaryScrollController to not automatically attach to scroll views on desktop as it does on mobile platforms.
This behavior has caused a lot of issues for users developing desktop applications that have multiple parallel vertical ScrollViews.
This adds two parameters to PrimaryScrollController
automaticallyInheritForPlatformsscrollDirectionAlso adds static method
shouldInherit, which uses the two properties above to determine if automatically inheriting the ScrollController is appropriate for the current configuration.This design and other approaches is discussed at length in this design document.
Fixes #100264
Related (among others):
Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.