-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathbb_pullable_body.dart
More file actions
61 lines (57 loc) · 2.14 KB
/
Copy pathbb_pullable_body.dart
File metadata and controls
61 lines (57 loc) · 2.14 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
58
59
60
61
import 'package:bb_mobile/core/widgets/bb_refresh_indicator.dart';
import 'package:flutter/material.dart';
/// Standard pull-to-refresh body. Use this for any screen that supports
/// pull-to-refresh — it enforces the three invariants that make the gesture
/// reliable across the whole screen:
///
/// 1. Single scrollable (CustomScrollView) so notifications never fight with
/// nested ListView/SingleChildScrollView.
/// 2. `AlwaysScrollableScrollPhysics` so short content can still overscroll
/// and trigger refresh.
/// 3. `SliverFillRemaining(hasScrollBody: false)` appended so the scrollable
/// fills the viewport — the pull gesture works from anywhere on screen,
/// including any [bottomChild] that gets pinned to the bottom.
///
/// Pass screen content as [slivers]. If the screen has a footer (action
/// buttons, etc.) supply it as [bottomChild]; it will be pushed to the
/// bottom of the viewport when content is short, and follow the content
/// when it overflows.
class BBPullableBody extends StatelessWidget {
const BBPullableBody({
super.key,
this.indicatorKey,
required this.onRefresh,
required this.slivers,
this.bottomChild,
this.bottomInset = 0,
});
/// Forwarded to the inner [BBRefreshIndicator]. Use a
/// `GlobalKey<RefreshIndicatorState>` to call `.show()` programmatically.
final Key? indicatorKey;
final RefreshCallback onRefresh;
final List<Widget> slivers;
final Widget? bottomChild;
/// Space reserved at the end of the scroll content.
final double bottomInset;
@override
Widget build(BuildContext context) {
return BBRefreshIndicator(
indicatorKey: indicatorKey,
onRefresh: onRefresh,
child: CustomScrollView(
physics: const AlwaysScrollableScrollPhysics(),
slivers: [
...slivers,
if (bottomInset > 0)
SliverToBoxAdapter(child: SizedBox(height: bottomInset)),
SliverFillRemaining(
hasScrollBody: false,
child: bottomChild == null
? const SizedBox.shrink()
: Column(children: [const Spacer(), bottomChild!]),
),
],
),
);
}
}