mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
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).
This commit is contained in:
parent
66e8f53ba0
commit
22a7afd99a
@ -312,5 +312,4 @@ final Set<String> _knownMissingTests = <String>{
|
||||
'examples/api/test/material/color_scheme/dynamic_content_color.0_test.dart',
|
||||
'examples/api/test/widgets/image/image.frame_builder.0_test.dart',
|
||||
'examples/api/test/widgets/image/image.loading_builder.0_test.dart',
|
||||
'examples/api/test/widgets/scrollbar/raw_scrollbar.desktop.0_test.dart',
|
||||
};
|
||||
|
@ -32,11 +32,11 @@ class RawScrollbarExample extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _RawScrollbarExampleState extends State<RawScrollbarExample> {
|
||||
final ScrollController _firstController = ScrollController();
|
||||
final ScrollController _controller = ScrollController();
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_firstController.dispose();
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@ -46,47 +46,52 @@ class _RawScrollbarExampleState extends State<RawScrollbarExample> {
|
||||
return Row(
|
||||
children: <Widget>[
|
||||
SizedBox(
|
||||
width: constraints.maxWidth / 2,
|
||||
// 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(
|
||||
thumbVisibility: true,
|
||||
controller: _firstController,
|
||||
child: ListView.builder(
|
||||
controller: _firstController,
|
||||
itemCount: 100,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Text('Scrollable 1 : Index $index'),
|
||||
);
|
||||
}),
|
||||
)),
|
||||
width: constraints.maxWidth / 2,
|
||||
// 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(
|
||||
thumbVisibility: true,
|
||||
controller: _controller,
|
||||
child: ListView.builder(
|
||||
controller: _controller,
|
||||
itemCount: 100,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Text('Scrollable 1 : Index $index'),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: constraints.maxWidth / 2,
|
||||
// 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(
|
||||
height: 50,
|
||||
color: index.isEven ? Colors.amberAccent : Colors.blueAccent,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Text('Scrollable 2 : Index $index'),
|
||||
));
|
||||
}),
|
||||
)),
|
||||
width: constraints.maxWidth / 2,
|
||||
// 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(
|
||||
height: 50,
|
||||
color: index.isEven ? Colors.amberAccent : Colors.blueAccent,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Text('Scrollable 2 : Index $index'),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
});
|
||||
|
@ -30,21 +30,21 @@ class RawScrollbarExample extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _RawScrollbarExampleState extends State<RawScrollbarExample> {
|
||||
final ScrollController _controllerOne = ScrollController();
|
||||
final ScrollController _controller = ScrollController();
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controllerOne.dispose();
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return RawScrollbar(
|
||||
controller: _controllerOne,
|
||||
controller: _controller,
|
||||
thumbVisibility: true,
|
||||
child: GridView.builder(
|
||||
controller: _controllerOne,
|
||||
controller: _controller,
|
||||
itemCount: 120,
|
||||
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3),
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
|
@ -32,11 +32,11 @@ class DesktopExample extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _DesktopExampleState extends State<DesktopExample> {
|
||||
final ScrollController controller = ScrollController();
|
||||
final ScrollController _controller = ScrollController();
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
controller.dispose();
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@ -46,54 +46,56 @@ class _DesktopExampleState extends State<DesktopExample> {
|
||||
return Row(
|
||||
children: <Widget>[
|
||||
SizedBox(
|
||||
width: constraints.maxWidth / 2,
|
||||
// When running this sample on desktop, two scrollbars will be
|
||||
// visible here. One is the default scrollbar and the other is the
|
||||
// Scrollbar widget with custom thickness.
|
||||
child: Scrollbar(
|
||||
thickness: 20.0,
|
||||
thumbVisibility: true,
|
||||
controller: controller,
|
||||
width: constraints.maxWidth / 2,
|
||||
// When running this sample on desktop, two scrollbars will be
|
||||
// visible here. One is the default scrollbar and the other is the
|
||||
// Scrollbar widget with custom thickness.
|
||||
child: Scrollbar(
|
||||
thickness: 20.0,
|
||||
thumbVisibility: true,
|
||||
controller: _controller,
|
||||
child: ListView.builder(
|
||||
controller: _controller,
|
||||
itemCount: 100,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
return SizedBox(
|
||||
height: 50,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Text('Scrollable 1 : Index $index'),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: constraints.maxWidth / 2,
|
||||
// When running this sample on desktop, one scrollbar will be
|
||||
// visible here. The default scrollbar is hidden by setting the
|
||||
// ScrollConfiguration's scrollbars to false. The Scrollbar widget
|
||||
// with custom thickness is visible.
|
||||
child: Scrollbar(
|
||||
thickness: 20.0,
|
||||
thumbVisibility: true,
|
||||
child: ScrollConfiguration(
|
||||
behavior: ScrollConfiguration.of(context).copyWith(scrollbars: false),
|
||||
child: ListView.builder(
|
||||
controller: controller,
|
||||
primary: true,
|
||||
itemCount: 100,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
return SizedBox(
|
||||
height: 50,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Text('Scrollable 1 : Index $index'),
|
||||
child: Text('Scrollable 2 : Index $index'),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
)),
|
||||
SizedBox(
|
||||
width: constraints.maxWidth / 2,
|
||||
// When running this sample on desktop, one scrollbar will be
|
||||
// visible here. The default scrollbar is hidden by setting the
|
||||
// ScrollConfiguration's scrollbars to false. The Scrollbar widget
|
||||
// with custom thickness is visible.
|
||||
child: Scrollbar(
|
||||
thickness: 20.0,
|
||||
thumbVisibility: true,
|
||||
child: ScrollConfiguration(
|
||||
behavior: ScrollConfiguration.of(context).copyWith(scrollbars: false),
|
||||
child: ListView.builder(
|
||||
primary: true,
|
||||
itemCount: 100,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
return SizedBox(
|
||||
height: 50,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Text('Scrollable 2 : Index $index'),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
)),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
});
|
||||
|
@ -8,7 +8,6 @@ import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Can hide default scrollbar on desktop', (WidgetTester tester) async {
|
||||
|
||||
await tester.pumpWidget(
|
||||
const example.ScrollbarApp(),
|
||||
);
|
||||
@ -16,5 +15,5 @@ void main() {
|
||||
// Two from left list view where scroll configuration is not set.
|
||||
// One from right list view where scroll configuration is set.
|
||||
expect(find.byType(Scrollbar), findsNWidgets(3));
|
||||
});
|
||||
}, variant: TargetPlatformVariant.desktop());
|
||||
}
|
Loading…
Reference in New Issue
Block a user