scrollToMonth method
Scroll to date.month
.
Animate the list over duration
using the given curve
such that the
item at index
ends up with its leading edge at the given alignment
.
See jumpTo
for an explanation of alignment.
The duration
must be greater than 0; otherwise, use jumpTo
.
When item position is not available, because it's too far, the scroll is composed into three phases:
- The currently displayed list view starts scrolling.
- Another list view, which scrolls with the same speed, fades over the first one and shows items that are close to the scroll target.
- The second list view scrolls and stops on the target.
The opacityAnimationWeights
can be used to apply custom weights to these
three stages of this animation. The default weights, [40, 20, 40]
, are
good with default Curves.linear. Different weights might be better for
other cases. For example, if you use Curves.easeOut, consider setting
opacityAnimationWeights
to [20, 20, 60]
.
Implementation
Future<void> scrollToMonth({
required DateTime date,
double alignment = 0,
required Duration duration,
Curve curve = Curves.linear,
List<double> opacityAnimationWeights = const [40, 20, 40],
}) async {
if (!(date.year >= minDate.year &&
(date.year > minDate.year || date.month >= minDate.month) &&
date.year <= maxDate.year &&
(date.year < maxDate.year || date.month <= maxDate.month))) {
return;
}
final month =
((date.year - minDate.year) * 12) - minDate.month + date.month;
await itemScrollController.scrollTo(
index: month,
alignment: alignment,
duration: duration,
curve: curve,
opacityAnimationWeights: opacityAnimationWeights);
}