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

🐛 fix: remove event from repeated events. #43

Merged
merged 1 commit into from
Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion example/lib/pages/create_event_page.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import '../app_colors.dart';
Expand Down
1 change: 0 additions & 1 deletion example/lib/pages/web/web_home_page.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import '../../enumerations.dart';
Expand Down
75 changes: 54 additions & 21 deletions example/lib/widgets/add_event_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class AddEventWidget extends StatefulWidget {
}

class _AddEventWidgetState extends State<AddEventWidget> {
late DateTime _date;
late DateTime _startDate;
late DateTime _endDate;

DateTime? _startTime;

Expand All @@ -42,9 +43,10 @@ class _AddEventWidgetState extends State<AddEventWidget> {

final GlobalKey<FormState> _form = GlobalKey();

late TextEditingController _dateController;
late TextEditingController _startDateController;
late TextEditingController _startTimeController;
late TextEditingController _endTimeController;
late TextEditingController _endDateController;

@override
void initState() {
Expand All @@ -54,7 +56,8 @@ class _AddEventWidgetState extends State<AddEventWidget> {
_descriptionNode = FocusNode();
_dateNode = FocusNode();

_dateController = TextEditingController();
_startDateController = TextEditingController();
_endDateController = TextEditingController();
_startTimeController = TextEditingController();
_endTimeController = TextEditingController();
}
Expand All @@ -65,7 +68,8 @@ class _AddEventWidgetState extends State<AddEventWidget> {
_descriptionNode.dispose();
_dateNode.dispose();

_dateController.dispose();
_startDateController.dispose();
_endDateController.dispose();
_startTimeController.dispose();
_endTimeController.dispose();

Expand Down Expand Up @@ -100,22 +104,50 @@ class _AddEventWidgetState extends State<AddEventWidget> {
SizedBox(
height: 15,
),
DateTimeSelectorFormField(
controller: _dateController,
decoration: AppConstants.inputDecoration.copyWith(
labelText: "Select Date",
),
validator: (value) {
if (value == null || value == "") return "Please select date.";
Row(
children: [
Expanded(
child: DateTimeSelectorFormField(
controller: _startDateController,
decoration: AppConstants.inputDecoration.copyWith(
labelText: "Start Date",
),
validator: (value) {
if (value == null || value == "")
return "Please select date.";

return null;
},
textStyle: TextStyle(
color: AppColors.black,
fontSize: 17.0,
),
onSave: (date) => _date = date,
type: DateTimeSelectionType.date,
return null;
},
textStyle: TextStyle(
color: AppColors.black,
fontSize: 17.0,
),
onSave: (date) => _startDate = date,
type: DateTimeSelectionType.date,
),
),
SizedBox(width: 20.0),
Expanded(
child: DateTimeSelectorFormField(
controller: _endDateController,
decoration: AppConstants.inputDecoration.copyWith(
labelText: "End Date",
),
validator: (value) {
if (value == null || value == "")
return "Please select date.";

return null;
},
textStyle: TextStyle(
color: AppColors.black,
fontSize: 17.0,
),
onSave: (date) => _endDate = date,
type: DateTimeSelectionType.date,
),
),
],
),
SizedBox(
height: 15,
Expand Down Expand Up @@ -230,11 +262,12 @@ class _AddEventWidgetState extends State<AddEventWidget> {
_form.currentState?.save();

final event = CalendarEventData<Event>(
date: _date,
date: _startDate,
color: _color,
endTime: _endTime,
startTime: _startTime,
description: _description,
endDate: _endDate,
title: _title,
event: Event(
title: _title,
Expand All @@ -247,7 +280,7 @@ class _AddEventWidgetState extends State<AddEventWidget> {

void _resetForm() {
_form.currentState?.reset();
_dateController.text = "";
_startDateController.text = "";
_endTimeController.text = "";
_startTimeController.text = "";
}
Expand Down
1 change: 0 additions & 1 deletion lib/src/calendar_event_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Use of this source code is governed by a MIT-style license
// that can be found in the LICENSE file.

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import 'extensions.dart';
Expand Down
1 change: 0 additions & 1 deletion lib/src/components/week_view_components.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// that can be found in the LICENSE file.

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

import 'common_components.dart';

Expand Down
19 changes: 17 additions & 2 deletions lib/src/event_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ class EventController<T> extends ChangeNotifier {
this.eventFilter,
});

// Stores events that occurs only once in a tree type structure.
final _events = <_YearEvent<T>>[];

// Stores all the events in a list.
final _eventList = <CalendarEventData<T>>[];

// Stores all the ranging events in a list.
final _rangingEventList = <CalendarEventData<T>>[];

/// Returns list of [CalendarEventData<T>] stored in this controller.
Expand Down Expand Up @@ -56,9 +59,18 @@ class EventController<T> extends ChangeNotifier {
for (final e in _events) {
if (e.year == event.date.year) {
e.removeEvent(event);
_eventList.removeWhere((element) => element.event == event.event);
_eventList.remove(event);
notifyListeners();
break;
return;
}
}

for (final e in _rangingEventList) {
if (e == event) {
_rangingEventList.remove(event);
_eventList.remove(event);
notifyListeners();
return;
}
}
}
Expand All @@ -74,6 +86,8 @@ class EventController<T> extends ChangeNotifier {
for (final e in _events) {
if (e.year == event.date.year && e.addEvent(event)) {
_eventList.add(event);
notifyListeners();

return;
}
}
Expand All @@ -84,6 +98,7 @@ class EventController<T> extends ChangeNotifier {
_eventList.add(event);
}
}

notifyListeners();
}

Expand Down
1 change: 0 additions & 1 deletion lib/src/week_view/week_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Use of this source code is governed by a MIT-style license
// that can be found in the LICENSE file.

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import '../calendar_constants.dart';
Expand Down