init method

void init(
  1. MonthOption<T> option, {
  2. PageController? pageController,
})

初始化

Implementation

void init(MonthOption<T> option, {PageController? pageController}) {
  _option = option;
  _controllerList = [];
  _position = CACHE_SIZE ~/ 2;
  _pageController = pageController;
  DateDay _day = option.currentDay ?? DateDay.now();
  List.generate(CACHE_SIZE, (index) {
    addMonth(DateMonth(_day.year, _day.month - CACHE_SIZE ~/ 2 + index));
  });

  if (_pageController != null) {
    _pageController!.addListener(() {
      double position = _pageController!.position.pixels;
      if (position == 0) {
        addFirstMonth();
        _position = 1;
        _pageController!.jumpToPage(_position);
      } else if (position == _pageController!.position.maxScrollExtent) {
        addMonth();
        if (monthList.length == CACHE_SIZE) {
          _position = CACHE_SIZE - 2;
          _pageController!.jumpToPage(_position);
        }
      }
    });
  }
}