diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c25b054..b573f981 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,15 @@ - Use `hourLinePainter` in `DayView` [#386](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/386) - Refactor `SideEventArranger` to arrange events properly. [#290](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/290) - Adds generic type in `_InternalWeekViewPageState`. [#380](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/380) +- Adds additional configurations for `HeaderStyle`. + - Added `mainAxisSize`, `mainAxisAlignment`, `rightIconConfig` and `leftIconConfig`. +- Adds additional configurations for `CalendarPageHeader`, `MonthPageHeader`, `DayPageHeader` and `WeekPageHeader`. + - Added `titleBuilder` to build custom title for header. +- `Deprecations`: + - deprecated `backgroundColor` and `iconColor` from `CalendarPageHeader`, `DayPageHeader`, `MonthPageHeader` and `WeekPageHeader`. + - **Solution:** use `headerStyle` instead. + - deprecated `leftIconVisible`, `rightIconVisible`, `leftIconPadding`, `rightIconPadding`, `leftIcon` and `rightIcon` from `HeaderStyle`. + - **Solution:** use `rightIconConfig` and `leftIconConfig` instead. # [1.2.0 - 10 May 2024](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/tree/1.2.0) diff --git a/docs/migration_guide.md b/docs/migration_guide.md new file mode 100644 index 00000000..adcf62e6 --- /dev/null +++ b/docs/migration_guide.md @@ -0,0 +1,74 @@ +# Migration Guide + +## Migrate from `1.x.x` to latest + +1. Migrate `HeaderStyle`. + ```dart + // Old + final style = HeaderStyle( + headerTextStyle : TextStyle(), + headerMargin : EdgeInsets.zero, + headerPadding : EdgeInsets.zero, + titleAlign : TextAlign.center, + decoration : BoxDecoration(), + mainAxisAlignment : MainAxisAlignment.spaceBetween, + leftIcon : Icon(Icons.left), + rightIcon : Icon(Icons.right), + leftIconVisible : true, + rightIconVisible : true, + leftIconPadding : EdgeInsets.zero, + rightIconPadding : EdgeInsets.zero, + ); + ``` + ```dart + // After Migration + + // NOTE: leftIconVisible and rightIconVisible is removed in + // latest version. set leftIconConfig and rightIconConfig null to + // hide the respective icon. + final style = HeaderStyle( + headerTextStyle : TextStyle(), + headerMargin : EdgeInsets.zero, + headerPadding : EdgeInsets.zero, + titleAlign : TextAlign.center, + decoration : BoxDecoration(), + mainAxisAlignment : MainAxisAlignment.spaceBetween, + + // Set this null to hide the left icon. + leftIconConfig : IconDataConfig( + padding: EdgeInsets.zero, + icon: Icon(Icons.left), + ), + + // Set this null to hide the right icon. + rightIconConfig : IconDataConfig( + padding: EdgeInsets.zero, + icon: Icon(Icons.right), + ), + ); + ``` +2. Migrate `CalendarPageHeader` | `DayPageHeader` | `MonthPageHeader` | `WeekPageHeader`: + ```dart + // Old + final header = MonthPageBuilder({ + date = DateTime.now(), + dateStringBuilder = (date, {secondaryDate}) => '$date', + backgroundColor = Constants.headerBackground, + iconColor = Constants.black, + }); + ``` + ```dart + // After Migration + final header = MonthPageBuilder({ + date = DateTime.now(), + dateStringBuilder = (date, {secondaryDate}) => '$date', + headerStyle = HeaderStyle.withSameIcons( + decoration: BoxDecoration( + color: Constants.headerBackground, + ), + iconConfig: IconDataConfig( + color: Constants.black, + ), + ), + }); + ``` \ No newline at end of file diff --git a/lib/calendar_view.dart b/lib/calendar_view.dart index 619955b0..80e038ea 100644 --- a/lib/calendar_view.dart +++ b/lib/calendar_view.dart @@ -8,7 +8,6 @@ export './src/calendar_constants.dart'; export './src/calendar_controller_provider.dart'; export './src/calendar_event_data.dart'; export './src/components/components.dart'; -export './src/components/safe_area_wrapper.dart'; export './src/day_view/day_view.dart'; export './src/enumerations.dart'; export './src/event_arrangers/event_arrangers.dart'; diff --git a/lib/src/components/common_components.dart b/lib/src/components/common_components.dart index 227fc001..cf2f7f29 100644 --- a/lib/src/components/common_components.dart +++ b/lib/src/components/common_components.dart @@ -2,126 +2,15 @@ // Use of this source code is governed by a MIT-style license // that can be found in the LICENSE file. -import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import '../calendar_event_data.dart'; import '../constants.dart'; +import '../enumerations.dart'; import '../extensions.dart'; -import '../style/header_style.dart'; import '../typedefs.dart'; -import '../enumerations.dart'; import 'components.dart'; -class CalendarPageHeader extends StatelessWidget { - /// When user taps on right arrow. - final VoidCallback? onNextDay; - - /// When user taps on left arrow. - final VoidCallback? onPreviousDay; - - /// When user taps on title. - final AsyncCallback? onTitleTapped; - - /// Date of month/day. - final DateTime date; - - /// Secondary date. This date will be used when we need to define a - /// range of dates. - /// [date] can be starting date and [secondaryDate] can be end date. - final DateTime? secondaryDate; - - /// Provides string to display as title. - final StringProvider dateStringBuilder; - - // TODO: Need to remove after next release - /// background color of header. - @Deprecated("Use Header Style to provide background") - final Color backgroundColor; - - // TODO: Need to remove after next release - /// Color of icons at both sides of header. - @Deprecated("Use Header Style to provide icon color") - final Color iconColor; - - /// Style for Calendar's header - final HeaderStyle headerStyle; - - /// Common header for month and day view In this header user can define format - /// in which date will be displayed by providing [dateStringBuilder] function. - const CalendarPageHeader({ - Key? key, - required this.date, - required this.dateStringBuilder, - this.onNextDay, - this.onTitleTapped, - this.onPreviousDay, - this.secondaryDate, - @Deprecated("Use Header Style to provide background") - this.backgroundColor = Constants.headerBackground, - @Deprecated("Use Header Style to provide icon color") - this.iconColor = Constants.black, - this.headerStyle = const HeaderStyle(), - }) : super(key: key); - - @override - Widget build(BuildContext context) { - return Container( - margin: headerStyle.headerMargin, - padding: headerStyle.headerPadding, - decoration: - // ignore_for_file: deprecated_member_use_from_same_package - headerStyle.decoration ?? BoxDecoration(color: backgroundColor), - clipBehavior: Clip.antiAlias, - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - if (headerStyle.leftIconVisible) - IconButton( - onPressed: onPreviousDay, - splashColor: Colors.transparent, - focusColor: Colors.transparent, - hoverColor: Colors.transparent, - highlightColor: Colors.transparent, - padding: headerStyle.leftIconPadding, - icon: headerStyle.leftIcon ?? - Icon( - Icons.chevron_left, - size: 30, - color: iconColor, - ), - ), - Expanded( - child: InkWell( - onTap: onTitleTapped, - child: Text( - dateStringBuilder(date, secondaryDate: secondaryDate), - textAlign: headerStyle.titleAlign, - style: headerStyle.headerTextStyle, - ), - ), - ), - if (headerStyle.rightIconVisible) - IconButton( - onPressed: onNextDay, - splashColor: Colors.transparent, - focusColor: Colors.transparent, - hoverColor: Colors.transparent, - highlightColor: Colors.transparent, - padding: headerStyle.rightIconPadding, - icon: headerStyle.rightIcon ?? - Icon( - Icons.chevron_right, - size: 30, - color: iconColor, - ), - ), - ], - ), - ); - } -} - /// This will be used in day and week view class DefaultPressDetector extends StatelessWidget { /// default press detector builder used in week and day view diff --git a/lib/src/components/components.dart b/lib/src/components/components.dart index 546364fe..374bcd5d 100644 --- a/lib/src/components/components.dart +++ b/lib/src/components/components.dart @@ -2,6 +2,13 @@ // Use of this source code is governed by a MIT-style license // that can be found in the LICENSE file. +export 'common_components.dart'; export 'day_view_components.dart'; +export 'event_scroll_notifier.dart'; +export 'headers/calendar_page_header.dart'; +export 'headers/day_page_header.dart'; +export 'headers/month_page_header.dart'; +export 'headers/week_page_header.dart'; export 'month_view_components.dart'; +export 'safe_area_wrapper.dart'; export 'week_view_components.dart'; diff --git a/lib/src/components/day_view_components.dart b/lib/src/components/day_view_components.dart index 745a19b1..b8e28e9e 100644 --- a/lib/src/components/day_view_components.dart +++ b/lib/src/components/day_view_components.dart @@ -2,15 +2,11 @@ // Use of this source code is governed by a MIT-style license // that can be found in the LICENSE file. -import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import '../calendar_event_data.dart'; -import '../constants.dart'; import '../extensions.dart'; -import '../style/header_style.dart'; import '../typedefs.dart'; -import 'common_components.dart'; /// This class defines default tile to display in day view. class RoundedEventTile extends StatelessWidget { @@ -114,37 +110,6 @@ class RoundedEventTile extends StatelessWidget { } } -/// A header widget to display on day view. -class DayPageHeader extends CalendarPageHeader { - /// A header widget to display on day view. - const DayPageHeader({ - Key? key, - VoidCallback? onNextDay, - AsyncCallback? onTitleTapped, - VoidCallback? onPreviousDay, - Color iconColor = Constants.black, - Color backgroundColor = Constants.headerBackground, - StringProvider? dateStringBuilder, - required DateTime date, - HeaderStyle headerStyle = const HeaderStyle(), - }) : super( - key: key, - date: date, - // ignore_for_file: deprecated_member_use_from_same_package - backgroundColor: backgroundColor, - iconColor: iconColor, - onNextDay: onNextDay, - onPreviousDay: onPreviousDay, - onTitleTapped: onTitleTapped, - dateStringBuilder: - dateStringBuilder ?? DayPageHeader._dayStringBuilder, - headerStyle: headerStyle, - ); - - static String _dayStringBuilder(DateTime date, {DateTime? secondaryDate}) => - "${date.day} - ${date.month} - ${date.year}"; -} - class DefaultTimeLineMark extends StatelessWidget { /// Defines time to display final DateTime date; diff --git a/lib/src/components/headers/calendar_page_header.dart b/lib/src/components/headers/calendar_page_header.dart new file mode 100644 index 00000000..21086ea8 --- /dev/null +++ b/lib/src/components/headers/calendar_page_header.dart @@ -0,0 +1,164 @@ +// Copyright (c) 2021 Simform Solutions. All rights reserved. +// Use of this source code is governed by a MIT-style license +// that can be found in the LICENSE file. + +// ignore_for_file: deprecated_member_use_from_same_package + +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; + +import '../../constants.dart'; +import '../../style/header_style.dart'; +import '../../typedefs.dart'; + +class CalendarPageHeader extends StatelessWidget { + /// When user taps on right arrow. + /// + /// This will be ignored if right icon is provided in [headerStyle]. + final VoidCallback? onNextDay; + + /// When user taps on left arrow. + /// + /// This will be ignored if left icon is provided in [headerStyle]. + final VoidCallback? onPreviousDay; + + /// When user taps on title. + /// + /// This will be ignored if [titleBuilder] is provided. + final AsyncCallback? onTitleTapped; + + /// Date of month/day. + final DateTime date; + + /// Secondary date. This date will be used when we need to define a + /// range of dates. + /// [date] can be starting date and [secondaryDate] can be end date. + /// + final DateTime? secondaryDate; + + /// Provides string to display as title. + final StringProvider? dateStringBuilder; + + /// Builds the custom header title. + /// + /// This is useful when we need to add icon or something with the title. + /// + /// If [titleBuilder] is provided, [onTitleTapped] will be ignored. + /// + /// So, you need to handle the tap event manually if required. + /// + final WidgetBuilder? titleBuilder; + + // TODO: Need to remove after next major release + /// background color of header. + /// + /// NOTE: This property is deprecated. + /// Use [HeaderStyle.decoration] to provide colors to header. + @Deprecated("Use HeaderStyle.decoration to provide background") + final Color backgroundColor; + + // TODO: Need to remove after next major release + /// Color of icons at both sides of header. + /// + /// NOTE: This property id deprecated. Use + /// [HeaderStyle.leftIconConfig] or [HeaderStyle.rightIconConfig] + /// to provide style to respective icons. + /// + @Deprecated("Use HeaderStyle to provide icon color") + final Color? iconColor; + + /// Style for Calendar's header + final HeaderStyle headerStyle; + + /// Common header for month and day view In this header user can define format + /// in which date will be displayed by providing [dateStringBuilder] function. + const CalendarPageHeader({ + Key? key, + required this.date, + this.dateStringBuilder, + this.titleBuilder, + this.onNextDay, + this.onTitleTapped, + this.onPreviousDay, + this.secondaryDate, + @Deprecated("Use HeaderStyle.decoration to provide background") + this.backgroundColor = Constants.headerBackground, + @Deprecated("Use HeaderStyle to provide icon color") + this.iconColor = Constants.black, + this.headerStyle = const HeaderStyle(), + }) : assert( + titleBuilder != null || dateStringBuilder != null, + 'titleBuilder and dateStringBuilder ' + 'can not be null at the same time'), + super(key: key); + + @override + Widget build(BuildContext context) { + return Container( + margin: headerStyle.headerMargin, + padding: headerStyle.headerPadding, + decoration: + headerStyle.decoration ?? BoxDecoration(color: backgroundColor), + clipBehavior: Clip.antiAlias, + child: Row( + mainAxisSize: headerStyle.mainAxisSize, + mainAxisAlignment: headerStyle.mainAxisAlignment, + children: [ + if (headerStyle.leftIconVisible && headerStyle.leftIconConfig != null) + headerStyle.leftIconConfig!.icon?.call(context) ?? + IconButton( + onPressed: onPreviousDay, + splashColor: Colors.transparent, + focusColor: Colors.transparent, + hoverColor: Colors.transparent, + highlightColor: Colors.transparent, + padding: headerStyle.leftIconPadding ?? + headerStyle.leftIconConfig!.padding, + icon: headerStyle.leftIcon ?? + Icon( + Icons.chevron_left, + size: headerStyle.leftIconConfig!.size, + color: iconColor ?? headerStyle.leftIconConfig!.color, + ), + ), + Expanded( + child: titleBuilder != null + ? DefaultTextStyle.merge( + style: headerStyle.headerTextStyle, + textAlign: headerStyle.titleAlign, + child: titleBuilder!(context), + ) + : InkWell( + onTap: onTitleTapped, + child: DefaultTextStyle.merge( + child: Text( + dateStringBuilder?.call(date, + secondaryDate: secondaryDate) ?? + '', + textAlign: headerStyle.titleAlign, + style: headerStyle.headerTextStyle, + ), + ), + ), + ), + if (headerStyle.rightIconVisible && + headerStyle.rightIconConfig != null) + IconButton( + onPressed: onNextDay, + splashColor: Colors.transparent, + focusColor: Colors.transparent, + hoverColor: Colors.transparent, + highlightColor: Colors.transparent, + padding: headerStyle.rightIconPadding, + icon: headerStyle.rightIcon ?? + Icon( + Icons.chevron_right, + size: headerStyle.rightIconConfig?.size, + color: iconColor ?? headerStyle.rightIconConfig?.color, + ), + ), + ], + ), + ); + } +} diff --git a/lib/src/components/headers/day_page_header.dart b/lib/src/components/headers/day_page_header.dart new file mode 100644 index 00000000..420906ef --- /dev/null +++ b/lib/src/components/headers/day_page_header.dart @@ -0,0 +1,44 @@ +// Copyright (c) 2021 Simform Solutions. All rights reserved. +// Use of this source code is governed by a MIT-style license +// that can be found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; + +import '../../constants.dart'; +import '../../style/header_style.dart'; +import '../../typedefs.dart'; +import 'calendar_page_header.dart'; + +/// A header widget to display on day view. +class DayPageHeader extends CalendarPageHeader { + /// A header widget to display on day view. + const DayPageHeader({ + Key? key, + VoidCallback? onNextDay, + AsyncCallback? onTitleTapped, + VoidCallback? onPreviousDay, + StringProvider? dateStringBuilder, + required DateTime date, + @Deprecated("Use HeaderStyle to provide icon color") + Color iconColor = Constants.black, + @Deprecated("Use HeaderStyle to provide background") + Color backgroundColor = Constants.headerBackground, + HeaderStyle headerStyle = const HeaderStyle(), + }) : super( + key: key, + date: date, + // ignore_for_file: deprecated_member_use_from_same_package + backgroundColor: backgroundColor, + iconColor: iconColor, + onNextDay: onNextDay, + onPreviousDay: onPreviousDay, + onTitleTapped: onTitleTapped, + dateStringBuilder: + dateStringBuilder ?? DayPageHeader._dayStringBuilder, + headerStyle: headerStyle, + ); + + static String _dayStringBuilder(DateTime date, {DateTime? secondaryDate}) => + "${date.day} - ${date.month} - ${date.year}"; +} diff --git a/lib/src/components/headers/month_page_header.dart b/lib/src/components/headers/month_page_header.dart new file mode 100644 index 00000000..f514f55d --- /dev/null +++ b/lib/src/components/headers/month_page_header.dart @@ -0,0 +1,43 @@ +// Copyright (c) 2021 Simform Solutions. All rights reserved. +// Use of this source code is governed by a MIT-style license +// that can be found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; + +import '../../constants.dart'; +import '../../style/header_style.dart'; +import '../../typedefs.dart'; +import 'calendar_page_header.dart'; + +class MonthPageHeader extends CalendarPageHeader { + /// A header widget to display on month view. + const MonthPageHeader({ + Key? key, + VoidCallback? onNextMonth, + AsyncCallback? onTitleTapped, + VoidCallback? onPreviousMonth, + @Deprecated("Use HeaderStyle to provide icon color") + Color iconColor = Constants.black, + @Deprecated("Use HeaderStyle to provide background color") + Color backgroundColor = Constants.headerBackground, + StringProvider? dateStringBuilder, + required DateTime date, + HeaderStyle headerStyle = const HeaderStyle(), + }) : super( + key: key, + date: date, + onNextDay: onNextMonth, + onPreviousDay: onPreviousMonth, + onTitleTapped: onTitleTapped, + // ignore_for_file: deprecated_member_use_from_same_package + backgroundColor: backgroundColor, + iconColor: iconColor, + dateStringBuilder: + dateStringBuilder ?? MonthPageHeader._monthStringBuilder, + headerStyle: headerStyle, + ); + + static String _monthStringBuilder(DateTime date, {DateTime? secondaryDate}) => + "${date.month} - ${date.year}"; +} diff --git a/lib/src/components/headers/week_page_header.dart b/lib/src/components/headers/week_page_header.dart new file mode 100644 index 00000000..c7efaa3e --- /dev/null +++ b/lib/src/components/headers/week_page_header.dart @@ -0,0 +1,47 @@ +// Copyright (c) 2021 Simform Solutions. All rights reserved. +// Use of this source code is governed by a MIT-style license +// that can be found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; + +import '../../constants.dart'; +import '../../style/header_style.dart'; +import '../../typedefs.dart'; +import 'calendar_page_header.dart'; + +class WeekPageHeader extends CalendarPageHeader { + /// A header widget to display on week view. + const WeekPageHeader({ + Key? key, + VoidCallback? onNextDay, + AsyncCallback? onTitleTapped, + VoidCallback? onPreviousDay, + required DateTime startDate, + required DateTime endDate, + @Deprecated("Use HeaderStyle to provide icon color") + Color iconColor = Constants.black, + @Deprecated("Use HeaderStyle to provide background color") + Color backgroundColor = Constants.headerBackground, + StringProvider? headerStringBuilder, + HeaderStyle headerStyle = const HeaderStyle(), + }) : super( + key: key, + date: startDate, + secondaryDate: endDate, + onNextDay: onNextDay, + onPreviousDay: onPreviousDay, + onTitleTapped: onTitleTapped, + // ignore_for_file: deprecated_member_use_from_same_package + iconColor: iconColor, + backgroundColor: backgroundColor, + dateStringBuilder: + headerStringBuilder ?? WeekPageHeader._weekStringBuilder, + headerStyle: headerStyle, + ); + + static String _weekStringBuilder(DateTime date, {DateTime? secondaryDate}) => + "${date.day} / ${date.month} / ${date.year} to " + "${secondaryDate != null ? "${secondaryDate.day} / " + "${secondaryDate.month} / ${secondaryDate.year}" : ""}"; +} diff --git a/lib/src/components/month_view_components.dart b/lib/src/components/month_view_components.dart index f64c0016..c09d6e12 100644 --- a/lib/src/components/month_view_components.dart +++ b/lib/src/components/month_view_components.dart @@ -2,15 +2,12 @@ // Use of this source code is governed by a MIT-style license // that can be found in the LICENSE file. -import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import '../calendar_event_data.dart'; import '../constants.dart'; import '../extensions.dart'; -import '../style/header_style.dart'; import '../typedefs.dart'; -import 'common_components.dart'; class CircularCell extends StatelessWidget { /// Date of cell. @@ -210,36 +207,6 @@ class FilledCell extends StatelessWidget { } } -class MonthPageHeader extends CalendarPageHeader { - /// A header widget to display on month view. - const MonthPageHeader({ - Key? key, - VoidCallback? onNextMonth, - AsyncCallback? onTitleTapped, - VoidCallback? onPreviousMonth, - Color iconColor = Constants.black, - Color backgroundColor = Constants.headerBackground, - StringProvider? dateStringBuilder, - required DateTime date, - HeaderStyle headerStyle = const HeaderStyle(), - }) : super( - key: key, - date: date, - onNextDay: onNextMonth, - onPreviousDay: onPreviousMonth, - onTitleTapped: onTitleTapped, - // ignore_for_file: deprecated_member_use_from_same_package - backgroundColor: backgroundColor, - iconColor: iconColor, - dateStringBuilder: - dateStringBuilder ?? MonthPageHeader._monthStringBuilder, - headerStyle: headerStyle, - ); - - static String _monthStringBuilder(DateTime date, {DateTime? secondaryDate}) => - "${date.month} - ${date.year}"; -} - class WeekDayTile extends StatelessWidget { /// Index of week day. final int dayIndex; diff --git a/lib/src/components/week_view_components.dart b/lib/src/components/week_view_components.dart index 77e1ff70..609c47c7 100644 --- a/lib/src/components/week_view_components.dart +++ b/lib/src/components/week_view_components.dart @@ -2,48 +2,8 @@ // Use of this source code is governed by a MIT-style license // that can be found in the LICENSE file. -import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; -import '../constants.dart'; -import '../style/header_style.dart'; -import '../typedefs.dart'; -import 'common_components.dart'; - -class WeekPageHeader extends CalendarPageHeader { - /// A header widget to display on week view. - const WeekPageHeader({ - Key? key, - VoidCallback? onNextDay, - AsyncCallback? onTitleTapped, - VoidCallback? onPreviousDay, - required DateTime startDate, - required DateTime endDate, - Color iconColor = Constants.black, - Color backgroundColor = Constants.headerBackground, - StringProvider? headerStringBuilder, - HeaderStyle headerStyle = const HeaderStyle(), - }) : super( - key: key, - date: startDate, - secondaryDate: endDate, - onNextDay: onNextDay, - onPreviousDay: onPreviousDay, - onTitleTapped: onTitleTapped, - // ignore_for_file: deprecated_member_use_from_same_package - iconColor: iconColor, - backgroundColor: backgroundColor, - dateStringBuilder: - headerStringBuilder ?? WeekPageHeader._weekStringBuilder, - headerStyle: headerStyle, - ); - - static String _weekStringBuilder(DateTime date, {DateTime? secondaryDate}) => - "${date.day} / ${date.month} / ${date.year} to " - "${secondaryDate != null ? "${secondaryDate.day} / " - "${secondaryDate.month} / ${secondaryDate.year}" : ""}"; -} - class FullDayHeaderTextConfig { /// Set full day events header text config const FullDayHeaderTextConfig({ diff --git a/lib/src/day_view/day_view.dart b/lib/src/day_view/day_view.dart index 163b8937..71b041bf 100644 --- a/lib/src/day_view/day_view.dart +++ b/lib/src/day_view/day_view.dart @@ -6,22 +6,9 @@ import 'dart:async'; import 'package:flutter/material.dart'; -import '../calendar_constants.dart'; -import '../calendar_controller_provider.dart'; -import '../calendar_event_data.dart'; -import '../components/common_components.dart'; -import '../components/day_view_components.dart'; -import '../components/event_scroll_notifier.dart'; -import '../components/safe_area_wrapper.dart'; +import '../../calendar_view.dart'; import '../constants.dart'; -import '../enumerations.dart'; -import '../event_arrangers/event_arrangers.dart'; -import '../event_controller.dart'; -import '../extensions.dart'; -import '../modals.dart'; import '../painters.dart'; -import '../style/header_style.dart'; -import '../typedefs.dart'; import '_internal_day_view_page.dart'; class DayView extends StatefulWidget { @@ -45,6 +32,13 @@ class DayView extends StatefulWidget { final DateWidgetBuilder? timeLineBuilder; /// Builds day title bar. + /// + /// If there are some configurations that is not directly available + /// in [DayView], override this to create your custom header or reuse, + /// [CalendarPageHeader] | [DayPageHeader] | [MonthPageHeader] | + /// [WeekPageHeader] widgets provided by this package with your custom + /// configurations. + /// final DateWidgetBuilder? dayTitleBuilder; /// Builds custom PressDetector widget diff --git a/lib/src/month_view/month_view.dart b/lib/src/month_view/month_view.dart index 236fb73e..51690910 100644 --- a/lib/src/month_view/month_view.dart +++ b/lib/src/month_view/month_view.dart @@ -8,7 +8,6 @@ import '../calendar_constants.dart'; import '../calendar_controller_provider.dart'; import '../calendar_event_data.dart'; import '../components/components.dart'; -import '../components/safe_area_wrapper.dart'; import '../constants.dart'; import '../enumerations.dart'; import '../event_controller.dart'; @@ -23,7 +22,12 @@ class MonthView extends StatefulWidget { /// Builds month page title. /// - /// Used default title builder if null. + /// If there are some configurations that is not directly available + /// in [MonthView], override this to create your custom header or reuse, + /// [CalendarPageHeader] | [DayPageHeader] | [MonthPageHeader] | + /// [WeekPageHeader] widgets provided by this package with your custom + /// configurations. + /// final DateWidgetBuilder? headerBuilder; /// This function will generate DateString in the calendar header. diff --git a/lib/src/style/header_style.dart b/lib/src/style/header_style.dart index c8929ee8..b7728ff3 100644 --- a/lib/src/style/header_style.dart +++ b/lib/src/style/header_style.dart @@ -5,20 +5,15 @@ class HeaderStyle { /// Provide text style for calendar's header. final TextStyle? headerTextStyle; - /// Widget used for left icon. - /// - /// Tapping on it will navigate to previous calendar page. - final Widget? leftIcon; - - /// Widget used for right icon. - /// - /// Tapping on it will navigate to next calendar page. - final Widget? rightIcon; - /// Determines left icon visibility. + + @Deprecated( + 'This flag is deprecated and will be removed in next major version. Instead of this pass null in leftIconConfig to hide the icon.') final bool leftIconVisible; /// Determines right icon visibility. + @Deprecated( + 'This flag is deprecated and will be removed in next major version. Instead of this pass null in rightIconConfig to hide the icon.') final bool rightIconVisible; /// Internal padding of the whole header. @@ -28,10 +23,15 @@ class HeaderStyle { final EdgeInsets headerMargin; /// Internal padding of left icon. - final EdgeInsets leftIconPadding; + + @Deprecated( + 'This is deprecated and will be removed in next major version. Use rightIconConfig to add the padding to default icon.') + final EdgeInsets? leftIconPadding; /// Internal padding of right icon. - final EdgeInsets rightIconPadding; + @Deprecated( + 'This is deprecated and will be removed in next major version. Use leftIconConfig to add the padding to default icon.') + final EdgeInsets? rightIconPadding; /// Define Alignment of header text. final TextAlign titleAlign; @@ -39,18 +39,134 @@ class HeaderStyle { /// Decoration of whole header. final BoxDecoration? decoration; + /// Defines the alignment between components of header. + final MainAxisAlignment mainAxisAlignment; + + /// Defines how the header should expand horizontally. + /// + /// [MainAxisSize.min] -> Shrinks header to the size of it's children. + /// [MainAxisSize.max] -> Expands header to available horizontal space. + /// + /// Defaults to [MainAxisSize.max] + final MainAxisSize mainAxisSize; + + /// Widget used for left icon. + /// + @Deprecated( + 'This is deprecated and will be removed in next major version. Use leftIconConfig to add custom icon') + final Widget? leftIcon; + + /// Widget used for right icon. + /// + @Deprecated( + 'This is deprecated and will be removed in next major version. Use leftIconConfig to add custom icon') + final Widget? rightIcon; + + /// Provides icon style for default left Icon. + /// + final IconDataConfig? leftIconConfig; + + /// Provides icon style for default right Icon. + /// + final IconDataConfig? rightIconConfig; + /// Create a `HeaderStyle` of calendar view const HeaderStyle({ this.headerTextStyle, + this.headerMargin = EdgeInsets.zero, + this.headerPadding = EdgeInsets.zero, + this.titleAlign = TextAlign.center, + this.decoration, + this.mainAxisAlignment = MainAxisAlignment.spaceBetween, + this.leftIconConfig = const IconDataConfig(), + this.rightIconConfig = const IconDataConfig(), + this.mainAxisSize = MainAxisSize.max, + @Deprecated( + 'This is deprecated and will be removed in next major version. Use leftIconConfig to add custom icon') this.leftIcon, + @Deprecated( + 'This is deprecated and will be removed in next major version. Use leftIconConfig to add custom icon') this.rightIcon, + @Deprecated( + 'This flag is deprecated and will be removed in next major version. Instead of this pass null in leftIconConfig to hide the icon.') this.leftIconVisible = true, + @Deprecated( + 'This flag is deprecated and will be removed in next major version. Instead of this pass null in rightIconConfig to hide the icon.') this.rightIconVisible = true, + @Deprecated( + 'This is deprecated and will be removed in next major version. Use rightIconConfig to add the padding to default icon.') + this.leftIconPadding, + @Deprecated( + 'This is deprecated and will be removed in next major version. Use leftIconConfig to add the padding to default icon.') + this.rightIconPadding, + }); + + /// Create a `HeaderStyle` of calendar view + /// + /// Used when you need to use same configs for left and right icons. + const HeaderStyle.withSameIcons({ + this.headerTextStyle, this.headerMargin = EdgeInsets.zero, this.headerPadding = EdgeInsets.zero, - this.leftIconPadding = const EdgeInsets.all(10), - this.rightIconPadding = const EdgeInsets.all(10), this.titleAlign = TextAlign.center, this.decoration, + this.mainAxisAlignment = MainAxisAlignment.spaceBetween, + IconDataConfig iconConfig = const IconDataConfig(), + this.mainAxisSize = MainAxisSize.max, + @Deprecated( + 'This is deprecated and will be removed in next major version. Use leftIconConfig to add custom icon') + this.leftIcon, + @Deprecated( + 'This is deprecated and will be removed in next major version. Use leftIconConfig to add custom icon') + this.rightIcon, + @Deprecated( + 'This flag is deprecated and will be removed in next major version. Instead of this pass null in leftIconConfig to hide the icon.') + this.leftIconVisible = true, + @Deprecated( + 'This flag is deprecated and will be removed in next major version. Instead of this pass null in rightIconConfig to hide the icon.') + this.rightIconVisible = true, + @Deprecated( + 'This is deprecated and will be removed in next major version. Use rightIconConfig to add the padding to default icon.') + this.leftIconPadding, + @Deprecated( + 'This is deprecated and will be removed in next major version. Use leftIconConfig to add the padding to default icon.') + this.rightIconPadding, + }) : leftIconConfig = iconConfig, + rightIconConfig = iconConfig; +} + +/// Defines the data for icons used in calendar_view. +class IconDataConfig { + /// Color of the default Icon. + final Color color; + + /// Size of the default Icon. + final double size; + + /// Padding for default icon. + final EdgeInsets padding; + + // NOTE(parth): We are using builder here. Because in future we are planning + // To add an `of` static method for CalendarViews. + // If user is providing this custom icon, developers can call, + // for ex, MonthView.of(context) using context provided by WidgetBuilder to + // access the nearest ancestor and call methods exposed by + // MonthViewState. + // + /// Custom icon widget. Keep this null to use default icon if + /// it's set by package. + /// + /// If this icon is passed, it will remove the tap on default icon if set. + /// + /// You can still manually implement the functionality provided by default + /// Icon. + final WidgetBuilder? icon; + + /// Defines the data for icons used in calendar_view. + const IconDataConfig({ + this.color = Colors.black, + this.size = 30, + this.padding = const EdgeInsets.all(10), + this.icon, }); } diff --git a/lib/src/week_view/week_view.dart b/lib/src/week_view/week_view.dart index dd61214c..38a524b1 100644 --- a/lib/src/week_view/week_view.dart +++ b/lib/src/week_view/week_view.dart @@ -7,10 +7,7 @@ import 'package:flutter/material.dart'; import '../calendar_constants.dart'; import '../calendar_controller_provider.dart'; import '../calendar_event_data.dart'; -import '../components/common_components.dart'; import '../components/components.dart'; -import '../components/event_scroll_notifier.dart'; -import '../components/safe_area_wrapper.dart'; import '../constants.dart'; import '../enumerations.dart'; import '../event_arrangers/event_arrangers.dart'; @@ -31,6 +28,13 @@ class WeekView extends StatefulWidget { final DateWidgetBuilder? timeLineBuilder; /// Header builder for week page header. + /// + /// If there are some configurations that is not directly available + /// in [WeekView], override this to create your custom header or reuse, + /// [CalendarPageHeader] | [DayPageHeader] | [MonthPageHeader] | + /// [WeekPageHeader] widgets provided by this package with your custom + /// configurations. + /// final WeekPageHeaderBuilder? weekPageHeaderBuilder; /// Builds custom PressDetector widget