summaryrefslogtreecommitdiffstats
path: root/packages/flutter_calendar_carousel/lib/classes
diff options
context:
space:
mode:
Diffstat (limited to 'packages/flutter_calendar_carousel/lib/classes')
-rw-r--r--packages/flutter_calendar_carousel/lib/classes/event.dart79
-rw-r--r--packages/flutter_calendar_carousel/lib/classes/event_list.dart40
-rw-r--r--packages/flutter_calendar_carousel/lib/classes/marked_date.dart46
-rw-r--r--packages/flutter_calendar_carousel/lib/classes/multiple_marked_dates.dart86
4 files changed, 251 insertions, 0 deletions
diff --git a/packages/flutter_calendar_carousel/lib/classes/event.dart b/packages/flutter_calendar_carousel/lib/classes/event.dart
new file mode 100644
index 0000000..c852a94
--- /dev/null
+++ b/packages/flutter_calendar_carousel/lib/classes/event.dart
@@ -0,0 +1,79 @@
+import 'package:flutter/material.dart';
+
+class Event implements EventInterface {
+ final DateTime date;
+ final String? title;
+ final String? description;
+ final String? location;
+ final Widget? icon;
+ final Widget? dot;
+ final int? id;
+ Event({
+ this.id,
+ required this.date,
+ this.title,
+ this.description,
+ this.location,
+ this.icon,
+ this.dot,
+ });
+
+ @override
+ bool operator ==(dynamic other) {
+ return date == other.date &&
+ title == other.title &&
+ description == other.description &&
+ location == other.location &&
+ icon == other.icon &&
+ dot == other.dot &&
+ id == other.id;
+ }
+
+ @override
+ int get hashCode => Object.hash(date, description, location, title, icon, id);
+
+ @override
+ DateTime getDate() {
+ return date;
+ }
+
+ @override
+ int? getId() {
+ return id;
+ }
+
+ @override
+ Widget? getDot() {
+ return dot;
+ }
+
+ @override
+ Widget? getIcon() {
+ return icon;
+ }
+
+ @override
+ String? getTitle() {
+ return title;
+ }
+
+ @override
+ String? getDescription() {
+ return description;
+ }
+
+ @override
+ String? getLocation() {
+ return location;
+ }
+}
+
+abstract class EventInterface {
+ DateTime getDate();
+ String? getTitle();
+ String? getDescription();
+ String? getLocation();
+ Widget? getIcon();
+ Widget? getDot();
+ int? getId();
+}
diff --git a/packages/flutter_calendar_carousel/lib/classes/event_list.dart b/packages/flutter_calendar_carousel/lib/classes/event_list.dart
new file mode 100644
index 0000000..a8c9252
--- /dev/null
+++ b/packages/flutter_calendar_carousel/lib/classes/event_list.dart
@@ -0,0 +1,40 @@
+class EventList<T> {
+ Map<DateTime, List<T>> events;
+
+ EventList({
+ required this.events,
+ });
+
+ void add(DateTime date, T event) {
+ final eventsOfDate = events[date];
+ if (eventsOfDate == null)
+ events[date] = [event];
+ else
+ eventsOfDate.add(event);
+ }
+
+ void addAll(DateTime date, List<T> events) {
+ final eventsOfDate = this.events[date];
+ if (eventsOfDate == null)
+ this.events[date] = events;
+ else
+ eventsOfDate.addAll(events);
+ }
+
+ bool remove(DateTime date, T event) {
+ final eventsOfDate = events[date];
+ return eventsOfDate != null ? eventsOfDate.remove(event) : false;
+ }
+
+ List<T> removeAll(DateTime date) {
+ return events.remove(date) ?? [];
+ }
+
+ void clear() {
+ events.clear();
+ }
+
+ List<T> getEvents(DateTime date) {
+ return events[date] ?? [];
+ }
+}
diff --git a/packages/flutter_calendar_carousel/lib/classes/marked_date.dart b/packages/flutter_calendar_carousel/lib/classes/marked_date.dart
new file mode 100644
index 0000000..a3db2d5
--- /dev/null
+++ b/packages/flutter_calendar_carousel/lib/classes/marked_date.dart
@@ -0,0 +1,46 @@
+import 'package:flutter/material.dart';
+
+class MarkedDate implements MarkedDateInterface {
+ final Color color;
+ final int? id;
+ final TextStyle? textStyle;
+ final DateTime date;
+
+ MarkedDate({
+ required this.color,
+ this.id,
+ this.textStyle,
+ required this.date,
+ });
+
+ @override
+ bool operator ==(dynamic other) {
+ return date == other.date &&
+ color == other.color &&
+ textStyle == other.textStyle &&
+ id == other.id;
+ }
+
+ @override
+ DateTime getDate() => this.date;
+
+ @override
+ int? getId() => this.id;
+
+ @override
+ Color getColor() => this.color;
+
+ @override
+ TextStyle? getTextStyle() => this.textStyle;
+
+ @override
+ // TODO: implement hashCode
+ int get hashCode => super.hashCode;
+}
+
+abstract class MarkedDateInterface {
+ DateTime getDate();
+ Color getColor();
+ int? getId();
+ TextStyle? getTextStyle();
+}
diff --git a/packages/flutter_calendar_carousel/lib/classes/multiple_marked_dates.dart b/packages/flutter_calendar_carousel/lib/classes/multiple_marked_dates.dart
new file mode 100644
index 0000000..3934549
--- /dev/null
+++ b/packages/flutter_calendar_carousel/lib/classes/multiple_marked_dates.dart
@@ -0,0 +1,86 @@
+import 'marked_date.dart';
+import 'package:flutter/material.dart';
+
+class MultipleMarkedDates {
+ List<MarkedDate> markedDates;
+
+ MultipleMarkedDates({required this.markedDates});
+
+ void add(MarkedDate markedDate) {
+ markedDates.add(markedDate);
+ }
+
+ void addRange(MarkedDate markedDate, {int plus = 0, int minus = 0}) {
+ this.add(markedDate);
+
+ if (plus > 0) {
+ int start = 1;
+ MarkedDate newAddMarkedDate;
+
+ while (start <= plus) {
+ newAddMarkedDate = new MarkedDate(
+ color: markedDate.color,
+ date: markedDate.date.add(Duration(days: start)),
+ textStyle: markedDate.textStyle,
+ );
+
+ this.add(newAddMarkedDate);
+
+ start += 1;
+ }
+ }
+
+ if (minus > 0) {
+ int start = 1;
+ MarkedDate newSubMarkedDate;
+
+ while (start <= minus) {
+ newSubMarkedDate = new MarkedDate(
+ color: markedDate.color,
+ date: markedDate.date.subtract(Duration(days: start)),
+ textStyle: markedDate.textStyle,
+ );
+
+ this.add(newSubMarkedDate);
+
+ start += 1;
+ }
+ }
+ }
+
+ void addAll(List<MarkedDate> markedDates) {
+ this.markedDates.addAll(markedDates);
+ }
+
+ bool remove(MarkedDate markedDate) {
+ return markedDates.remove(markedDate);
+ }
+
+ void clear() {
+ markedDates.clear();
+ }
+
+ bool isMarked(DateTime date) {
+ final results = markedDates.firstWhere((element) => element.date == date,
+ orElse: () => MarkedDate(color: Colors.black, date: DateTime(0)));
+ return results.date.year == date.year;
+ }
+
+ Color getColor(DateTime date) {
+ final results = markedDates.firstWhere((element) => element.date == date,
+ orElse: () => MarkedDate(color: Colors.black, date: DateTime(0)));
+ return results.color;
+ }
+
+ DateTime getDate(DateTime date) {
+ final results = markedDates.firstWhere((element) => element.date == date,
+ orElse: () => MarkedDate(color: Colors.black, date: DateTime(0)));
+ return results.date;
+ }
+
+ TextStyle? getTextStyle(DateTime date) {
+ final results = markedDates.firstWhere((element) => element.date == date,
+ orElse: () => MarkedDate(color: Colors.black, date: DateTime(0)));
+ return results.textStyle;
+ }
+}