build method

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

Implementation

@override
Widget build(BuildContext context) {
  // Check if widget is visible before wasting resources on building it
  if (!widget.model.visible) return const Offstage();

  /// Busy / Loading Indicator
  busy ??= BusyModel(widget.model,
          visible: widget.model.busy, observable: widget.model.busyObservable)
      .getView();

  // Direction
  dynamic direction = Axis.vertical;
  if (widget.model.direction == 'horizontal') direction = Axis.horizontal;

  List<Widget> children = [];

  // View
  Widget view;

  if (widget.model.collapsed) {
    view = SingleChildScrollView(
        physics: widget.model.onpulldown != null
            ? const AlwaysScrollableScrollPhysics()
            : null,
        child: ExpansionPanelList.radio(
            dividerColor: Theme.of(context).colorScheme.onInverseSurface,
            initialOpenPanelValue: 0,
            elevation: 2,
            expandedHeaderPadding: const EdgeInsets.all(4),
            children: expansionItems(context)));
  } else {
    view = ListView.builder(
        reverse: widget.model.reverse,
        physics: widget.model.onpulldown != null
            ? const AlwaysScrollableScrollPhysics()
            : null,
        scrollDirection: direction,
        controller: controller,
        itemBuilder: itemBuilder);
  }

  if (widget.model.onpulldown != null) {
    view = RefreshIndicator(
        onRefresh: () => widget.model.onPull(context), child: view);
  }

  if (widget.model.onpulldown != null || widget.model.allowDrag) {
    view = ScrollConfiguration(
      behavior: ScrollConfiguration.of(context).copyWith(
        dragDevices: {
          PointerDeviceKind.touch,
          PointerDeviceKind.mouse,
        },
      ),
      child: view,
    );
  }

  // add list
  children.add(view);

  // add busy
  children.add(Center(child: busy));

  view = Stack(children: children);

  // add margins
  view = addMargins(view);

  // apply user defined constraints
  view = applyConstraints(view, widget.model.tightestOrDefault);

  // apply visual transforms
  view = applyTransforms(view);

  return view;
}