Skip to content

Commit 22a7afd

Browse files
authored
Fix RawScrollbar examples and desktop test (#158237)
## Description Fix the formatting of some `RawScrollbar` examples. Fix and rename one test file (name without `_test` suffix).
1 parent 66e8f53 commit 22a7afd

File tree

5 files changed

+93
-88
lines changed

5 files changed

+93
-88
lines changed

dev/bots/check_code_samples.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,5 +312,4 @@ final Set<String> _knownMissingTests = <String>{
312312
'examples/api/test/material/color_scheme/dynamic_content_color.0_test.dart',
313313
'examples/api/test/widgets/image/image.frame_builder.0_test.dart',
314314
'examples/api/test/widgets/image/image.loading_builder.0_test.dart',
315-
'examples/api/test/widgets/scrollbar/raw_scrollbar.desktop.0_test.dart',
316315
};

examples/api/lib/widgets/scrollbar/raw_scrollbar.0.dart

Lines changed: 47 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ class RawScrollbarExample extends StatefulWidget {
3232
}
3333

3434
class _RawScrollbarExampleState extends State<RawScrollbarExample> {
35-
final ScrollController _firstController = ScrollController();
35+
final ScrollController _controller = ScrollController();
3636

3737
@override
3838
void dispose() {
39-
_firstController.dispose();
39+
_controller.dispose();
4040
super.dispose();
4141
}
4242

@@ -46,47 +46,52 @@ class _RawScrollbarExampleState extends State<RawScrollbarExample> {
4646
return Row(
4747
children: <Widget>[
4848
SizedBox(
49-
width: constraints.maxWidth / 2,
50-
// When using the PrimaryScrollController and a Scrollbar
51-
// together, only one ScrollPosition can be attached to the
52-
// PrimaryScrollController at a time. Providing a
53-
// unique scroll controller to this scroll view prevents it
54-
// from attaching to the PrimaryScrollController.
55-
child: Scrollbar(
56-
thumbVisibility: true,
57-
controller: _firstController,
58-
child: ListView.builder(
59-
controller: _firstController,
60-
itemCount: 100,
61-
itemBuilder: (BuildContext context, int index) {
62-
return Padding(
63-
padding: const EdgeInsets.all(8.0),
64-
child: Text('Scrollable 1 : Index $index'),
65-
);
66-
}),
67-
)),
49+
width: constraints.maxWidth / 2,
50+
// When using the PrimaryScrollController and a Scrollbar
51+
// together, only one ScrollPosition can be attached to the
52+
// PrimaryScrollController at a time. Providing a
53+
// unique scroll controller to this scroll view prevents it
54+
// from attaching to the PrimaryScrollController.
55+
child: Scrollbar(
56+
thumbVisibility: true,
57+
controller: _controller,
58+
child: ListView.builder(
59+
controller: _controller,
60+
itemCount: 100,
61+
itemBuilder: (BuildContext context, int index) {
62+
return Padding(
63+
padding: const EdgeInsets.all(8.0),
64+
child: Text('Scrollable 1 : Index $index'),
65+
);
66+
},
67+
),
68+
),
69+
),
6870
SizedBox(
69-
width: constraints.maxWidth / 2,
70-
// This vertical scroll view has primary set to true, so it is
71-
// using the PrimaryScrollController. On mobile platforms, the
72-
// PrimaryScrollController automatically attaches to vertical
73-
// ScrollViews, unlike on Desktop platforms, where the primary
74-
// parameter is required.
75-
child: Scrollbar(
76-
thumbVisibility: true,
77-
child: ListView.builder(
78-
primary: true,
79-
itemCount: 100,
80-
itemBuilder: (BuildContext context, int index) {
81-
return Container(
82-
height: 50,
83-
color: index.isEven ? Colors.amberAccent : Colors.blueAccent,
84-
child: Padding(
85-
padding: const EdgeInsets.all(8.0),
86-
child: Text('Scrollable 2 : Index $index'),
87-
));
88-
}),
89-
)),
71+
width: constraints.maxWidth / 2,
72+
// This vertical scroll view has primary set to true, so it is
73+
// using the PrimaryScrollController. On mobile platforms, the
74+
// PrimaryScrollController automatically attaches to vertical
75+
// ScrollViews, unlike on Desktop platforms, where the primary
76+
// parameter is required.
77+
child: Scrollbar(
78+
thumbVisibility: true,
79+
child: ListView.builder(
80+
primary: true,
81+
itemCount: 100,
82+
itemBuilder: (BuildContext context, int index) {
83+
return Container(
84+
height: 50,
85+
color: index.isEven ? Colors.amberAccent : Colors.blueAccent,
86+
child: Padding(
87+
padding: const EdgeInsets.all(8.0),
88+
child: Text('Scrollable 2 : Index $index'),
89+
),
90+
);
91+
},
92+
),
93+
),
94+
),
9095
],
9196
);
9297
});

examples/api/lib/widgets/scrollbar/raw_scrollbar.2.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,21 @@ class RawScrollbarExample extends StatefulWidget {
3030
}
3131

