Search code examples
android-studioflutterdartflutter-pageview

Is it possible to give index to a date and then use jumpToPage to that date?


So this is what I want basicly: enter image description here

I want every day to be and index so 2020 jan. is 31 days + feb. 21 = 52. When I click on feb 21 I want to jump to page with index 52. Right now Its jump to 52 because of this code:

controller.jumpToPage(52);

Solution

  • You can use DateTime.difference() :

    final firstDate = DateTime(2020, 1, 1);
    final secondDate = DateTime(2020, 2, 21);
    final index = secondDate.difference(firstDate).inDays;
    controller.jumpToPage(index) // index : 51