-
Notifications
You must be signed in to change notification settings - Fork 0
/
BottomSheetDummyUI.dart
205 lines (186 loc) · 5.77 KB
/
BottomSheetDummyUI.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return const MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
backgroundColor: Colors.black,
body: MyDraggableSheet(
child: Column(
children: [
BottomSheetDummyUI(),
BottomSheetDummyUI(),
BottomSheetDummyUI(),
BottomSheetDummyUI(),
BottomSheetDummyUI(),
BottomSheetDummyUI(),
BottomSheetDummyUI(),
],
)),
),
);
}
}
class BottomSheetDummyUI extends StatelessWidget {
const BottomSheetDummyUI({super.key});
@override
Widget build(BuildContext context) {
return Container(
child: Container(
padding: EdgeInsets.only(left: 30, right: 30),
child: Column(
children: [
Row(
children: [
ClipRRect(
borderRadius: BorderRadius.circular(15.0),
child: Container(
color: Colors.black12,
height: 100,
width: 100,
),
),
SizedBox(width: 10),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ClipRRect(
borderRadius: BorderRadius.circular(15.0),
child: Container(
color: Colors.black12,
height: 20,
width: 240,
),
),
SizedBox(height: 5),
ClipRRect(
borderRadius: BorderRadius.circular(15.0),
child: Container(
color: Colors.black12,
height: 20,
width: 180,
),
),
SizedBox(height: 50),
],
)
],
),
SizedBox(height: 10),
],
)),
);
}
}
class MyDraggableSheet extends StatefulWidget {
final Widget child;
const MyDraggableSheet({super.key, required this.child});
@override
State<MyDraggableSheet> createState() => _MyDraggableSheetState();
}
class _MyDraggableSheetState extends State<MyDraggableSheet> {
final sheet = GlobalKey();
final controller = DraggableScrollableController();
@override
void initState() {
super.initState();
controller.addListener(onChanged);
}
void onChanged() {
final currentSize = controller.size;
if (currentSize <= 0.05) collapse();
}
void collapse() => animateSheet(getSheet.snapSizes!.first);
void anchor() => animateSheet(getSheet.snapSizes!.last);
void expand() => animateSheet(getSheet.maxChildSize);
void hide() => animateSheet(getSheet.minChildSize);
void animateSheet(double size) {
controller.animateTo(
size,
duration: const Duration(milliseconds: 50),
curve: Curves.easeInOut,
);
}
@override
void dispose() {
super.dispose();
controller.dispose();
}
DraggableScrollableSheet get getSheet =>
(sheet.currentWidget as DraggableScrollableSheet);
@override
Widget build(BuildContext context) {
return LayoutBuilder(builder: (context, constraints) {
return DraggableScrollableSheet(
key: sheet,
initialChildSize: 0.5,
maxChildSize: 0.95,
minChildSize: 0,
expand: true,
snap: true,
snapSizes: [
60 / constraints.maxHeight,
0.5,
],
controller: controller,
builder: (BuildContext context, ScrollController scrollController) {
return DecoratedBox(
decoration: const BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.yellow,
blurRadius: 10,
spreadRadius: 1,
offset: Offset(0, 1),
),
],
borderRadius: BorderRadius.only(
topLeft: Radius.circular(22),
topRight: Radius.circular(22),
),
),
child: CustomScrollView(
controller: scrollController,
slivers: [
topButtonIndicator(),
SliverToBoxAdapter(
child: widget.child,
),
],
),
);
},
);
});
}
SliverToBoxAdapter topButtonIndicator() {
return SliverToBoxAdapter(
child: Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Container(
child: Center(
child: Wrap(children: <Widget>[
Container(
width: 100,
margin: const EdgeInsets.only(top: 10, bottom: 10),
height: 5,
decoration: const BoxDecoration(
color: Colors.black45,
shape: BoxShape.rectangle,
borderRadius: BorderRadius.all(Radius.circular(8.0)),
)),
]))),
])),
);
}
}