-
Notifications
You must be signed in to change notification settings - Fork 22
/
sheet_controller.dart
105 lines (93 loc) · 2.64 KB
/
sheet_controller.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
import 'package:flutter/material.dart';
import 'package:smooth_sheets/smooth_sheets.dart';
void main() {
runApp(const _SheetControllerExample());
}
class _SheetControllerExample extends StatelessWidget {
const _SheetControllerExample();
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: _ExampleHome(),
);
}
}
class _ExampleHome extends StatefulWidget {
const _ExampleHome();
@override
State<_ExampleHome> createState() => _ExampleHomeState();
}
class _ExampleHomeState extends State<_ExampleHome> {
late final SheetController controller;
@override
void initState() {
super.initState();
controller = SheetController();
}
@override
void dispose() {
controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: [
SafeArea(
child: Align(
alignment: Alignment.topCenter,
// Like ScrollController for scrollable widgets,
// SheetController can be used to observe changes in the sheet position.
child: ValueListenableBuilder(
valueListenable: controller,
builder: (context, pixels, child) {
return Text(
'Position: ${pixels?.toStringAsFixed(1)}',
style: Theme.of(context).textTheme.displaySmall,
);
},
),
),
),
_ExampleSheet(
controller: controller,
),
],
),
floatingActionButton: FloatingActionButton(
backgroundColor: Theme.of(context).colorScheme.primary,
foregroundColor: Theme.of(context).colorScheme.onPrimary,
child: const Icon(Icons.arrow_downward_rounded),
onPressed: () {
// SheetController can also be used to animate the sheet position.
controller.animateTo(const SheetAnchor.proportional(0.5));
},
),
);
}
}
class _ExampleSheet extends StatelessWidget {
const _ExampleSheet({
required this.controller,
});
final SheetController controller;
@override
Widget build(BuildContext context) {
return DraggableSheet(
controller: controller,
minPosition: const SheetAnchor.proportional(0.5),
physics: const BouncingSheetPhysics(
parent: SnappingSheetPhysics(),
),
child: Card(
margin: EdgeInsets.zero,
color: Theme.of(context).colorScheme.secondaryContainer,
child: const SizedBox(
height: 500,
width: double.infinity,
),
),
);
}
}