From 8aa85b1d20496d0b0bac8069bee821486f6584f6 Mon Sep 17 00:00:00 2001 From: Shubham Jitiya Date: Mon, 28 Oct 2024 14:48:31 +0530 Subject: [PATCH] feat: Fixes issue #413: Set max width of event slot in week & day view --- CHANGELOG.md | 1 + example/lib/widgets/day_view_widget.dart | 1 + example/lib/widgets/week_view_widget.dart | 1 + lib/src/event_arrangers/side_event_arranger.dart | 10 +++++++++- 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cc07b30a..22a6b9f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - Fixes issue calendar scroll physics for day & week view. [#417](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/417) - Adds `onTimestampTap` callback in `WeekView` and `DayView`. [#383](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/383) +- Use `maxWidth` to set max width of event slot in day & week view. [#413](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/413) - `Deprecations`: - deprecated `backgroundColor` and `iconColor` from `CalendarPageHeader`, `DayPageHeader`, `MonthPageHeader` and `WeekPageHeader`. - **Solution:** use `headerStyle` instead. diff --git a/example/lib/widgets/day_view_widget.dart b/example/lib/widgets/day_view_widget.dart index 46b9d979..bc8cf3f8 100644 --- a/example/lib/widgets/day_view_widget.dart +++ b/example/lib/widgets/day_view_widget.dart @@ -23,6 +23,7 @@ class DayViewWidget extends StatelessWidget { heightPerMinute: 3, timeLineBuilder: _timeLineBuilder, scrollPhysics: const BouncingScrollPhysics(), + eventArranger: SideEventArranger(maxWidth: 30), hourIndicatorSettings: HourIndicatorSettings( color: Theme.of(context).dividerColor, ), diff --git a/example/lib/widgets/week_view_widget.dart b/example/lib/widgets/week_view_widget.dart index 337c1213..765e8fcb 100644 --- a/example/lib/widgets/week_view_widget.dart +++ b/example/lib/widgets/week_view_widget.dart @@ -15,6 +15,7 @@ class WeekViewWidget extends StatelessWidget { key: state, width: width, showLiveTimeLineInAllDays: true, + eventArranger: SideEventArranger(maxWidth: 30), timeLineWidth: 65, scrollPhysics: const BouncingScrollPhysics(), liveTimeIndicatorSettings: LiveTimeIndicatorSettings( diff --git a/lib/src/event_arrangers/side_event_arranger.dart b/lib/src/event_arrangers/side_event_arranger.dart index c11a725b..5c0283c9 100644 --- a/lib/src/event_arrangers/side_event_arranger.dart +++ b/lib/src/event_arrangers/side_event_arranger.dart @@ -8,6 +8,7 @@ class SideEventArranger extends EventArranger { /// This class will provide method that will arrange /// all the events side by side. const SideEventArranger({ + this.maxWidth, this.includeEdges = false, }); @@ -19,6 +20,12 @@ class SideEventArranger extends EventArranger { /// final bool includeEdges; + /// If enough space is available, the event slot will + /// use the specified max width. + /// Otherwise, it will reduce to fit all events in the cell. + /// If max width is not specified, slots will expand to fill the cell. + final double? maxWidth; + /// {@macro event_arranger_arrange_method_doc} /// /// Make sure that all the events that are passed in [events], must be in @@ -100,7 +107,8 @@ class SideEventArranger extends EventArranger { final arranged = >[]; for (final event in events) { - final slotWidth = width / event.columns; + final slotWidth = + math.min(width / event.columns, maxWidth ?? double.maxFinite); if (event.event.isNotEmpty) { // TODO(parth): Arrange events and add it in arranged.