Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Provide more configurations for page headers. #408

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
74 changes: 74 additions & 0 deletions docs/migration_guide.md
Original file line number Diff line number Diff line change
@@ -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,
),
),
});
```
1 change: 0 additions & 1 deletion lib/calendar_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
113 changes: 1 addition & 112 deletions lib/src/components/common_components.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions lib/src/components/components.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
35 changes: 0 additions & 35 deletions lib/src/components/day_view_components.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down
Loading
Loading