-
Notifications
You must be signed in to change notification settings - Fork 22
/
sheet_content_scaffold.dart
112 lines (103 loc) · 3.18 KB
/
sheet_content_scaffold.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
import 'package:flutter/material.dart';
import 'package:smooth_sheets/smooth_sheets.dart';
void main() {
runApp(const _SheetContentScaffoldExample());
}
class _SheetContentScaffoldExample extends StatelessWidget {
const _SheetContentScaffoldExample();
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: Stack(
children: [
Scaffold(),
SheetViewport(
child: _ExampleSheet(),
),
],
),
);
}
}
class _ExampleSheet extends StatelessWidget {
const _ExampleSheet();
@override
Widget build(BuildContext context) {
// SheetContentScaffold is a special Scaffold designed for use in a sheet.
// It has slots for an app bar and a sticky bottom bar, similar to Scaffold.
// However, it differs in that its height reduces to fit the 'body' widget.
final content = SheetContentScaffold(
backgroundColor: Theme.of(context).colorScheme.secondaryContainer,
// With the following configuration, the sheet height will be
// 500px + (app bar height) + (bottom bar height).
body: Container(height: 500),
appBar: buildAppBar(context),
// BottomBarVisibility widgets can be used to control the visibility
// of the bottom bar based on the sheet's position.
// For example, the following configuration keeps the bottom bar visible
// as long as the keyboard is closed and at least 50% of the sheet is visible.
bottomBar: ConditionalStickyBottomBarVisibility(
// This callback is called whenever the sheet's metrics changes.
getIsVisible: (metrics) {
return metrics.viewportInsets.bottom == 0 &&
metrics.pixels >
const SheetAnchor.proportional(0.5)
.resolve(metrics.contentSize);
},
child: buildBottomBar(),
),
);
const physics = BouncingSheetPhysics(
parent: SnappingSheetPhysics(
behavior: SnapToNearest(
anchors: [
SheetAnchor.proportional(0.2),
SheetAnchor.proportional(0.5),
SheetAnchor.proportional(1),
],
),
),
);
return DraggableSheet(
physics: physics,
minPosition: const SheetAnchor.pixels(0),
child: Card(
clipBehavior: Clip.antiAlias,
margin: EdgeInsets.zero,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
),
child: content,
),
);
}
PreferredSizeWidget buildAppBar(BuildContext context) {
return AppBar(
title: const Text('Appbar'),
backgroundColor: Theme.of(context).colorScheme.secondaryContainer,
);
}
Widget buildBottomBar() {
return BottomAppBar(
child: Row(
children: [
Flexible(
fit: FlexFit.tight,
child: TextButton(
onPressed: () {},
child: const Text('Cancel'),
),
),
const SizedBox(width: 16),
Flexible(
fit: FlexFit.tight,
child: FilledButton(
onPressed: () {},
child: const Text('OK'),
),
)
],
),
);
}
}