From 22a7afd99aeb34eb59abb01eb01bdaf30eb7d0b1 Mon Sep 17 00:00:00 2001 From: Bruno Leroux Date: Wed, 6 Nov 2024 09:34:36 +0100 Subject: [PATCH] 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). --- dev/bots/check_code_samples.dart | 1 - .../widgets/scrollbar/raw_scrollbar.0.dart | 89 ++++++++++--------- .../widgets/scrollbar/raw_scrollbar.2.dart | 8 +- .../scrollbar/raw_scrollbar.desktop.0.dart | 80 +++++++++-------- ...dart => raw_scrollbar.desktop.0_test.dart} | 3 +- 5 files changed, 93 insertions(+), 88 deletions(-) rename examples/api/test/widgets/scrollbar/{raw_scrollbar.desktop.0.dart => raw_scrollbar.desktop.0_test.dart} (93%) diff --git a/dev/bots/check_code_samples.dart b/dev/bots/check_code_samples.dart index f45e431d9ad..d7e21ef1a98 100644 --- a/dev/bots/check_code_samples.dart +++ b/dev/bots/check_code_samples.dart @@ -312,5 +312,4 @@ final Set _knownMissingTests = { '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', }; diff --git a/examples/api/lib/widgets/scrollbar/raw_scrollbar.0.dart b/examples/api/lib/widgets/scrollbar/raw_scrollbar.0.dart index 781a4965ca7..b64308326ea 100644 --- a/examples/api/lib/widgets/scrollbar/raw_scrollbar.0.dart +++ b/examples/api/lib/widgets/scrollbar/raw_scrollbar.0.dart @@ -32,11 +32,11 @@ class RawScrollbarExample extends StatefulWidget { } class _RawScrollbarExampleState extends State { - 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 { return Row( children: [ 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'), + ), + ); + }, + ), + ), + ), ], ); }); diff --git a/examples/api/lib/widgets/scrollbar/raw_scrollbar.2.dart b/examples/api/lib/widgets/scrollbar/raw_scrollbar.2.dart index e25eba1bd40..ead487f3425 100644 --- a/examples/api/lib/widgets/scrollbar/raw_scrollbar.2.dart +++ b/examples/api/lib/widgets/scrollbar/raw_scrollbar.2.dart @@ -30,21 +30,21 @@ class RawScrollbarExample extends StatefulWidget { } class _RawScrollbarExampleState extends State { - 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) { diff --git a/examples/api/lib/widgets/scrollbar/raw_scrollbar.desktop.0.dart b/examples/api/lib/widgets/scrollbar/raw_scrollbar.desktop.0.dart index ad2ecf4c02a..f3c4ff805a0 100644 --- a/examples/api/lib/widgets/scrollbar/raw_scrollbar.desktop.0.dart +++ b/examples/api/lib/widgets/scrollbar/raw_scrollbar.desktop.0.dart @@ -32,11 +32,11 @@ class DesktopExample extends StatefulWidget { } class _DesktopExampleState extends State { - 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 { return Row( children: [ 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'), - ), - ); - }, - ), - ), - )), + ), + ), + ), ], ); }); diff --git a/examples/api/test/widgets/scrollbar/raw_scrollbar.desktop.0.dart b/examples/api/test/widgets/scrollbar/raw_scrollbar.desktop.0_test.dart similarity index 93% rename from examples/api/test/widgets/scrollbar/raw_scrollbar.desktop.0.dart rename to examples/api/test/widgets/scrollbar/raw_scrollbar.desktop.0_test.dart index f05964b559c..7e733b6a675 100644 --- a/examples/api/test/widgets/scrollbar/raw_scrollbar.desktop.0.dart +++ b/examples/api/test/widgets/scrollbar/raw_scrollbar.desktop.0_test.dart @@ -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()); }