Open moda20 opened 4 years ago
All constructors are extracting required parameters (scrollController
, scrollDirection
, reverse
) from child widgets. Unfortunately scrollable widgets don't share same interface for this purpose even if their methods are looking similar.
You could allow any Widget
and extract based on type:
factory FadingEdgeScrollView({
Key? key,
required Widget child,
double gradientFractionOnStart = 0.1,
double gradientFractionOnEnd = 0.1,
}) {
final (controller, scrollDirection, reverse) = _extractFromChild(child);
if (controller == null) {
throw Exception("Child must have controller set");
}
return FadingEdgeScrollView._internal(
key: key,
scrollController: controller,
scrollDirection: scrollDirection,
reverse: reverse,
gradientFractionOnStart: gradientFractionOnStart,
gradientFractionOnEnd: gradientFractionOnEnd,
child: child,
);
}
static (ScrollController? controller, Axis scrollDirection, bool reverse) _extractFromChild(Widget widget) {
switch (widget) {
case (ScrollView widget):
return (widget.controller, widget.scrollDirection, widget.reverse);
case (ReorderableListView widget):
return (widget.scrollController, widget.scrollDirection, widget.reverse);
case (SingleChildScrollView widget):
return (widget.controller, widget.scrollDirection, widget.reverse);
case (PageView widget):
return (widget.controller, widget.scrollDirection, widget.reverse);
case (AnimatedList widget):
return (widget.controller, widget.scrollDirection, widget.reverse);
case (ListWheelScrollView widget):
return (widget.controller, Axis.vertical, false);
default:
throw Exception(
"Child must be ScrollView, ReorderableListView, SingleChildScrollView, PageView, AnimatedList or ListWheelScrollView",
);
}
}
I found out that you are creating constructors for no reason when you don't do anything special for each constructor : here check these constructors they have the same implementation but with different constructor arguments :
why is that ?