From 8855d85690ef9f5b497fb27b28c1d9bf37734df9 Mon Sep 17 00:00:00 2001 From: Jonas Wanke Date: Tue, 24 Jan 2023 15:39:34 +0100 Subject: [PATCH] Implement Diagnosticable for VisibleDateRange --- lib/src/date/controller.dart | 12 +++++++++--- lib/src/date/visible_date_range.dart | 29 +++++++++++++++++++++++----- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/lib/src/date/controller.dart b/lib/src/date/controller.dart index 654f84a..ee59800 100644 --- a/lib/src/date/controller.dart +++ b/lib/src/date/controller.dart @@ -143,7 +143,7 @@ class DateController extends ValueNotifier { /// The value held by [DateController]. @immutable -class DatePageValue { +class DatePageValue with Diagnosticable { const DatePageValue(this.visibleRange, this.page); final VisibleDateRange visibleRange; @@ -198,8 +198,14 @@ class DatePageValue { } @override - String toString() => - 'DatePageValue(visibleRange = $visibleRange, page = $page)'; + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add( + DiagnosticsProperty('visibleRange', visibleRange), + ); + properties.add(DoubleProperty('page', page)); + properties.add(DateDiagnosticsProperty('date', date)); + } } /// Provides the [DateController] for Timetable widgets below it. diff --git a/lib/src/date/visible_date_range.dart b/lib/src/date/visible_date_range.dart index e7640ba..b00cfaa 100644 --- a/lib/src/date/visible_date_range.dart +++ b/lib/src/date/visible_date_range.dart @@ -1,3 +1,4 @@ +import 'package:flutter/foundation.dart'; import 'package:flutter/physics.dart'; import '../layouts/recurring_multi_date.dart'; @@ -5,7 +6,7 @@ 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, @@ -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; @@ -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)); + } }