build method
Describes the part of the user interface represented by this component.
The framework calls this method when this component is inserted into the tree in a given BuildContext and when the dependencies of this component change (e.g., an InheritedComponent referenced by this component changes). This method can potentially be called in every frame and should not have any side effects beyond building a component.
The framework replaces the subtree below this component with the component returned by this method, either by updating the existing subtree or by removing the subtree and inflating a new subtree, depending on whether the component returned by this method can update the root of the existing subtree, as determined by calling Component.canUpdate.
Typically implementations return a newly created constellation of components that are configured with information from this component's constructor and from the given BuildContext.
The given BuildContext contains information about the location in the tree at which this component is being built. For example, the context provides the set of inherited components for this location in the tree. A given component might be built with multiple different BuildContext arguments over time if the component is moved around the tree or if the component is inserted into the tree in multiple places at once.
The implementation of this method must only depend on:
- the fields of the component, which themselves must not change over time, and
- any ambient state obtained from the
contextusing BuildContext.dependOnInheritedComponentOfExactType.
If a component's build method is to depend on anything else, use a StatefulComponent instead.
See also:
- StatelessComponent, which contains the discussion on performance considerations.
Implementation
@override
Component build(BuildContext context) {
return dom.div(
classes: 'codex-dialog-overlay',
styles: const dom.Styles(raw: {
'position': 'fixed',
'inset': '0',
'z-index': '50',
'display': 'flex',
'align-items': 'center',
'justify-content': 'center',
'padding': '1.5rem',
// Codex: darker backdrop for OLED
'background-color': 'rgba(0, 0, 0, 0.85)',
'backdrop-filter': 'blur(4px)',
'-webkit-backdrop-filter': 'blur(4px)',
}),
events: props.barrierDismissible && props.onClose != null
? {'click': (_) => props.onClose!()}
: null,
[
// Dialog content
dom.div(
classes: 'codex-dialog',
styles: dom.Styles(raw: {
'position': 'relative',
'max-width': '${props.maxWidth}px',
'width': '100%',
// Codex: glass effect
'background-color': 'rgba(10, 10, 10, 0.95)',
'backdrop-filter': 'blur(12px)',
'-webkit-backdrop-filter': 'blur(12px)',
'border': '1px solid var(--primary)',
'border-radius': 'var(--radius-2xl)', // Codex: larger radius
// Codex: subtle accent glow
'box-shadow': '0 14px 40px rgba(var(--primary-rgb), 0.15), 0 25px 50px -12px rgba(0, 0, 0, 0.25)',
// Codex: more padding
'padding': '2rem',
}),
events: {'click': (e) => e.stopPropagation()},
[
// Close button
if (props.showCloseButton)
dom.button(
classes: 'codex-dialog-close',
styles: const dom.Styles(raw: {
'position': 'absolute',
'top': '1rem',
'right': '1rem',
'width': '32px',
'height': '32px',
'display': 'flex',
'align-items': 'center',
'justify-content': 'center',
'background': 'transparent',
'border': 'none',
'border-radius': 'var(--radius-md)',
'color': 'var(--muted-foreground)',
'cursor': 'pointer',
'transition': 'all var(--transition)',
}),
events: props.onClose == null
? null
: {'click': (_) => props.onClose!()},
[const Component.text('\u2715')], // X mark
),
// Title
if (props.title != null)
dom.h2(
classes: 'codex-dialog-title',
styles: const dom.Styles(raw: {
'font-size': 'var(--font-size-xl)',
'font-weight': 'var(--font-weight-semibold)',
'color': 'var(--foreground)',
'margin': '0 0 1rem 0',
'padding-right': '2rem', // Space for close button
}),
[Component.text(props.title!)],
),
// Content
dom.div(
classes: 'codex-dialog-content',
styles: const dom.Styles(raw: {
'color': 'var(--foreground)',
}),
props.content,
),
// Actions
if (props.actions != null && props.actions!.isNotEmpty)
dom.div(
classes: 'codex-dialog-actions',
styles: const dom.Styles(raw: {
'display': 'flex',
'justify-content': 'flex-end',
'gap': '0.75rem', // Codex: more gap
'margin-top': '1.5rem', // Codex: more spacing
}),
props.actions!,
),
],
),
],
);
}