Skip to content

Commit

Permalink
:feat: adds option to update the events. (#297)
Browse files Browse the repository at this point in the history
* ✨ Adds new method updateEvent to update the existing event in the calendar view.

- Fixes issue #125

* ✨ Add option to view, delete and update the events in example.

- Migrate example to flutter 3.3.10

* ✨ Quick fixes before PR.
  • Loading branch information
PRBaraiya authored Dec 13, 2023
1 parent 060fb36 commit d65bb7f
Show file tree
Hide file tree
Showing 30 changed files with 783 additions and 396 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
1 change: 0 additions & 1 deletion example/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
/build/

# Web related
lib/generated_plugin_registrant.dart

# Symbolication related
app.*.symbols
Expand Down
22 changes: 5 additions & 17 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ import 'dart:ui';
import 'package:calendar_view/calendar_view.dart';
import 'package:flutter/material.dart';

import 'model/event.dart';
import 'pages/mobile/mobile_home_page.dart';
import 'pages/web/web_home_page.dart';
import 'widgets/responsive_widget.dart';
import 'pages/home_page.dart';

DateTime get _now => DateTime.now();

Expand All @@ -18,8 +15,8 @@ class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return CalendarControllerProvider<Event>(
controller: EventController<Event>()..addAll(_events),
return CalendarControllerProvider(
controller: EventController()..addAll(_events),
child: MaterialApp(
title: 'Flutter Calendar Page Demo',
debugShowCheckedModeBanner: false,
Expand All @@ -31,19 +28,15 @@ class MyApp extends StatelessWidget {
PointerDeviceKind.touch,
},
),
home: ResponsiveWidget(
mobileWidget: MobileHomePage(),
webWidget: WebHomePage(),
),
home: HomePage(),
),
);
}
}

List<CalendarEventData<Event>> _events = [
List<CalendarEventData> _events = [
CalendarEventData(
date: _now,
event: Event(title: "Joe's Birthday"),
title: "Project meeting",
description: "Today is project meeting.",
startTime: DateTime(_now.year, _now.month, _now.day, 18, 30),
Expand All @@ -53,15 +46,13 @@ List<CalendarEventData<Event>> _events = [
date: _now.add(Duration(days: 1)),
startTime: DateTime(_now.year, _now.month, _now.day, 18),
endTime: DateTime(_now.year, _now.month, _now.day, 19),
event: Event(title: "Wedding anniversary"),
title: "Wedding anniversary",
description: "Attend uncle's wedding anniversary.",
),
CalendarEventData(
date: _now,
startTime: DateTime(_now.year, _now.month, _now.day, 14),
endTime: DateTime(_now.year, _now.month, _now.day, 17),
event: Event(title: "Football Tournament"),
title: "Football Tournament",
description: "Go to football tournament.",
),
Expand All @@ -71,7 +62,6 @@ List<CalendarEventData<Event>> _events = [
_now.add(Duration(days: 3)).month, _now.add(Duration(days: 3)).day, 10),
endTime: DateTime(_now.add(Duration(days: 3)).year,
_now.add(Duration(days: 3)).month, _now.add(Duration(days: 3)).day, 14),
event: Event(title: "Sprint Meeting."),
title: "Sprint Meeting.",
description: "Last day of project submission for last year.",
),
Expand All @@ -87,7 +77,6 @@ List<CalendarEventData<Event>> _events = [
_now.subtract(Duration(days: 2)).month,
_now.subtract(Duration(days: 2)).day,
16),
event: Event(title: "Team Meeting"),
title: "Team Meeting",
description: "Team Meeting",
),
Expand All @@ -103,7 +92,6 @@ List<CalendarEventData<Event>> _events = [
_now.subtract(Duration(days: 2)).month,
_now.subtract(Duration(days: 2)).day,
12),
event: Event(title: "Chemistry Viva"),
title: "Chemistry Viva",
description: "Today is Joe's birthday.",
),
Expand Down
17 changes: 0 additions & 17 deletions example/lib/model/event.dart

This file was deleted.

42 changes: 19 additions & 23 deletions example/lib/pages/create_event_page.dart
Original file line number Diff line number Diff line change
@@ -1,29 +1,14 @@
import 'package:calendar_view/calendar_view.dart';
import 'package:flutter/material.dart';

