Skip to content

Commit

Permalink
📌 Fix formatting issue.
Browse files Browse the repository at this point in the history
- Fix late initialization error in EventController.

- Add flutter_calendar_page.iml in .gitignore.

- Updated workflow to check formatting options.

- Add CONTRIBUTING.md file.
  • Loading branch information
ParthBaraiya authored and AnkitPanchal10 committed Aug 12, 2022
1 parent e2b357a commit f9b1ee2
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 53 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/flutter_analyze.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,8 @@ jobs:
- name: Install dependencies
run: flutter pub get

- name: Formatting check
run: flutter format . --dry-run --set-exit-if-changed

- name: Analyse
run: flutter analyze
9 changes: 9 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Way to contribute

1. Fork the repo and create your branch from `master` or `devlop`.
2. Clone the project to your own machine.
3. Commit changes to your own branch
4. Make sure your code lints.
5. Push your work back up to your fork.
6. Create a pull request on `devlop` branch.
7. And Done!
14 changes: 0 additions & 14 deletions flutter_calendar_page.iml

This file was deleted.

24 changes: 11 additions & 13 deletions lib/src/day_view/day_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,10 @@ class DayViewState<T extends Object?> extends State<DayView<T>> {

late DateWidgetBuilder _dayTitleBuilder;

late EventController<T> _controller;
EventController<T>? _controller;

late ScrollController _scrollController;

bool _controllerAdded = false;

late VoidCallback _reloadCallback;

final _scrollConfiguration = EventScrollConfiguration<T>();
Expand Down Expand Up @@ -249,10 +247,10 @@ class DayViewState<T extends Object?> extends State<DayView<T>> {
final newController = widget.controller ??
CalendarControllerProvider.of<T>(context).controller;

if (_controller != newController) {
if (newController != _controller) {
_controller = newController;

_controller
_controller!
// Removes existing callback.
..removeListener(_reloadCallback)

Expand All @@ -261,8 +259,6 @@ class DayViewState<T extends Object?> extends State<DayView<T>> {
..addListener(_reloadCallback);
}

_controllerAdded = true;

_updateViewDimensions();
}

Expand All @@ -274,9 +270,9 @@ class DayViewState<T extends Object?> extends State<DayView<T>> {
CalendarControllerProvider.of<T>(context).controller;

if (newController != _controller) {
_controller.removeListener(_reloadCallback);
_controller?.removeListener(_reloadCallback);
_controller = newController;
_controller.addListener(_reloadCallback);
_controller?.addListener(_reloadCallback);
}

// Update date range.
Expand All @@ -301,7 +297,7 @@ class DayViewState<T extends Object?> extends State<DayView<T>> {

@override
void dispose() {
_controller.removeListener(_reloadCallback);
_controller?.removeListener(_reloadCallback);
_pageController.dispose();
super.dispose();
}
Expand Down Expand Up @@ -356,7 +352,7 @@ class DayViewState<T extends Object?> extends State<DayView<T>> {
verticalLineOffset: widget.verticalLineOffset,
showVerticalLine: widget.showVerticalLine,
height: _height,
controller: _controller,
controller: controller,
hourHeight: _hourHeight,
eventArranger: _eventArranger,
minuteSlotSize: widget.minuteSlotSize,
Expand All @@ -379,9 +375,11 @@ class DayViewState<T extends Object?> extends State<DayView<T>> {
/// This will throw [AssertionError] if controller is called before its
/// initialization is complete.
EventController<T> get controller {
assert(_controllerAdded, "EventController is not initialized yet.");
if (_controller == null) {
throw "EventController is not initialized yet.";
}

return _controller;
return _controller!;
}

/// Reloads page.
Expand Down
24 changes: 11 additions & 13 deletions lib/src/month_view/month_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,7 @@ class MonthViewState<T extends Object?> extends State<MonthView<T>> {

late DateWidgetBuilder _headerBuilder;

late EventController<T> _controller;

bool _controllerAdded = false;
EventController<T>? _controller;

late VoidCallback _reloadCallback;

Expand Down Expand Up @@ -199,10 +197,10 @@ class MonthViewState<T extends Object?> extends State<MonthView<T>> {
final newController = widget.controller ??
CalendarControllerProvider.of<T>(context).controller;

if (_controller != newController) {
if (newController != _controller) {
_controller = newController;

_controller
_controller!
// Removes existing callback.
..removeListener(_reloadCallback)

Expand All @@ -211,8 +209,6 @@ class MonthViewState<T extends Object?> extends State<MonthView<T>> {
..addListener(_reloadCallback);
}

_controllerAdded = true;

updateViewDimensions();
}

Expand All @@ -224,9 +220,9 @@ class MonthViewState<T extends Object?> extends State<MonthView<T>> {
CalendarControllerProvider.of<T>(context).controller;

if (newController != _controller) {
_controller.removeListener(_reloadCallback);
_controller?.removeListener(_reloadCallback);
_controller = newController;
_controller.addListener(_reloadCallback);
_controller?.addListener(_reloadCallback);
}

// Update date range.
Expand All @@ -246,7 +242,7 @@ class MonthViewState<T extends Object?> extends State<MonthView<T>> {

@override
void dispose() {
_controller.removeListener(_reloadCallback);
_controller?.removeListener(_reloadCallback);
_pageController.dispose();
super.dispose();
}
Expand Down Expand Up @@ -301,7 +297,7 @@ class MonthViewState<T extends Object?> extends State<MonthView<T>> {
onDateLongPress: widget.onDateLongPress,
width: _width,
height: _height,
controller: _controller,
controller: controller,
borderColor: widget.borderColor,
borderSize: widget.borderSize,
cellBuilder: _cellBuilder,
Expand Down Expand Up @@ -330,9 +326,11 @@ class MonthViewState<T extends Object?> extends State<MonthView<T>> {
/// This will throw [AssertionError] if controller is called before its
/// initialization is complete.
EventController<T> get controller {
assert(_controllerAdded, "EventController is not initialized yet.");
if (_controller == null) {
throw "EventController is not initialized yet.";
}

return _controller;
return _controller!;
}

void _reload() {
Expand Down
24 changes: 11 additions & 13 deletions lib/src/week_view/week_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,9 @@ class WeekViewState<T extends Object?> extends State<WeekView<T>> {
late double _weekTitleWidth;
late int _totalDaysInWeek;

bool _controllerAdded = false;

late VoidCallback _reloadCallback;

late EventController<T> _controller;
EventController<T>? _controller;

late ScrollController _scrollController;
late List<WeekDays> _weekDays;
Expand Down Expand Up @@ -254,7 +252,7 @@ class WeekViewState<T extends Object?> extends State<WeekView<T>> {
if (_controller != newController) {
_controller = newController;

_controller
_controller!
// Removes existing callback.
..removeListener(_reloadCallback)

Expand All @@ -263,8 +261,6 @@ class WeekViewState<T extends Object?> extends State<WeekView<T>> {
..addListener(_reloadCallback);
}

_controllerAdded = true;

_updateViewDimensions();
}

Expand All @@ -276,9 +272,9 @@ class WeekViewState<T extends Object?> extends State<WeekView<T>> {
CalendarControllerProvider.of<T>(context).controller;

if (newController != _controller) {
_controller.removeListener(_reloadCallback);
_controller?.removeListener(_reloadCallback);
_controller = newController;
_controller.addListener(_reloadCallback);
_controller?.addListener(_reloadCallback);
}

_setWeekDays();
Expand All @@ -305,7 +301,7 @@ class WeekViewState<T extends Object?> extends State<WeekView<T>> {

@override
void dispose() {
_controller.removeListener(_reloadCallback);
_controller?.removeListener(_reloadCallback);
_pageController.dispose();
super.dispose();
}
Expand Down Expand Up @@ -363,12 +359,12 @@ class WeekViewState<T extends Object?> extends State<WeekView<T>> {
timeLineWidth: _timeLineWidth,
verticalLineOffset: 0,
showVerticalLine: true,
controller: _controller,
controller: controller,
hourHeight: _hourHeight,
scrollController: _scrollController,
eventArranger: _eventArranger,
weekDays: _weekDays,
minuteSlotSize: widget.minuteSlotSize,
minuteSlotSize: widget.minuteSlotSize,
scrollConfiguration: _scrollConfiguration,
));
},
Expand All @@ -387,9 +383,11 @@ class WeekViewState<T extends Object?> extends State<WeekView<T>> {
/// This will throw [AssertionError] if controller is called before its
/// initialization is complete.
EventController<T> get controller {
assert(_controllerAdded, "EventController is not initialized yet.");
if (_controller == null) {
throw "EventController is not initialized yet.";
}

return _controller;
return _controller!;
}

/// Reloads page.
Expand Down

0 comments on commit f9b1ee2

Please sign in to comment.