buildScrollables method

dynamic buildScrollables(
  1. BuildContext context,
  2. PlatformLayoutInfo layoutInfo,
  3. bool shrinkWrap, [
  4. dynamic _body,
])

Returns either a single widget (may be a CustomScrollView) or a List of widgets

Implementation

dynamic buildScrollables(
  BuildContext context,
  PlatformLayoutInfo layoutInfo,
  bool shrinkWrap, [
  dynamic _body,
]) {
  _body ??= _body ?? widget.body;

  if (_body is Stream<Widget>) {
    final sb = StreamBuilder<Widget>(
      stream: _body,
      builder: (context, snap) {
        return snap.data ?? sliverEmptyBox;
      },
    );
    _body = sb;
  } else if (_body is Stream<List<Widget>>) {
    return StreamBuilder<List<Widget>>(
      stream: _body,
      builder: (context, snap) {
        return buildScrollView(
          context,
          snap.data ?? <Widget>[],
          buildHeader(context, layoutInfo),
          layoutInfo,
          shrinkWrap: shrinkWrap,
        );
      },
    );
  } else if (_body is Function) {
    late DynamicContextFactory producer;
    if (_body is WidgetFactory || _body is WidgetListFactory) {
      producer = (_) => _body();
    } else if (_body is WidgetContextFactory ||
        _body is WidgetListContextFactory) {
      producer = (context) => _body(context);
    } else if (_body is WidgetScrollerContextFactory ||
        _body is WidgetListScrollerContextFactory) {
      producer = (context) => _body(context, widget.scroller);
    }

    _body = producer(context);
  }
  assert(_body is Widget || _body is List<Widget>,
      "Body must produce a widget or list of widgets but was ${_body?.runtimeType ?? 'null'}");

  return _body;
}