Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change visible range dynamically #60

Open
eduardothiesen opened this issue Dec 1, 2020 · 6 comments
Open

Change visible range dynamically #60

eduardothiesen opened this issue Dec 1, 2020 · 6 comments
Labels
T: Feature Type: :tada: New Features

Comments

@eduardothiesen
Copy link

eduardothiesen commented Dec 1, 2020

I apologize if the feature is already available, but I couldn't find a way to make it work.

I want to give the user the option between 4 visible ranges. 1, 3, 5 and week.

            IconButton(
              icon: Icon(
                Icons.more_vert,
              ),
              onPressed: () {
                showModalBottomSheet(
                  context: context,
                  builder: (context) {
                    return CustomPicker(
                      title: 'Visualização',
                      items: [
                        'Dia',
                        '3 dias',
                        '5 dias',
                        'Semana',
                      ],
                      onSelect: (index) {
                        Navigator.pop(context);
                        setState(() {
                          switch (index) {
                            case 0:
                              visibleRange = VisibleRange.days(1);
                              break;
                            case 1:
                              visibleRange = VisibleRange.days(3);
                              break;
                            case 2:
                              visibleRange = VisibleRange.days(5);
                              break;
                            case 3:
                              visibleRange = VisibleRange.week();
                              break;
                          }
                        });
                      },
                    );
                  },
                  isScrollControlled: false,
                  backgroundColor: Colors.transparent,
                );
              },
            ),

But, the grid does not update after that and keeps the first used VisibleRange (example: if when I created the controller I used VisibleRange.days(5) it always maintain a grid with 5 columns)

My controller code is as follows:

   _controller = TimetableController(
      eventProvider: EventProvider.stream(
        eventGetter: (range) => Stream.periodic(
          Duration(milliseconds: 16),
          (i) {
            final start =
                LocalDate.today().atMidnight() + Period(minutes: i * 2);
            return [
              BasicEvent(
                id: 0,
                title: 'Event',
                color: Colors.blue,
                start: start,
                end: start + Period(hours: 5),
              ),
            ];
          },
        ),
      ),
      initialTimeRange: InitialTimeRange.range(
        startTime: LocalTime(8, 0, 0),
        endTime: LocalTime(20, 0, 0),
      ),
      initialDate: initialDate,
      visibleRange: visibleRange,
      firstDayOfWeek: DayOfWeek.monday,
    );

Below are some screenshots.

Thanks in advance.
Screenshot_1606842184
Screenshot_1606842182
Screenshot_1606842179
Screenshot_1606842176
Screenshot_1606842173

@eduardothiesen eduardothiesen added the T: Feature Type: :tada: New Features label Dec 1, 2020
@vendelin8
Copy link

Hey,

Awesome lib!
I was about to check if there's a possibility to change number of days based on mobile orientation, but found the same thing, that I can't change it. This would be very useful for me too. Thanks!

@TatsuUkraine
Copy link
Contributor

I was able to solve this with just rebuilding timetable widget with a different controller instance

@javieralcantara
Copy link

Having two different controller instances doesn't solve it to me, could you please explain how you solved it? @TatsuUkraine thanks!

@TatsuUkraine
Copy link
Contributor

TatsuUkraine commented Feb 16, 2021

Having two different controller instances doesn't solve it to me, could you please explain how you solved it? @TatsuUkraine thanks!

so I have an enum that represents all my range variants, Statefull widget that creates controller in initState and renders timetable itself. In the constructor it receives enum value. Then in didUpdateWidget this stateful widget checks if the enum is changed, and if so - disposes prev controller and creates a new one with a different visible range

@TatsuUkraine
Copy link
Contributor

@javieralcantara sorry, don't pay attention to my prev comment)) I looked at different package)))

in timetable - I'm changing value key for this Statefull widget each time range is changing. This leads to destroy widget with prev range and creating a new range from the scratch

@TatsuUkraine
Copy link
Contributor

TatsuUkraine commented Feb 16, 2021

but I'm going to change this behavior to a variant with didUpdateWidget (at least I will try))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: Feature Type: :tada: New Features
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants