Skip to content

Commit

Permalink
✨ Quick fixes before PR.
Browse files Browse the repository at this point in the history
  • Loading branch information
PRBaraiya committed Dec 13, 2023
1 parent 85e557e commit 252bbf8
Show file tree
Hide file tree
Showing 24 changed files with 146 additions and 97 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# [1.0.5] (UnReleased)(https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/tree/1.0.5)
# [1.0.5] (UnReleased)

- Fixed issue related to auto scroll to initial duration for day
view. [#269](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/269)
Expand All @@ -11,6 +11,13 @@
feature added Support for changing the week day position(top/bottom) in weekView. [#283](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/283)
- Adds new flag `includeEdges` in `EventArrangers`. [#290](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/pull/294)
- Fixes null check exception while adding events. [#282](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/282)
- Added new method `update` to update the events in `EventController`. [#125](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/125)
- Adds new parameter `includeFullDayEvents` in `getEventsOnDay` to decide whether to include full-day events in the returned list or not.
- Adds getters `isRangingEvent` and `isFullDayEvent` in `CalendarEventData` to check if the event is a ranging event or a full-day event.
- Adds new method `occursOnDate` in `CalendarEventData` to check if the event occurs on the given date or not.
- Make `description` in `CalendarEventData` nullable.
- #### Deprecations
- Deprecate `events` getter in `EventController` and adds `allEvents` to replace it.

# [1.0.4 - 9 Aug 2023](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/tree/1.0.4)

Expand Down
28 changes: 21 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,19 @@ assigned.

Methods provided by `EventController`

| Name | Parameters | Description |
|----------------|---------------------------------------|------------------------------------------------------|
| add | CalendarEventData\<T\> event | Adds one event in controller and rebuilds view. |
| addAll | List\<CalendarEventData\<T\>\> events | Adds list of events in controller and rebuilds view. |
| remove | CalendarEventData\<T\> event | Removes an event from controller and rebuilds view. |
| getEventsOnDay | DateTime date | Returns list of events on `date` |
| Name | Parameters | Description |
|-----------------|--------------------------------------------------------------|-----------------------------------------------------------|
| add | CalendarEventData\<T\> event | Adds one event in controller and rebuilds view. |
| addAll | List\<CalendarEventData\<T\>\> events | Adds list of events in controller and rebuilds view. |
| remove | CalendarEventData\<T\> event | Removes an event from controller and rebuilds view. |
| removeAll | List\<CalendarEventData\<T\>\> events | Removes all event defined in the list |
| removeWhere | TestPredicate\<CalendarEventData\<T\>\> test | Removes all events for which test returns true. |
| update | CalendarEventData\<T\> event, CalendarEventData\<T\> updated | Updates event with updated event. |
| getFullDayEvent | DateTime date | Returns the list of full day events stored in controller |
| updateFilter | EventFilter\<T\> newFilter | Updates the event filter of the controller. |
| getEventsOnDay | DateTime date | Returns list of events on `date` |

Check [documentation](https://pub.dev/documentation/calendar_view/latest/calendar_view/EventController-class.html) for more info.

### Use of `GlobalKey`

Expand All @@ -256,6 +263,9 @@ Methods defined by `MonthViewState` class:
| jumpToMonth | DateTime month | Jumps to the page that has a calendar for month defined by `month` |
| animateToMonth | DateTime month | Animate to the page that has a calendar for month defined by `month` |

Check [documentation](https://pub.dev/documentation/calendar_view/latest/calendar_view/MonthViewState-class.html) for more info.


Methods defined by `DayViewState` class.

| Name | Parameters | Description |
Expand All @@ -270,6 +280,8 @@ Methods defined by `DayViewState` class.
| animateToEvent | CalendarEventData event | Animates to the page where a given `event` is and then scrolls to make that `event` visible on the screen. |
| jumpToEvent | CalendarEventData event | Jumps to the page where a given `event` is and then scrolls to make that `event` visible on the screen. |

Check [documentation](https://pub.dev/documentation/calendar_view/latest/calendar_view/DayViewState-class.html) for more info.

Methods defined by `WeekViewState` class.

| Name | Parameters | Description |
Expand All @@ -283,6 +295,8 @@ Methods defined by `WeekViewState` class.
| animateToEvent | CalendarEventData event | Animates to the page where a given `event` is and then scrolls to make that `event` visible on the screen. |
| jumpToEvent | CalendarEventData event | Jumps to the page where a given `event` is and then scrolls to make that `event` visible on the screen. |

Check [documentation](https://pub.dev/documentation/calendar_view/latest/calendar_view/WeekViewState-class.html) for more info.

### Synchronize events between calendar views

There are two ways to synchronize events between calendar views.
Expand Down Expand Up @@ -353,7 +367,7 @@ copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
Expand Down
2 changes: 1 addition & 1 deletion example/lib/pages/create_event_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class CreateEventPage extends StatelessWidget {
if (this.event != null) {
CalendarControllerProvider.of(context)
.controller
.updateEvent(this.event!, newEvent);
.update(this.event!, newEvent);
} else {
CalendarControllerProvider.of(context).controller.add(newEvent);
}
Expand Down
4 changes: 2 additions & 2 deletions example/lib/pages/day_view_page.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import 'package:example/enumerations.dart';
import 'package:flutter/material.dart';

import '../enumerations.dart';
import '../extension.dart';
import '../widgets/day_view_widget.dart';
import '../widgets/responsive_widget.dart';
import 'create_event_page.dart';
import 'web/web_home_page.dart';

class DayViewPageDemo extends StatefulWidget {
const DayViewPageDemo({Key? key}) : super(key: key);
const DayViewPageDemo({super.key});

@override
_DayViewPageDemoState createState() => _DayViewPageDemoState();
Expand Down
4 changes: 2 additions & 2 deletions example/lib/pages/event_details_page.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import 'package:calendar_view/calendar_view.dart';
import 'package:example/pages/create_event_page.dart';
import 'package:flutter/material.dart';

import '../extension.dart';
import 'create_event_page.dart';

class DetailsPage extends StatelessWidget {
final CalendarEventData event;

const DetailsPage({Key? key, required this.event}) : super(key: key);
const DetailsPage({super.key, required this.event});
@override
Widget build(BuildContext context) {
return Scaffold(
Expand Down
2 changes: 1 addition & 1 deletion example/lib/pages/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'mobile/mobile_home_page.dart';
import 'web/web_home_page.dart';

class HomePage extends StatelessWidget {
const HomePage({Key? key}) : super(key: key);
const HomePage({super.key});

@override
Widget build(BuildContext context) {
Expand Down
4 changes: 2 additions & 2 deletions example/lib/pages/month_view_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import 'web/web_home_page.dart';

class MonthViewPageDemo extends StatefulWidget {
const MonthViewPageDemo({
Key? key,
}) : super(key: key);
super.key,
});

@override
_MonthViewPageDemoState createState() => _MonthViewPageDemoState();
Expand Down
7 changes: 3 additions & 4 deletions example/lib/pages/week_view_page.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import 'package:calendar_view/calendar_view.dart';
import 'package:example/enumerations.dart';
import 'package:example/widgets/responsive_widget.dart';
import 'package:flutter/material.dart';

import '../enumerations.dart';
import '../extension.dart';
import '../widgets/responsive_widget.dart';
import '../widgets/week_view_widget.dart';
import 'create_event_page.dart';
import 'web/web_home_page.dart';

class WeekViewDemo extends StatefulWidget {
const WeekViewDemo({Key? key}) : super(key: key);
const WeekViewDemo({super.key});

@override
_WeekViewDemoState createState() => _WeekViewDemoState();
Expand Down
5 changes: 5 additions & 0 deletions example/lib/widgets/add_event_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,11 @@ class _AddOrEditEventFormState extends State<AddOrEditEventForm> {
_endDate = DateTime.now().withoutTime;
_startTime = null;
_endTime = null;
_color = Colors.blue;

if (mounted) {
setState(() {});
}
}

void _displayColorPicker() {
Expand Down
4 changes: 2 additions & 2 deletions example/lib/widgets/calendar_configs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ class CalendarConfig extends StatelessWidget {
final CalendarView currentView;

const CalendarConfig({
Key? key,
super.key,
required this.onViewChange,
this.currentView = CalendarView.month,
}) : super(key: key);
});

@override
Widget build(BuildContext context) {
Expand Down
3 changes: 1 addition & 2 deletions example/lib/widgets/calendar_views.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import 'week_view_widget.dart';
class CalendarViews extends StatelessWidget {
final CalendarView view;

const CalendarViews({Key? key, this.view = CalendarView.month})
: super(key: key);
const CalendarViews({super.key, this.view = CalendarView.month});

final _breakPoint = 490.0;

Expand Down
3 changes: 1 addition & 2 deletions example/lib/widgets/custom_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ class CustomButton extends StatelessWidget {
final String title;
final VoidCallback? onTap;

const CustomButton({Key? key, required this.title, this.onTap})
: super(key: key);
const CustomButton({super.key, required this.title, this.onTap});

@override
Widget build(BuildContext context) {
Expand Down
2 changes: 0 additions & 2 deletions example/lib/widgets/date_time_selector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ class DateTimeSelectorFormField extends StatefulWidget {
}

class _DateTimeSelectorFormFieldState extends State<DateTimeSelectorFormField> {
bool _isSelectorOpen = false;

late var _minimumDate = CalendarConstants.minDate.withoutTime;

late var _textEditingController =
Expand Down
7 changes: 4 additions & 3 deletions example/lib/widgets/day_view_widget.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import 'package:calendar_view/calendar_view.dart';
import 'package:example/pages/event_details_page.dart';
import 'package:flutter/material.dart';

import '../pages/event_details_page.dart';

class DayViewWidget extends StatelessWidget {
final GlobalKey<DayViewState>? state;
final double? width;

const DayViewWidget({
Key? key,
super.key,
this.state,
this.width,
}) : super(key: key);
});

@override
Widget build(BuildContext context) {
Expand Down
4 changes: 2 additions & 2 deletions example/lib/widgets/month_view_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ class MonthViewWidget extends StatelessWidget {
final double? width;

const MonthViewWidget({
Key? key,
super.key,
this.state,
this.width,
}) : super(key: key);
});

@override
Widget build(BuildContext context) {
Expand Down
4 changes: 2 additions & 2 deletions example/lib/widgets/responsive_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ class ResponsiveWidget extends StatelessWidget {
final Widget mobileWidget;

const ResponsiveWidget({
Key? key,
super.key,
this.width,
this.breakPoint = BreakPoints.web,
required this.webWidget,
required this.mobileWidget,
}) : super(key: key);
});

@override
Widget build(BuildContext context) {
Expand Down
2 changes: 1 addition & 1 deletion example/lib/widgets/week_view_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class WeekViewWidget extends StatelessWidget {
final GlobalKey<WeekViewState>? state;
final double? width;

const WeekViewWidget({Key? key, this.state, this.width}) : super(key: key);
const WeekViewWidget({super.key, this.state, this.width});

@override
Widget build(BuildContext context) {
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1

environment:
sdk: ">=2.18.6 <3.0.0"
sdk: ">=3.0.0 <4.0.0"
flutter: ^3.3.10

dependencies:
Expand Down
65 changes: 55 additions & 10 deletions lib/src/calendar_event_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

import 'package:flutter/material.dart';

import 'extensions.dart';
import '../calendar_view.dart';

/// Stores all the events on [date]
@immutable

/// {@macro calendar_event_data_doc}
class CalendarEventData<T extends Object?> {
/// Specifies date on which all these events are.
final DateTime date;
Expand Down Expand Up @@ -43,13 +44,10 @@ class CalendarEventData<T extends Object?> {
/// Define style of description.
final TextStyle? descriptionStyle;

/// Stores all the events on [date].
///
/// If [startTime] and [endTime] both are 0 or either of them is null, then
/// event will be considered a full day event.
///
const CalendarEventData({
/// {@macro calendar_event_data_doc}
CalendarEventData({
required this.title,
required DateTime date,
this.description,
this.event,
this.color = Colors.blue,
Expand All @@ -58,23 +56,43 @@ class CalendarEventData<T extends Object?> {
this.titleStyle,
this.descriptionStyle,
DateTime? endDate,
required this.date,
}) : _endDate = endDate;
}) : _endDate = endDate?.withoutTime,
date = date.withoutTime;

DateTime get endDate => _endDate ?? date;

/// If this flag returns true that means event is occurring on multiple
/// days and is not a full day event.
///
bool get isRangingEvent {
final diff = endDate.withoutTime.difference(date.withoutTime).inDays;

return diff > 0 && !isFullDayEvent;
}

/// Returns if the events is full day event or not.
///
/// If it returns true that means the events is full day. but also it can
/// span across multiple days.
///
bool get isFullDayEvent {
return (startTime == null ||
endTime == null ||
(startTime!.isDayStart && endTime!.isDayStart));
}

/// Returns a boolean that defines whether current event is occurring on
/// [currentDate] or not.
///
bool occursOnDate(DateTime currentDate) {
return currentDate == date ||
currentDate == endDate ||
(currentDate.isBefore(endDate.withoutTime) &&
currentDate.isAfter(date.withoutTime));
}

/// Returns event data in [Map<String, dynamic>] format.
///
Map<String, dynamic> toJson() => {
"date": date,
"startTime": startTime,
Expand All @@ -85,6 +103,9 @@ class CalendarEventData<T extends Object?> {
"endDate": endDate,
};

/// Returns new object of [CalendarEventData] with the updated values defined
/// as the arguments.
///
CalendarEventData<T> copyWith({
String? title,
String? description,
Expand Down Expand Up @@ -139,3 +160,27 @@ class CalendarEventData<T extends Object?> {
@override
int get hashCode => super.hashCode;
}

/// {@template calendar_event_data_doc}
/// Stores all the events on [date].
///
/// If [startTime] and [endTime] both are 0 or either of them is null, then
/// event will be considered a full day event.
///
/// - [date] and [endDate] are used to define dates only. So, If you
/// are providing any time information with these two arguments,
/// it will be ignored.
///
/// - [startTime] and [endTime] are used to define the time span of the event.
/// So, If you are providing any day information (year, month, day), it will
/// be ignored. It will also, consider only hour and minutes as time. So,
/// seconds, milliseconds and microseconds will be ignored as well.
///
/// - [startTime] and [endTime] can not span more then one day. For example,
/// If start time is 11th Nov 11:30 PM and end time is 12th Nov 1:30 AM, it
/// will not be considered as valid time. Because for [startTime] and [endTime],
/// day will be ignored so, 11:30 PM ([startTime]) occurs after
/// 1:30 AM ([endTime]). Events with invalid time will throw
/// [AssertionError] in debug mode and will be ignored in release mode
/// in [DayView] and [WeekView].
/// {@endtemplate}
Loading

0 comments on commit 252bbf8

Please sign in to comment.