-
Notifications
You must be signed in to change notification settings - Fork 22
/
sheet_draggable.dart
92 lines (83 loc) · 2.45 KB
/
sheet_draggable.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
import 'package:flutter/material.dart';
import 'package:smooth_sheets/smooth_sheets.dart';
void main() {
runApp(const _SheetDraggableExample());
}
class _SheetDraggableExample extends StatelessWidget {
const _SheetDraggableExample();
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: Scaffold(
body: Stack(
children: [
Placeholder(),
SheetViewport(
child: _ExampleSheet(),
),
],
),
),
);
}
}
class _ExampleSheet extends StatelessWidget {
const _ExampleSheet();
@override
Widget build(BuildContext context) {
final handle = Container(
alignment: Alignment.center,
padding: const EdgeInsets.symmetric(vertical: 12),
child: Container(
height: 8,
width: 56,
decoration: const ShapeDecoration(
color: Colors.black12,
shape: StadiumBorder(),
),
),
);
final content = ListView.builder(
itemCount: 50,
itemBuilder: (context, index) {
return ListTile(
title: Text('Item $index'),
);
},
);
final body = Column(
children: [
// SheetDraggable enables the child widget to act as a drag handle for the sheet.
// Typically, you will want to use this widget when placing non-scrollable widget(s)
// in a ScrollableSheet, since it only works with scrollable widgets, so you can't
// drag the sheet by touching a non-scrollable area. Try removing SheetDraggable and
// you will see that the drag handle doesn't work as it should.
//
// Note that SheetDraggable is not needed when using DraggableSheet
// since it implicitly wraps the child widget with SheetDraggable.
SheetDraggable(child: handle),
Expanded(child: content),
],
);
const minPosition = SheetAnchor.proportional(0.5);
const physics = BouncingSheetPhysics(
parent: SnappingSheetPhysics(),
);
return SafeArea(
bottom: false,
child: ScrollableSheet(
physics: physics,
minPosition: minPosition,
initialPosition: minPosition,
child: Card(
margin: EdgeInsets.zero,
color: Theme.of(context).colorScheme.secondaryContainer,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
child: body,
),
),
);
}
}