1
1
part of 'scaffold.dart' ;
2
2
3
+ enum _ScaffoldElement {
4
+ header,
5
+ body;
6
+ }
7
+
3
8
/// A widget that provides a basic structure for a page or screen.
4
9
///
5
10
/// It consists of a single [body] widget that is wrapped in a
@@ -26,11 +31,14 @@ part of 'scaffold.dart';
26
31
class Scaffold extends StatelessWidget {
27
32
const Scaffold ({
28
33
super .key,
34
+ this .header,
29
35
required this .body,
30
36
this .style,
31
37
this .variants = const [],
32
38
});
33
39
40
+ final Widget ? header;
41
+
34
42
/// The primary content of the scaffold.
35
43
final Widget body;
36
44
@@ -50,8 +58,60 @@ class Scaffold extends StatelessWidget {
50
58
builder: (context) {
51
59
final spec = ScaffoldSpec .of (context);
52
60
53
- return spec.container (child: ToastLayer (child: body));
61
+ return spec.container (
62
+ child: ToastLayer (
63
+ child: CustomMultiChildLayout (
64
+ delegate: _ScaffoldLayoutDelegate (),
65
+ children: [
66
+ if (header != null )
67
+ LayoutId (
68
+ id: _ScaffoldElement .header,
69
+ child: header! ,
70
+ ),
71
+ LayoutId (
72
+ id: _ScaffoldElement .body,
73
+ child: body,
74
+ ),
75
+ ],
76
+ ),
77
+ ),
78
+ );
54
79
},
55
80
);
56
81
}
57
82
}
83
+
84
+ class _ScaffoldLayoutDelegate extends MultiChildLayoutDelegate {
85
+ @override
86
+ void performLayout (Size size) {
87
+ final BoxConstraints looseConstraints = BoxConstraints .loose (size);
88
+ final BoxConstraints fullWidthConstraints =
89
+ looseConstraints.tighten (width: size.width);
90
+
91
+ double appBarHeight = 0.0 ;
92
+
93
+ const headerKey = _ScaffoldElement .header;
94
+ if (hasChild (headerKey)) {
95
+ appBarHeight = layoutChild (headerKey, fullWidthConstraints).height;
96
+ positionChild (headerKey, Offset .zero);
97
+ }
98
+
99
+ const bodyKey = _ScaffoldElement .body;
100
+ if (hasChild (bodyKey)) {
101
+ final listHeight = size.height - appBarHeight;
102
+
103
+ final bodyConstraints = BoxConstraints .tightFor (
104
+ width: fullWidthConstraints.maxWidth,
105
+ height: listHeight,
106
+ );
107
+
108
+ layoutChild (bodyKey, bodyConstraints);
109
+ positionChild (bodyKey, Offset (0 , appBarHeight));
110
+ }
111
+ }
112
+
113
+ @override
114
+ bool shouldRelayout (covariant MultiChildLayoutDelegate oldDelegate) {
115
+ return false ;
116
+ }
117
+ }
0 commit comments