modal_scroll_controller.dart
1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
/// Associates a [ScrollController] with a subtree.
///
/// This mechanism can be used to provide default behavior for scroll views in a
/// subtree inside a modal bottom sheet.
///
/// We want to remove this and use [PrimaryScrollController].
/// This issue should be solved first https://github.com/flutter/flutter/issues/64236
///
/// See [PrimaryScrollController]
class ModalScrollController extends InheritedWidget {
/// Creates a widget that associates a [ScrollController] with a subtree.
ModalScrollController({
Key? key,
required this.controller,
required Widget child,
}) : super(
key: key,
child: PrimaryScrollController(
controller: controller,
child: child,
),
);
/// The [ScrollController] associated with the subtree.
///
/// See also:
///
/// * [ScrollView.controller], which discusses the purpose of specifying a
/// scroll controller.
final ScrollController controller;
/// Returns the [ScrollController] most closely associated with the given
/// context.
///
/// Returns null if there is no [ScrollController] associated with the given
/// context.
static ScrollController? of(BuildContext context) {
final result =
context.dependOnInheritedWidgetOfExactType<ModalScrollController>();
return result?.controller;
}
@override
bool updateShouldNotify(ModalScrollController oldWidget) =>
controller != oldWidget.controller;
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(DiagnosticsProperty<ScrollController>(
'controller', controller,
ifNull: 'no controller', showName: false));
}
}