builder method
Implementation
List<Widget> builder(BuildContext context, BoxConstraints constraints) {
// 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
var direction = widget.model.directionOf();
List<Widget> children = [];
// View
Widget view;
switch (widget.model.collapsed) {
// collapsed list
case true:
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)));
break;
// regular list
case false:
int? items = widget.model.datasource == null ? widget.model.items.length : widget.model.data?.length;
view = ListView.builder(
reverse: widget.model.reverse,
itemCount: items,
physics: widget.model.onpulldown != null
? const AlwaysScrollableScrollPhysics()
: null,
scrollDirection: direction,
controller: controller,
itemBuilder: itemBuilder);
break;
}
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));
// show busy spinner over list
view = Stack(children: children);
return [view];
}