Skip to content

Commit

Permalink
Implement Diagnosticable for VisibleDateRange
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasWanke committed Jan 24, 2023
1 parent 469a0de commit 8855d85
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
12 changes: 9 additions & 3 deletions lib/src/date/controller.dart
Expand Up @@ -143,7 +143,7 @@ class DateController extends ValueNotifier<DatePageValue> {

/// The value held by [DateController].
@immutable
class DatePageValue {
class DatePageValue with Diagnosticable {
const DatePageValue(this.visibleRange, this.page);

final VisibleDateRange visibleRange;
Expand Down Expand Up @@ -198,8 +198,14 @@ class DatePageValue {
}

@override
String toString() =>
'DatePageValue(visibleRange = $visibleRange, page = $page)';
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(
DiagnosticsProperty<VisibleDateRange>('visibleRange', visibleRange),
);
properties.add(DoubleProperty('page', page));
properties.add(DateDiagnosticsProperty('date', date));
}
}

/// Provides the [DateController] for Timetable widgets below it.
Expand Down
29 changes: 24 additions & 5 deletions lib/src/date/visible_date_range.dart
@@ -1,11 +1,12 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/physics.dart';

import '../layouts/recurring_multi_date.dart';
import '../utils.dart';

/// Defines how many days are visible at once and whether they, e.g., snap to
/// weeks.
abstract class VisibleDateRange {
abstract class VisibleDateRange with Diagnosticable {
const VisibleDateRange({
required this.visibleDayCount,
required this.canScroll,
Expand Down Expand Up @@ -174,16 +175,27 @@ class DaysVisibleDateRange extends VisibleDateRange {
);
return page - targetPage;
}

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(IntProperty('swipeRange', swipeRange));
properties.add(DateDiagnosticsProperty('alignmentDate', alignmentDate));
properties
.add(DateDiagnosticsProperty('minDate', minDate, defaultValue: null));
properties.add(DoubleProperty('minPage', minPage, defaultValue: null));
properties
.add(DateDiagnosticsProperty('maxDate', maxDate, defaultValue: null));
properties.add(DoubleProperty('maxPage', maxPage, defaultValue: null));
}
}

/// A non-scrollable [VisibleDateRange], used by [VisibleDateRange.fixed].
///
/// This is useful for, e.g., [RecurringMultiDateTimetable].
class FixedDaysVisibleDateRange extends VisibleDateRange {
FixedDaysVisibleDateRange(
this.startDate,
int visibleDayCount,
) : assert(startDate.debugCheckIsValidTimetableDate()),
FixedDaysVisibleDateRange(this.startDate, int visibleDayCount)
: assert(startDate.debugCheckIsValidTimetableDate()),
super(visibleDayCount: visibleDayCount, canScroll: false);

final DateTime startDate;
Expand All @@ -204,4 +216,11 @@ class FixedDaysVisibleDateRange extends VisibleDateRange {
Tolerance tolerance = Tolerance.defaultTolerance,
}) =>
page;

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(DateDiagnosticsProperty('startDate', startDate));
properties.add(DoubleProperty('page', page));
}
}

0 comments on commit 8855d85

Please sign in to comment.