rebuild method
Rebuilds the modal layout, useful when modifying properties like scrollContent, title, footer, etc.
Implementation
Future<void> rebuild() async {
removeAll(children);
_backgroundComponent =
_background ??
RectangleComponent(size: size, paint: Paint()..color = Colors.black87);
_backgroundComponent.size = size;
_backgroundComponent.position = Vector2.zero();
add(_backgroundComponent);
double scrollTop = padding.top;
double scrollBottom = padding.bottom;
titleComponent = null;
if (title != null) {
titleComponent = TextComponent(
text: title!,
anchor: Anchor.topLeft,
position: Vector2(padding.left, scrollTop),
textRenderer: TextPaint(
style:
titleStyle ??
const TextStyle(
fontSize: 14,
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
);
add(titleComponent!);
await titleComponent!.onLoad();
scrollTop += titleComponent!.height + titleSpacing;
}
if (closeButton != null) {
await closeButton!.onLoad();
closeButton!
..position = Vector2(
size.x - padding.right - closeButton!.size.x,
padding.top,
)
..anchor = Anchor.topLeft;
add(closeButton!);
}
if (footer != null) {
await footer!.onLoad();
final footerHeight =
footer!.size.y > 0 ? footer!.size.y : defaultFooterHeight;
scrollBottom += footerHeight + titleSpacing;
footer!.position = Vector2(
padding.left,
size.y - scrollBottom + titleSpacing,
);
add(footer!);
}
final scrollAreaSize = Vector2(
size.x - padding.horizontal,
size.y - scrollTop - scrollBottom,
);
scrollArea = ScrollableAreaComponent(
content: scrollContent,
size: scrollAreaSize,
position: Vector2(padding.left, scrollTop),
contentHeight: contentHeight,
autoContentHeight: autoContentHeight,
);
add(scrollArea);
onAfterLoad?.call();
}