0

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);
Community
  • 1
  • 1
Matelevi12
  • 27
  • 6

1 Answers1

2

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
Augustin R
  • 7,089
  • 3
  • 26
  • 54
  • Thank you, It was pretty helpful so far, but I don’t get it how to use the controller.jumpToPage. If I chose like jan 15 how do I jump to number 15. page? – Matelevi12 Feb 20 '20 at 14:30
  • @Matelevi12 I don't know what you are referring by `controller.jumpToPage`. – Augustin R Feb 20 '20 at 14:44
  • I am using this: https://pub.dev/packages/datetime_picker_formfield Should i use something else? – Matelevi12 Feb 20 '20 at 14:50
  • What is the `controller` related to ? A `TabView`? – Augustin R Feb 20 '20 at 14:56
  • final controller = new PageController(initialPage: 999); Then i use: body: PageView.builder( controller: controller, Then i try to use this: controller.jumpToPage(index); – Matelevi12 Feb 20 '20 at 14:57
  • I did it! final index = date.difference(firstDate).inDays; setState(() { controller.jumpToPage(index); Thank you! – Matelevi12 Feb 20 '20 at 15:41