Skip to content
Open
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
2 changes: 1 addition & 1 deletion example/lib/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void initDebugOverlay() {
}

class ExampleApp extends StatelessWidget {
const ExampleApp({required this.child});
const ExampleApp({super.key, required this.child});

final Widget child;

Expand Down
32 changes: 28 additions & 4 deletions lib/src/event/basic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:black_hole_flutter/black_hole_flutter.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

import '../utils.dart';
import 'all_day.dart';
import 'event.dart';

Expand All @@ -11,14 +12,14 @@ import 'event.dart';
///
/// * [BasicEventWidget], which can display instances of [BasicEvent].
@immutable
class BasicEvent extends Event {
class BasicEvent with Diagnosticable implements Event {
const BasicEvent({
required this.id,
required this.title,
required this.backgroundColor,
required super.start,
required super.end,
});
required this.start,
required this.end,
}) : assert(start <= end);

/// An ID for this event.
///
Expand All @@ -37,6 +38,17 @@ class BasicEvent extends Event {
/// This is currently used by [BasicEventWidget] and [BasicAllDayEventWidget].
final Color backgroundColor;

/// Start of the event; inclusive.
@override
final DateTime start;

/// End of the event; exclusive.
@override
final DateTime end;

@override
bool get isAllDay => end.difference(start).inDays >= 1;

BasicEvent copyWith({
Object? id,
String? title,
Expand All @@ -55,6 +67,7 @@ class BasicEvent extends Event {

@override
int get hashCode => Object.hash(super.hashCode, title, backgroundColor);

@override
bool operator ==(Object other) =>
other is BasicEvent &&
Expand All @@ -68,6 +81,16 @@ class BasicEvent extends Event {
properties.add(DiagnosticsProperty('id', id));
properties.add(StringProperty('title', title));
properties.add(ColorProperty('backgroundColor', backgroundColor));
properties.add(DiagnosticsProperty('start', start));
properties.add(DiagnosticsProperty('end', end));
properties.add(
FlagProperty(
'isAllDay',
value: isAllDay,
ifTrue: 'all-day',
ifFalse: 'part-day',
),
);
}
}

Expand Down Expand Up @@ -232,6 +255,7 @@ class BasicAllDayEventWidgetStyle {

@override
int get hashCode => Object.hash(margin, radii, padding, textStyle);

@override
bool operator ==(Object other) {
return other is BasicAllDayEventWidgetStyle &&
Expand Down
30 changes: 4 additions & 26 deletions lib/src/event/event.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'package:flutter/foundation.dart';

import '../utils.dart';
import 'basic.dart';

Expand All @@ -8,34 +6,14 @@ import 'basic.dart';
/// See also:
///
/// * [BasicEvent], which provides a basic implementation to get you started.
abstract class Event with Diagnosticable {
const Event({
required this.start,
required this.end,
}) : assert(start <= end);

abstract interface class Event {
/// Start of the event; inclusive.
final DateTime start;
DateTime get start;

/// End of the event; exclusive.
final DateTime end;
DateTime get end;

bool get isAllDay => end.difference(start).inDays >= 1;

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(DiagnosticsProperty('start', start));
properties.add(DiagnosticsProperty('end', end));
properties.add(
FlagProperty(
'isAllDay',
value: isAllDay,
ifTrue: 'all-day',
ifFalse: 'part-day',
),
);
}
bool get isAllDay;
}

extension EventExtension on Event {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/time/zoom.dart
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ class _RenderVerticalOverflowBox extends RenderShiftedBox {
class _ScaleGestureRecognizer extends OneSequenceGestureRecognizer {
_ScaleGestureRecognizer({
super.debugOwner,
// ignore: unused_element
// ignore: unused_element_parameter
this.dragStartBehavior = DragStartBehavior.down,
});

Expand Down
14 changes: 11 additions & 3 deletions test/event_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,15 @@ void main() {
});
}

class _TestEvent extends Event {
const _TestEvent(DateTime start, DateTime end)
: super(start: start, end: end);
class _TestEvent implements Event {
const _TestEvent(this.start, this.end);

@override
final DateTime start;

@override
final DateTime end;

@override
bool get isAllDay => end.difference(start).inDays >= 1;
}