build method

  1. @override
Widget build(
  1. BuildContext context
)
override

Builds and returns the Section widget.

This method conditionally renders either a GlassSection or BarSection based on the presence of customHeader. If customHeader is non-null, it uses GlassSection with the custom header and the child (converted to sliver if needed). Otherwise, it uses BarSection configured with the title, subtitle, leading, trailing, back button, and expandability settings.

The child is checked for sliver compatibility using isSliver; if not a sliver, it is wrapped via toSliver with fillRemaining: false to preserve original sizing in scroll views.

No side effects; purely declarative rendering based on provided properties. Returns a sliver-compatible widget for integration into scrollable parents like those in Collection.

Implementation

@override

/// Builds and returns the [Section] widget.
///
/// This method conditionally renders either a [GlassSection] or [BarSection] based on the presence of [customHeader]. If [customHeader] is non-null, it uses [GlassSection] with the custom header and the [child] (converted to sliver if needed). Otherwise, it uses [BarSection] configured with the title, subtitle, leading, trailing, back button, and expandability settings.
///
/// The [child] is checked for sliver compatibility using [isSliver]; if not a sliver, it is wrapped via [toSliver] with `fillRemaining: false` to preserve original sizing in scroll views.
///
/// No side effects; purely declarative rendering based on provided properties. Returns a sliver-compatible widget for integration into scrollable parents like those in [Collection].
Widget build(BuildContext context) => customHeader != null
    ? GlassSection(
        sliver: child.isSliver(context)
            ? child
            : child.toSliver(context, fillRemaining: false),
        header: customHeader!)
    : BarSection(
        expandable: expandable,
        initiallyExpanded: initiallyExpanded,
        titleText: titleText,
        subtitleText: subtitleText,
        headerText: headerText,
        title: title,
        subtitle: subtitle,
        header: header,
        leading: leading,
        trailing: trailing,
        backButton: backButton,
        sliver: child.isSliver(context)
            ? child
            : child.toSliver(context, fillRemaining: false));