-
Notifications
You must be signed in to change notification settings - Fork 26.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updating PrimaryScrollController for Desktop #102099
Conversation
@@ -96,6 +96,7 @@ class PaletteTabView extends StatelessWidget { | |||
final TextStyle blackTextStyle = textTheme.bodyText2!.copyWith(color: Colors.black); | |||
return Scrollbar( | |||
child: ListView( | |||
primary: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without this, the test will fail when run configured to desktop, because it is no longer automatic.
@@ -34,14 +44,18 @@ class PrimaryScrollController extends InheritedWidget { | |||
const PrimaryScrollController({ | |||
super.key, | |||
required ScrollController this.controller, | |||
this.autoForPlatforms = _kMobilePlatforms, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not like this name, but have not thought of something else yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -96,6 +96,7 @@ class PaletteTabView extends StatelessWidget { | |||
final TextStyle blackTextStyle = textTheme.bodyText2!.copyWith(color: Colors.black); | |||
return Scrollbar( | |||
child: ListView( | |||
primary: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for my own understanding: why were you able to simplify this so much?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is where I relocated some of the logic from isEnabled, after we know it is safe to access the position.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
}()); | ||
|
||
if (primaryScrollController!.position.context.notificationContext == null | ||
&& Scrollable.of(primaryScrollController.position.context.notificationContext!) == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
automaticallyInheritForPlatforms
scrollDirection
Also 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.