Skip to content

Commit

Permalink
Update scaffold_widget.dart
Browse files Browse the repository at this point in the history
  • Loading branch information
tilucasoli committed Feb 7, 2025
1 parent 4ed6405 commit d1fea5a
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions packages/remix/lib/src/components/scaffold/scaffold_widget.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
part of 'scaffold.dart';

enum _ScaffoldElement {
sidebar,
header,
body;
}
Expand Down Expand Up @@ -32,12 +33,14 @@ class Scaffold extends StatelessWidget {
const Scaffold({
super.key,
this.header,
this.sidebar,
required this.body,
this.style,
this.variants = const [],
});

final Widget? header;
final Widget? sidebar;

/// The primary content of the scaffold.
final Widget body;
Expand All @@ -63,6 +66,11 @@ class Scaffold extends StatelessWidget {
child: CustomMultiChildLayout(
delegate: _ScaffoldLayoutDelegate(),
children: [
if (sidebar != null)
LayoutId(
id: _ScaffoldElement.sidebar,
child: sidebar!,
),
if (header != null)
LayoutId(
id: _ScaffoldElement.header,
Expand All @@ -86,24 +94,31 @@ class _ScaffoldLayoutDelegate extends MultiChildLayoutDelegate {
void performLayout(Size size) {
final BoxConstraints looseConstraints = BoxConstraints.loose(size);
double appBarHeight = 0.0;
double sideBarWidth = 0.0;

const sidebarKey = _ScaffoldElement.sidebar;
if (hasChild(sidebarKey)) {
sideBarWidth = layoutChild(sidebarKey, looseConstraints).width;
positionChild(sidebarKey, Offset.zero);
}

const headerKey = _ScaffoldElement.header;
if (hasChild(headerKey)) {
appBarHeight = layoutChild(headerKey, looseConstraints).height;
positionChild(headerKey, Offset.zero);
positionChild(headerKey, Offset(sideBarWidth, 0));
}

const bodyKey = _ScaffoldElement.body;
if (hasChild(bodyKey)) {
final listHeight = size.height - appBarHeight;

final bodyConstraints = BoxConstraints.tightFor(
width: looseConstraints.maxWidth,
width: looseConstraints.maxWidth - sideBarWidth,
height: listHeight,
);

layoutChild(bodyKey, bodyConstraints);
positionChild(bodyKey, Offset(0, appBarHeight));
positionChild(bodyKey, Offset(sideBarWidth, appBarHeight));
}
}

Expand Down

0 comments on commit d1fea5a

Please sign in to comment.