Skip to content

Commit 8833bea

Browse files
committed
scroll [nfc]: Give SingleChildScrollViewWithScrollbar docs and a new home
1 parent c92c71e commit 8833bea

File tree

2 files changed

+40
-27
lines changed

2 files changed

+40
-27
lines changed

lib/widgets/content.dart

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import 'inset_shadow.dart';
2222
import 'lightbox.dart';
2323
import 'message_list.dart';
2424
import 'poll.dart';
25+
import 'scrolling.dart';
2526
import 'store.dart';
2627
import 'text.dart';
2728

@@ -796,33 +797,6 @@ class _CodeBlockContainer extends StatelessWidget {
796797
}
797798
}
798799

799-
class SingleChildScrollViewWithScrollbar extends StatefulWidget {
800-
const SingleChildScrollViewWithScrollbar(
801-
{super.key, required this.scrollDirection, required this.child});
802-
803-
final Axis scrollDirection;
804-
final Widget child;
805-
806-
@override
807-
State<SingleChildScrollViewWithScrollbar> createState() =>
808-
_SingleChildScrollViewWithScrollbarState();
809-
}
810-
811-
class _SingleChildScrollViewWithScrollbarState
812-
extends State<SingleChildScrollViewWithScrollbar> {
813-
final ScrollController controller = ScrollController();
814-
815-
@override
816-
Widget build(BuildContext context) {
817-
return Scrollbar(
818-
controller: controller,
819-
child: SingleChildScrollView(
820-
controller: controller,
821-
scrollDirection: widget.scrollDirection,
822-
child: widget.child));
823-
}
824-
}
825-
826800
class MathBlock extends StatelessWidget {
827801
const MathBlock({super.key, required this.node});
828802

lib/widgets/scrolling.dart

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import 'package:flutter/material.dart';
2+
3+
/// A [SingleChildScrollView] that always shows a Material [Scrollbar].
4+
///
5+
/// This differs from the behavior provided by [MaterialScrollBehavior] in that
6+
/// (a) the scrollbar appears even when [scrollDirection] is [Axis.horizontal],
7+
/// and (b) the scrollbar appears on all platforms, rather than only on
8+
/// desktop platforms.
9+
// TODO(upstream): SingleChildScrollView should have a scrollBehavior field
10+
// and pass it on to Scrollable, just like ScrollView does; then this would
11+
// be covered by using that.
12+
// TODO: Maybe show scrollbar only on mobile platforms, like MaterialScrollBehavior
13+
// and the base ScrollBehavior do?
14+
class SingleChildScrollViewWithScrollbar extends StatefulWidget {
15+
const SingleChildScrollViewWithScrollbar(
16+
{super.key, required this.scrollDirection, required this.child});
17+
18+
final Axis scrollDirection;
19+
final Widget child;
20+
21+
@override
22+
State<SingleChildScrollViewWithScrollbar> createState() =>
23+
_SingleChildScrollViewWithScrollbarState();
24+
}
25+
26+
class _SingleChildScrollViewWithScrollbarState
27+
extends State<SingleChildScrollViewWithScrollbar> {
28+
final ScrollController controller = ScrollController();
29+
30+
@override
31+
Widget build(BuildContext context) {
32+
return Scrollbar(
33+
controller: controller,
34+
child: SingleChildScrollView(
35+
controller: controller,
36+
scrollDirection: widget.scrollDirection,
37+
child: widget.child));
38+
}
39+
}

0 commit comments

Comments
 (0)