-
Notifications
You must be signed in to change notification settings - Fork 22
/
scrollable_sheet.dart
75 lines (67 loc) · 2.11 KB
/
scrollable_sheet.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
import 'package:flutter/material.dart';
import 'package:smooth_sheets/smooth_sheets.dart';
void main() {
runApp(const _BasicScrollableSheetExample());
}
class _BasicScrollableSheetExample extends StatelessWidget {
const _BasicScrollableSheetExample();
@override
Widget build(BuildContext context) {
return const MaterialApp(
// Typically, you would use a Stack to place the sheet
// on top of another widget.
home: Stack(
children: [
Scaffold(),
_MySheet(),
],
),
);
}
}
class _MySheet extends StatelessWidget {
const _MySheet();
@override
Widget build(BuildContext context) {
// Create a content whatever you want.
// ScrollableSheet works with any scrollable widget such as
// ListView, GridView, CustomScrollView, etc.
final content = ListView.builder(
itemCount: 50,
itemBuilder: (context, index) {
return ListTile(
title: Text('Item $index'),
);
},
);
// Just wrap the content in a ScrollableSheet!
final sheet = ScrollableSheet(
child: buildSheetBackground(context, content),
// Optional: Comment out the following lines to add multiple stop positions.
//
// minPosition: const SheetAnchor.proportional(0.2),
// physics: BouncingSheetPhysics(
// parent: SnappingSheetPhysics(
// snappingBehavior: SnapToNearest(
// snapTo: [
// const SheetAnchor.proportional(0.2),
// const SheetAnchor.proportional(0.5),
// const SheetAnchor.proportional(1),
// ],
// ),
// ),
// ),
);
return SafeArea(bottom: false, child: sheet);
}
Widget buildSheetBackground(BuildContext context, Widget content) {
// Add background color, circular corners and material shadow to the sheet.
// This is just an example, you can customize it however you want.
return Material(
color: Theme.of(context).colorScheme.secondaryContainer,
borderRadius: BorderRadius.circular(16),
clipBehavior: Clip.antiAlias,
child: content,
);
}
}