3232
class _RawScrollbarExampleState extends State<RawScrollbarExample> {
33-
final ScrollController _controllerOne = ScrollController();
33+
final ScrollController _controller = ScrollController();
3434

3535
@override
3636
void dispose() {
37-
_controllerOne.dispose();
37+
_controller.dispose();
3838
super.dispose();
3939
}
4040

4141
@override
4242
Widget build(BuildContext context) {
4343
return RawScrollbar(
44-
controller: _controllerOne,
44+
controller: _controller,
4545
thumbVisibility: true,
4646
child: GridView.builder(
47-
controller: _controllerOne,
47+
controller: _controller,
4848
itemCount: 120,
4949
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3),
5050
itemBuilder: (BuildContext context, int index) {

examples/api/lib/widgets/scrollbar/raw_scrollbar.desktop.0.dart

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ class DesktopExample extends StatefulWidget {
3232
}
3333

3434
class _DesktopExampleState extends State<DesktopExample> {
35-
final ScrollController controller = ScrollController();
35+
final ScrollController _controller = ScrollController();
3636

3737
@override
3838
void dispose() {
39-
controller.dispose();
39+
_controller.dispose();
4040
super.dispose();
4141
}
4242

@@ -46,54 +46,56 @@ class _DesktopExampleState extends State<DesktopExample> {
4646
return Row(
4747
children: <Widget>[
4848
SizedBox(
49-
width: constraints.maxWidth / 2,
50-
// When running this sample on desktop, two scrollbars will be
51-
// visible here. One is the default scrollbar and the other is the
52-
// Scrollbar widget with custom thickness.
53-
child: Scrollbar(
54-
thickness: 20.0,
55-
thumbVisibility: true,
56-
controller: controller,
49+
width: constraints.maxWidth / 2,
50+
// When running this sample on desktop, two scrollbars will be
51+
// visible here. One is the default scrollbar and the other is the
52+
// Scrollbar widget with custom thickness.
53+
child: Scrollbar(
54+
thickness: 20.0,
55+
thumbVisibility: true,
56+
controller: _controller,
57+
child: ListView.builder(
58+
controller: _controller,
59+
itemCount: 100,
60+
itemBuilder: (BuildContext context, int index) {
61+
return SizedBox(
62+
height: 50,
63+
child: Padding(
64+
padding: const EdgeInsets.all(8.0),
65+
child: Text('Scrollable 1 : Index $index'),
66+
),
67+
);
68+
},
69+
),
70+
),
71+
),
72+
SizedBox(
73+
width: constraints.maxWidth / 2,
74+
// When running this sample on desktop, one scrollbar will be
75+
// visible here. The default scrollbar is hidden by setting the
76+
// ScrollConfiguration's scrollbars to false. The Scrollbar widget
77+
// with custom thickness is visible.
78+
child: Scrollbar(
79+
thickness: 20.0,
80+
thumbVisibility: true,
81+
child: ScrollConfiguration(
82+
behavior: ScrollConfiguration.of(context).copyWith(scrollbars: false),
5783
child: ListView.builder(
58-
controller: controller,
84+
primary: true,
5985
itemCount: 100,
6086
itemBuilder: (BuildContext context, int index) {
6187
return SizedBox(
6288
height: 50,
6389
child: Padding(
6490
padding: const EdgeInsets.all(8.0),
65-
child: Text('Scrollable 1 : Index $index'),
91+
child: Text('Scrollable 2 : Index $index'),
6692
),
6793
);
6894
},
6995
),
70-
)),
71-
SizedBox(
72-
width: constraints.maxWidth / 2,
73-
// When running this sample on desktop, one scrollbar will be
74-
// visible here. The default scrollbar is hidden by setting the
75-
// ScrollConfiguration's scrollbars to false. The Scrollbar widget
76-
// with custom thickness is visible.
77-
child: Scrollbar(
78-
thickness: 20.0,
79-
thumbVisibility: true,
80-
child: ScrollConfiguration(
81-
behavior: ScrollConfiguration.of(context).copyWith(scrollbars: false),
82-
child: ListView.builder(
83-
primary: true,
84-
itemCount: 100,
85-
itemBuilder: (BuildContext context, int index) {
86-
return SizedBox(
87-
height: 50,
88-
child: Padding(
89-
padding: const EdgeInsets.all(8.0),
90-
child: Text('Scrollable 2 : Index $index'),
91-
),
92-
);
93-
},
94-
),
95-
),
96-
)),
96+
),
97+
),
98+
),
9799
],
98100
);
99101
});

examples/api/test/widgets/scrollbar/raw_scrollbar.desktop.0.dart renamed to examples/api/test/widgets/scrollbar/raw_scrollbar.desktop.0_test.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@ import 'package:flutter_test/flutter_test.dart';
88

99
void main() {
1010
testWidgets('Can hide default scrollbar on desktop', (WidgetTester tester) async {
11-
1211
await tester.pumpWidget(
1312
const example.ScrollbarApp(),
1413
);
1514

1615
// Two from left list view where scroll configuration is not set.
1716
// One from right list view where scroll configuration is set.
1817
expect(find.byType(Scrollbar), findsNWidgets(3));
19-
});
18+
}, variant: TargetPlatformVariant.desktop());
2019
}

0 commit comments

Comments
 (0)