From da9cc90fb73017a6d6117515f9ed4083ccd09131 Mon Sep 17 00:00:00 2001 From: Jaimin Rana Date: Tue, 8 Aug 2023 12:44:53 +0530 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9BFixed=20week-view=20&=20day-?= =?UTF-8?q?view=20layout=20issue=20in=20landscape=20mode=20#237.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/lib/pages/create_event_page.dart | 11 +- lib/src/day_view/day_view.dart | 130 ++++++++++----------- lib/src/week_view/week_view.dart | 139 +++++++++++------------ 3 files changed, 141 insertions(+), 139 deletions(-) diff --git a/example/lib/pages/create_event_page.dart b/example/lib/pages/create_event_page.dart index b32b8ae7..6f9acf6c 100644 --- a/example/lib/pages/create_event_page.dart +++ b/example/lib/pages/create_event_page.dart @@ -48,10 +48,13 @@ class _CreateEventPageState extends State { ), ), ), - body: Padding( - padding: EdgeInsets.all(20.0), - child: AddEventWidget( - onEventAdd: context.pop, + body: SingleChildScrollView( + physics: ClampingScrollPhysics(), + child: Padding( + padding: EdgeInsets.all(20.0), + child: AddEventWidget( + onEventAdd: context.pop, + ), ), ), ); diff --git a/lib/src/day_view/day_view.dart b/lib/src/day_view/day_view.dart index b644c821..1e861939 100644 --- a/lib/src/day_view/day_view.dart +++ b/lib/src/day_view/day_view.dart @@ -318,8 +318,6 @@ class DayViewState extends State> { // user adds new events. ..addListener(_reloadCallback); } - - _updateViewDimensions(); } @override @@ -349,8 +347,6 @@ class DayViewState extends State> { // Update heights. _calculateHeights(); - _updateViewDimensions(); - // Update builders and callbacks _assignBuilders(); } @@ -366,68 +362,74 @@ class DayViewState extends State> { Widget build(BuildContext context) { return SafeAreaWrapper( option: widget.safeAreaOption, - child: SizedBox( - width: _width, - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisSize: MainAxisSize.min, - children: [ - _dayTitleBuilder(_currentDate), - Expanded( - child: DecoratedBox( - decoration: BoxDecoration(color: widget.backgroundColor), - child: SizedBox( - height: _height, - child: PageView.builder( - physics: widget.pageViewPhysics, - itemCount: _totalDays, - controller: _pageController, - onPageChanged: _onPageChange, - itemBuilder: (_, index) { - final date = DateTime( - _minDate.year, _minDate.month, _minDate.day + index); - return ValueListenableBuilder( - valueListenable: _scrollConfiguration, - builder: (_, __, ___) => InternalDayViewPage( - key: ValueKey( - _hourHeight.toString() + date.toString()), - width: _width, - liveTimeIndicatorSettings: _liveTimeIndicatorSettings, - timeLineBuilder: _timeLineBuilder, - dayDetectorBuilder: _dayDetectorBuilder, - eventTileBuilder: _eventTileBuilder, - heightPerMinute: widget.heightPerMinute, - hourIndicatorSettings: _hourIndicatorSettings, - date: date, - onTileTap: widget.onEventTap, - onDateLongPress: widget.onDateLongPress, - onDateTap: widget.onDateTap, - showLiveLine: widget.showLiveTimeLineInAllDays || - date.compareWithoutTime(DateTime.now()), - timeLineOffset: widget.timeLineOffset, - timeLineWidth: _timeLineWidth, - verticalLineOffset: widget.verticalLineOffset, - showVerticalLine: widget.showVerticalLine, - height: _height, - controller: controller, - hourHeight: _hourHeight, - eventArranger: _eventArranger, - minuteSlotSize: widget.minuteSlotSize, - scrollNotifier: _scrollConfiguration, - fullDayEventBuilder: _fullDayEventBuilder, - scrollController: _scrollController, - showHalfHours: widget.showHalfHours, - halfHourIndicatorSettings: _halfHourIndicatorSettings, - ), - ); - }, + child: LayoutBuilder(builder: (context, constraint) { + _width = widget.width ?? constraint.maxWidth; + _updateViewDimensions(); + return SizedBox( + width: _width, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + _dayTitleBuilder(_currentDate), + Expanded( + child: DecoratedBox( + decoration: BoxDecoration(color: widget.backgroundColor), + child: SizedBox( + height: _height, + child: PageView.builder( + physics: widget.pageViewPhysics, + itemCount: _totalDays, + controller: _pageController, + onPageChanged: _onPageChange, + itemBuilder: (_, index) { + final date = DateTime(_minDate.year, _minDate.month, + _minDate.day + index); + return ValueListenableBuilder( + valueListenable: _scrollConfiguration, + builder: (_, __, ___) => InternalDayViewPage( + key: ValueKey( + _hourHeight.toString() + date.toString()), + width: _width, + liveTimeIndicatorSettings: + _liveTimeIndicatorSettings, + timeLineBuilder: _timeLineBuilder, + dayDetectorBuilder: _dayDetectorBuilder, + eventTileBuilder: _eventTileBuilder, + heightPerMinute: widget.heightPerMinute, + hourIndicatorSettings: _hourIndicatorSettings, + date: date, + onTileTap: widget.onEventTap, + onDateLongPress: widget.onDateLongPress, + onDateTap: widget.onDateTap, + showLiveLine: widget.showLiveTimeLineInAllDays || + date.compareWithoutTime(DateTime.now()), + timeLineOffset: widget.timeLineOffset, + timeLineWidth: _timeLineWidth, + verticalLineOffset: widget.verticalLineOffset, + showVerticalLine: widget.showVerticalLine, + height: _height, + controller: controller, + hourHeight: _hourHeight, + eventArranger: _eventArranger, + minuteSlotSize: widget.minuteSlotSize, + scrollNotifier: _scrollConfiguration, + fullDayEventBuilder: _fullDayEventBuilder, + scrollController: _scrollController, + showHalfHours: widget.showHalfHours, + halfHourIndicatorSettings: + _halfHourIndicatorSettings, + ), + ); + }, + ), ), ), ), - ), - ], - ), - ), + ], + ), + ); + }), ); } @@ -453,8 +455,6 @@ class DayViewState extends State> { /// Updates data related to size of this view. void _updateViewDimensions() { - _width = widget.width ?? MediaQuery.of(context).size.width; - _timeLineWidth = widget.timeLineWidth ?? _width * 0.13; _liveTimeIndicatorSettings = widget.liveTimeIndicatorSettings ?? diff --git a/lib/src/week_view/week_view.dart b/lib/src/week_view/week_view.dart index 55ea0096..8357e98c 100644 --- a/lib/src/week_view/week_view.dart +++ b/lib/src/week_view/week_view.dart @@ -326,8 +326,6 @@ class WeekViewState extends State> { // user adds new events. ..addListener(_reloadCallback); } - - _updateViewDimensions(); } @override @@ -359,8 +357,6 @@ class WeekViewState extends State> { // Update heights. _calculateHeights(); - _updateViewDimensions(); - // Update builders and callbacks _assignBuilders(); } @@ -376,73 +372,78 @@ class WeekViewState extends State> { Widget build(BuildContext context) { return SafeAreaWrapper( option: widget.safeAreaOption, - child: SizedBox( - width: _width, - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisSize: MainAxisSize.min, - children: [ - _weekHeaderBuilder(_currentStartDate, _currentEndDate), - Expanded( - child: DecoratedBox( - decoration: BoxDecoration(color: widget.backgroundColor), - child: SizedBox( - height: _height, - width: _width, - child: PageView.builder( - itemCount: _totalWeeks, - controller: _pageController, - onPageChanged: _onPageChange, - itemBuilder: (_, index) { - final dates = DateTime(_minDate.year, _minDate.month, - _minDate.day + (index * DateTime.daysPerWeek)) - .datesOfWeek(start: widget.startDay); - - return ValueListenableBuilder( - valueListenable: _scrollConfiguration, - builder: (_, __, ___) => InternalWeekViewPage( - key: ValueKey( - _hourHeight.toString() + dates[0].toString()), - height: _height, - width: _width, - weekTitleWidth: _weekTitleWidth, - weekTitleHeight: widget.weekTitleHeight, - weekDayBuilder: _weekDayBuilder, - weekNumberBuilder: _weekNumberBuilder, - weekDetectorBuilder: _weekDetectorBuilder, - liveTimeIndicatorSettings: _liveTimeIndicatorSettings, - timeLineBuilder: _timeLineBuilder, - onTileTap: widget.onEventTap, - onDateLongPress: widget.onDateLongPress, - onDateTap: widget.onDateTap, - eventTileBuilder: _eventTileBuilder, - heightPerMinute: widget.heightPerMinute, - hourIndicatorSettings: _hourIndicatorSettings, - dates: dates, - showLiveLine: widget.showLiveTimeLineInAllDays || - _showLiveTimeIndicator(dates), - timeLineOffset: widget.timeLineOffset, - timeLineWidth: _timeLineWidth, - verticalLineOffset: 0, - showVerticalLine: true, - controller: controller, - hourHeight: _hourHeight, - scrollController: _scrollController, - eventArranger: _eventArranger, - weekDays: _weekDays, - minuteSlotSize: widget.minuteSlotSize, - scrollConfiguration: _scrollConfiguration, - fullDayEventBuilder: _fullDayEventBuilder, - ), - ); - }, + child: LayoutBuilder(builder: (context, constraint) { + _width = widget.width ?? constraint.maxWidth; + _updateViewDimensions(); + return SizedBox( + width: _width, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + _weekHeaderBuilder(_currentStartDate, _currentEndDate), + Expanded( + child: DecoratedBox( + decoration: BoxDecoration(color: widget.backgroundColor), + child: SizedBox( + height: _height, + width: _width, + child: PageView.builder( + itemCount: _totalWeeks, + controller: _pageController, + onPageChanged: _onPageChange, + itemBuilder: (_, index) { + final dates = DateTime(_minDate.year, _minDate.month, + _minDate.day + (index * DateTime.daysPerWeek)) + .datesOfWeek(start: widget.startDay); + + return ValueListenableBuilder( + valueListenable: _scrollConfiguration, + builder: (_, __, ___) => InternalWeekViewPage( + key: ValueKey( + _hourHeight.toString() + dates[0].toString()), + height: _height, + width: _width, + weekTitleWidth: _weekTitleWidth, + weekTitleHeight: widget.weekTitleHeight, + weekDayBuilder: _weekDayBuilder, + weekNumberBuilder: _weekNumberBuilder, + weekDetectorBuilder: _weekDetectorBuilder, + liveTimeIndicatorSettings: + _liveTimeIndicatorSettings, + timeLineBuilder: _timeLineBuilder, + onTileTap: widget.onEventTap, + onDateLongPress: widget.onDateLongPress, + onDateTap: widget.onDateTap, + eventTileBuilder: _eventTileBuilder, + heightPerMinute: widget.heightPerMinute, + hourIndicatorSettings: _hourIndicatorSettings, + dates: dates, + showLiveLine: widget.showLiveTimeLineInAllDays || + _showLiveTimeIndicator(dates), + timeLineOffset: widget.timeLineOffset, + timeLineWidth: _timeLineWidth, + verticalLineOffset: 0, + showVerticalLine: true, + controller: controller, + hourHeight: _hourHeight, + scrollController: _scrollController, + eventArranger: _eventArranger, + weekDays: _weekDays, + minuteSlotSize: widget.minuteSlotSize, + scrollConfiguration: _scrollConfiguration, + fullDayEventBuilder: _fullDayEventBuilder, + ), + ); + }, + ), ), ), ), - ), - ], - ), - ), + ], + ), + ); + }), ); } @@ -484,8 +485,6 @@ class WeekViewState extends State> { } void _updateViewDimensions() { - _width = widget.width ?? MediaQuery.of(context).size.width; - _timeLineWidth = widget.timeLineWidth ?? _width * 0.13; _liveTimeIndicatorSettings = widget.liveTimeIndicatorSettings ??