Skyost / FlutterWeekView

Displays a highly customizable week view (or day view) which is able to display events, to be scrolled, to be zoomed-in & out and a lot more !
https://pub.dev/packages/flutter_week_view
MIT License
208 stars 89 forks source link

WeekView.builder crashes when dateCount is null #32

Closed luistrivelatto closed 4 years ago

luistrivelatto commented 4 years ago

Describe the bug When using the WeekView.builder constructor, a dateCreator is required, but not a dateCount (which is in accordance to idiomatic builder constructors in Flutter). Indeed, the constructor allows that, with the assertion assert(dateCount == null || dateCount >= 0). However this causes a crash when dateCount == null and a WeekViewController isn't passed, since a WeekViewController is then instanced using dateCount, but WeekViewController itself doesn't allow for a null dateCount: assert(dayViewsCount != null && dayViewsCount > 0).

To Reproduce Steps to reproduce the behavior:

  1. Take the example code on the package.
  2. Replace _DemoWeekView with
    class _DemoWeekView extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
    return WeekView.builder(
      dateCreator: (index) => DateTime(2020, 1, 1 + index),
      events: [],
    );
    }
    }
  3. Run the app and click on the Demo week view button. This should show the following error:
    'package:flutter_week_view/src/controller.dart': Failed assertion: line 160 pos 16: 'dayViewsCount != null && dayViewsCount > 0': is not true.

Expected behavior No errors should be thrown, and the controllers should be managed seamlessly until dateCreator returns null for a given index.

Smartphone (please complete the following information):

Skyost commented 4 years ago

Thanks for pointing this out. The problem is that internally, the WeekViewController is instantiating a DayViewController for each DayView (this allows to scale them at the same time, to scroll them, etc...), therefore, the WeekViewController is lost if we don't provide it a day view count ; and with a builder, it's not always possible to give an item count.

I think we should have to do an almost complete rewrite of WeekViewController in order to fix this one.

luistrivelatto commented 4 years ago

The fix looks great, congrats :)