Updating PrimaryScrollController for Desktop (#102099)
This commit is contained in:
@@ -45,8 +45,9 @@ class _MyStatefulWidgetState extends State<MyStatefulWidget> {
|
||||
children: <Widget>[
|
||||
SizedBox(
|
||||
width: constraints.maxWidth / 2,
|
||||
// Only one scroll position can be attached to the
|
||||
// PrimaryScrollController if using Scrollbars. Providing a
|
||||
// When using the PrimaryScrollController and a Scrollbar
|
||||
// together, only one ScrollPosition can be attached to the
|
||||
// PrimaryScrollController at a time. Providing a
|
||||
// unique scroll controller to this scroll view prevents it
|
||||
// from attaching to the PrimaryScrollController.
|
||||
child: Scrollbar(
|
||||
@@ -64,12 +65,15 @@ class _MyStatefulWidgetState extends State<MyStatefulWidget> {
|
||||
)),
|
||||
SizedBox(
|
||||
width: constraints.maxWidth / 2,
|
||||
// This vertical scroll view has not been provided a
|
||||
// ScrollController, so it is using the
|
||||
// PrimaryScrollController.
|
||||
// This vertical scroll view has primary set to true, so it is
|
||||
// using the PrimaryScrollController. On mobile platforms, the
|
||||
// PrimaryScrollController automatically attaches to vertical
|
||||
// ScrollViews, unlike on Desktop platforms, where the primary
|
||||
// parameter is required.
|
||||
child: Scrollbar(
|
||||
thumbVisibility: true,
|
||||
child: ListView.builder(
|
||||
primary: true,
|
||||
itemCount: 100,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
return Container(
|
||||
|
||||
@@ -35,6 +35,11 @@ class MyStatelessWidget extends StatelessWidget {
|
||||
thumbColor: Colors.blue,
|
||||
thumbVisibility: true,
|
||||
child: ListView(
|
||||
// On mobile platforms, setting primary to true is not required, as
|
||||
// the PrimaryScrollController automatically attaches to vertical
|
||||
// ScrollPositions. On desktop platforms however, using the
|
||||
// PrimaryScrollController requires ScrollView.primary be set.
|
||||
primary: true,
|
||||
physics: const BouncingScrollPhysics(),
|
||||
children: List<Text>.generate(
|
||||
100, (int index) => Text((index * index).toString())),
|
||||
|
||||
Reference in New Issue
Block a user