import '../app_colors.dart';
import '../extension.dart';
import '../widgets/add_event_widget.dart';
import '../widgets/add_event_form.dart';

class CreateEventPage extends StatefulWidget {
final bool withDuration;
class CreateEventPage extends StatelessWidget {
const CreateEventPage({super.key, this.event});

const CreateEventPage({Key? key, this.withDuration = false})
: super(key: key);

@override
_CreateEventPageState createState() => _CreateEventPageState();
}

class _CreateEventPageState extends State<CreateEventPage> {
@override
void initState() {
super.initState();
}

@override
void dispose() {
super.dispose();
}
final CalendarEventData? event;

@override
Widget build(BuildContext context) {
Expand All @@ -40,7 +25,7 @@ class _CreateEventPageState extends State<CreateEventPage> {
),
),
title: Text(
"Create New Event",
event == null ? "Create New Event" : "Update Event",
style: TextStyle(
color: AppColors.black,
fontSize: 20.0,
Expand All @@ -52,8 +37,19 @@ class _CreateEventPageState extends State<CreateEventPage> {
physics: ClampingScrollPhysics(),
child: Padding(
padding: EdgeInsets.all(20.0),
child: AddEventWidget(
onEventAdd: context.pop,
child: AddOrEditEventForm(
onEventAdd: (newEvent) {
if (this.event != null) {
CalendarControllerProvider.of(context)
.controller
.update(this.event!, newEvent);
} else {
CalendarControllerProvider.of(context).controller.add(newEvent);
}

context.pop(true);
},
event: event,
),
),
),
Expand Down
31 changes: 15 additions & 16 deletions example/lib/pages/day_view_page.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import 'package:calendar_view/calendar_view.dart';
import 'package:flutter/material.dart';

import '../enumerations.dart';
import '../extension.dart';
import '../model/event.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 All @@ -16,20 +17,18 @@ class DayViewPageDemo extends StatefulWidget {
class _DayViewPageDemoState extends State<DayViewPageDemo> {
@override
Widget build(BuildContext context) {
return Scaffold(
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add),
elevation: 8,
onPressed: () async {
final event =
await context.pushRoute<CalendarEventData<Event>>(CreateEventPage(
withDuration: true,
));
if (event == null) return;
CalendarControllerProvider.of<Event>(context).controller.add(event);
},
return ResponsiveWidget(
webWidget: WebHomePage(
selectedView: CalendarView.day,
),
mobileWidget: Scaffold(
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add),
elevation: 8,
onPressed: () => context.pushRoute(CreateEventPage()),
),
body: DayViewWidget(),
),
body: DayViewWidget(),
);
}
}
44 changes: 40 additions & 4 deletions example/lib/pages/event_details_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import 'package:calendar_view/calendar_view.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 Expand Up @@ -76,14 +77,49 @@ class DetailsPage extends StatelessWidget {
height: 30.0,
),
],
if (event.description != "") ...[
if (event.description?.isNotEmpty ?? false) ...[
Divider(),
Text("Description"),
SizedBox(
height: 10.0,
),
Text(event.description),
]
Text(event.description!),
],
const SizedBox(height: 50),
Row(
children: [
Expanded(
child: ElevatedButton(
onPressed: () {
CalendarControllerProvider.of(context)
.controller
.remove(event);
Navigator.of(context).pop();
},
child: Text('Delete Event'),
),
),
SizedBox(width: 30),
Expanded(
child: ElevatedButton(
onPressed: () async {
final result = await Navigator.of(context).push(
MaterialPageRoute(
builder: (_) => CreateEventPage(
event: event,
),
),
);

if (result) {
Navigator.of(context).pop();
}
},
child: Text('Edit Event'),
),
),
],
),
],
),
);
Expand Down
17 changes: 17 additions & 0 deletions example/lib/pages/home_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import 'package:flutter/material.dart';

import '../widgets/responsive_widget.dart';
import 'mobile/mobile_home_page.dart';
import 'web/web_home_page.dart';

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

@override
Widget build(BuildContext context) {
return ResponsiveWidget(
mobileWidget: MobileHomePage(),
webWidget: WebHomePage(),
);
}
}
Loading

0 comments on commit d65bb7f

Please sign in to comment.