-
Notifications
You must be signed in to change notification settings - Fork 22
/
bouncing_behaviors.dart
123 lines (113 loc) · 3.74 KB
/
bouncing_behaviors.dart
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import 'package:flutter/material.dart';
import 'package:smooth_sheets/smooth_sheets.dart';
void main() {
runApp(const MaterialApp(home: _Home()));
}
class _Home extends StatelessWidget {
const _Home();
@override
Widget build(BuildContext context) {
void showModalSheet(Widget sheet) {
Navigator.push(context, ModalSheetRoute(builder: (_) => sheet));
}
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ListTile(
title: const Text('FixedBouncingBehavior'),
subtitle: const Text('with ScrollableSheet'),
onTap: () => showModalSheet(
const _ScrollableSheet(
behavior: FixedBouncingBehavior(
// Allows the sheet position to exceed the content bounds
// by ±10% of the content height.
SheetAnchor.proportional(0.1),
),
),
),
),
ListTile(
title: const Text('FixedBouncingBehavior'),
subtitle: const Text('with DraggableSheet'),
onTap: () => showModalSheet(
const _DraggableSheet(
behavior: FixedBouncingBehavior(
// Allows the sheet position to exceed the content bounds by ±50 pixels.
SheetAnchor.pixels(50),
),
),
),
),
ListTile(
title: const Text('DirectionAwareBouncingBehavior'),
subtitle: const Text('with ScrollableSheet'),
onTap: () => showModalSheet(
const _ScrollableSheet(
behavior: DirectionAwareBouncingBehavior(
// Allows the sheet position to exceed the content bounds by 10 pixels
// when dragging the sheet upwards, and by ±30% of the content height
// when dragging it downwards.
upward: SheetAnchor.pixels(20),
downward: SheetAnchor.proportional(0.3),
),
),
),
),
ListTile(
title: const Text('DirectionAwareBouncingBehavior'),
subtitle: const Text('with DraggableSheet'),
onTap: () => showModalSheet(
const _DraggableSheet(
behavior: DirectionAwareBouncingBehavior(
// Allows the sheet to bounce only when dragging it downwards.
upward: SheetAnchor.pixels(0),
downward: SheetAnchor.proportional(0.1),
),
),
),
),
],
),
),
);
}
}
class _ScrollableSheet extends StatelessWidget {
const _ScrollableSheet({required this.behavior});
final BouncingBehavior behavior;
@override
Widget build(BuildContext context) {
return ScrollableSheet(
physics: BouncingSheetPhysics(behavior: behavior),
child: Material(
color: Colors.white,
child: SizedBox(
height: 500,
child: ListView(
children: List.generate(
30,
(index) => ListTile(title: Text('Item $index')),
),
),
),
),
);
}
}
class _DraggableSheet extends StatelessWidget {
const _DraggableSheet({required this.behavior});
final BouncingBehavior behavior;
@override
Widget build(BuildContext context) {
return DraggableSheet(
physics: BouncingSheetPhysics(behavior: behavior),
child: Container(
height: 500,
width: double.infinity,
color: Colors.white,
),
);
}
}