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

Add support weekend day styles #102

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
13 changes: 13 additions & 0 deletions example/ios/Flutter/flutter_export_environment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh
# This is a generated file; do not edit or check into version control.
export "FLUTTER_ROOT=/Users/apple/SDK/flutter"
export "FLUTTER_APPLICATION_PATH=/Volumes/HDD_MAC/PRO/flutter_date_pickers/example"
export "COCOAPODS_PARALLEL_CODE_SIGN=true"
export "FLUTTER_TARGET=lib/main.dart"
export "FLUTTER_BUILD_DIR=build"
export "FLUTTER_BUILD_NAME=1.0.0"
export "FLUTTER_BUILD_NUMBER=1"
export "DART_OBFUSCATION=false"
export "TRACK_WIDGET_CREATION=false"
export "TREE_SHAKE_ICONS=false"
export "PACKAGE_CONFIG=.dart_tool/package_config.json"
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.3.0"
version: "0.4.0"
flutter_localizations:
dependency: "direct main"
description: flutter
Expand Down
6 changes: 5 additions & 1 deletion lib/src/basic_day_based_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,11 @@ class _DayCell extends StatelessWidget {
} else if (DatePickerUtils.sameDate(currentDate, day)) {
itemStyle = datePickerStyles.currentDateStyle;
} else {
itemStyle = datePickerStyles.defaultDateTextStyle;
if (day.weekday == 6 || day.weekday == 7) {
itemStyle = datePickerStyles.weekendDateStyle;
} else {
itemStyle = datePickerStyles.defaultDateTextStyle;
}
}

// Merges decoration and textStyle with [EventDecoration].
Expand Down
11 changes: 10 additions & 1 deletion lib/src/day_based_changable_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ class _DayBasedChangeablePickerState<T>
onNextMonthTapped:
state.isLastMonth ? null : _presenter.gotoNextMonth,
title: Text(
state.curMonthDis,
state.curMonthDis.capitalize(),
key: widget.datePickerKeys?.selectedPeriodKeys,
style: _resultStyles.displayedPeriodTitle,
),
Expand Down Expand Up @@ -377,3 +377,12 @@ DateTime _getInitiallyShownDate(
/// non-nullable can still be used with `!` and `?`
/// to support older versions of the API as well.
T? _ambiguate<T>(T? value) => value;


// ignore: public_member_api_docs
extension StringExtension on String {
// ignore: prefer_expression_function_bodies, public_member_api_docs
String capitalize() {
return "${this[0].toUpperCase()}${substring(1).toLowerCase()}";
}
}
4 changes: 3 additions & 1 deletion lib/src/i_selectable_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ abstract class ISelectablePicker<T> {
/// If [_selectableDayPredicate] is set checks it as well.
@protected
bool isDisabled(DateTime day) =>
day.isAfter(lastDate) || day.isBefore(firstDate) || !_selectableDayPredicate(day);
day.isAfter(lastDate) ||
day.isBefore(firstDate) ||
!_selectableDayPredicate(day);

/// Closes [onUpdateController].
/// After it [onUpdateController] can't get new events.
Expand Down
1 change: 0 additions & 1 deletion lib/src/range_picker.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';

import 'date_period.dart';
import 'date_picker_keys.dart';
Expand Down
14 changes: 13 additions & 1 deletion lib/src/styles/date_picker_styles.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class DatePickerStyles {
/// Style for the numbers of disabled dates.
final TextStyle? disabledDateStyle;

/// Style for weekend date.
final TextStyle? weekendDateStyle;

/// Style for the number of selected date.
final TextStyle? selectedDateStyle;

Expand Down Expand Up @@ -73,6 +76,7 @@ class DatePickerStyles {
{this.displayedPeriodTitle,
this.currentDateStyle,
this.disabledDateStyle,
this.weekendDateStyle,
this.selectedDateStyle,
this.selectedSingleDateDecoration,
this.defaultDateTextStyle,
Expand Down Expand Up @@ -106,6 +110,8 @@ class DatePickerStyles {
theme.textTheme.bodyText1?.copyWith(color: theme.colorScheme.secondary);
TextStyle? _disabledDateStyle = disabledDateStyle ??
theme.textTheme.bodyText2?.copyWith(color: theme.disabledColor);
TextStyle? _weekendDateStyle = weekendDateStyle ??
theme.textTheme.bodyText2?.copyWith(color: theme.disabledColor);
TextStyle? _selectedDateStyle = selectedDateStyle ??
theme.textTheme.bodyText1?.copyWith(
color: theme.colorScheme.onSecondary,
Expand All @@ -125,6 +131,7 @@ class DatePickerStyles {
}

return DatePickerStyles(
weekendDateStyle: _weekendDateStyle,
disabledDateStyle: _disabledDateStyle,
currentDateStyle: _currentDateStyle,
displayedPeriodTitle: _displayedPeriodTitle,
Expand Down Expand Up @@ -282,13 +289,15 @@ class DatePickerRangeStyles extends DatePickerStyles {
selectedPeriodStartTextStyle: _selectedPeriodStartTextStyle,
selectedPeriodMiddleTextStyle: _selectedPeriodMiddleTextStyle,
selectedPeriodEndTextStyle: _selectedPeriodEndTextStyle,
weekendDateStyle: commonStyles.weekendDateStyle,
);
}

/// Styles for the pickers that allows to select range ([RangePicker],
/// [WeekPicker]).
DatePickerRangeStyles({
TextStyle? displayedPeriodTitle,
TextStyle? weekendDateStyle,
TextStyle? currentDateStyle,
TextStyle? disabledDateStyle,
TextStyle? selectedDateStyle,
Expand Down Expand Up @@ -318,6 +327,7 @@ class DatePickerRangeStyles extends DatePickerStyles {
dayHeaderTitleBuilder: dayHeaderTitleBuilder,
nextIcon: nextIcon,
prevIcon: prevIcon,
weekendDateStyle: weekendDateStyle,
firstDayOfeWeekIndex: firstDayOfWeekIndex);

@override
Expand All @@ -344,7 +354,8 @@ class DatePickerRangeStyles extends DatePickerStyles {
other.dayHeaderTitleBuilder == dayHeaderTitleBuilder &&
other.prevIcon == prevIcon &&
other.nextIcon == nextIcon &&
other.firstDayOfeWeekIndex == firstDayOfeWeekIndex;
other.firstDayOfeWeekIndex == firstDayOfeWeekIndex &&
other.weekendDateStyle == weekendDateStyle;
}

@override
Expand All @@ -358,6 +369,7 @@ class DatePickerRangeStyles extends DatePickerStyles {
displayedPeriodTitle,
currentDateStyle,
disabledDateStyle,
weekendDateStyle,
selectedDateStyle,
defaultDateTextStyle,
selectedSingleDateDecoration,
Expand Down
1 change: 0 additions & 1 deletion lib/src/week_picker.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';

import 'date_period.dart';
import 'date_picker_keys.dart';
Expand Down
34 changes: 17 additions & 17 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.8.1"
version: "2.8.2"
boolean_selector:
dependency: transitive
description:
Expand All @@ -21,7 +21,7 @@ packages:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.2.0"
charcode:
dependency: transitive
description:
Expand All @@ -42,14 +42,14 @@ packages:
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "1.15.0"
version: "1.16.0"
fake_async:
dependency: transitive
description:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.3.0"
flutter:
dependency: "direct main"
description: flutter
Expand Down Expand Up @@ -78,7 +78,14 @@ packages:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.10"
version: "0.12.11"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.4"
meta:
dependency: transitive
description:
Expand All @@ -92,7 +99,7 @@ packages:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
version: "1.8.1"
sky_engine:
dependency: transitive
description: flutter
Expand All @@ -104,7 +111,7 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.1"
version: "1.8.2"
stack_trace:
dependency: transitive
description:
Expand Down Expand Up @@ -139,20 +146,13 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.2"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
version: "0.4.9"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
version: "2.1.2"
sdks:
dart: ">=2.12.0 <3.0.0"
dart: ">=2.17.0-0 <3.0.0"
2 changes: 1 addition & 1 deletion test/day_selectable_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void main() {

// ignore: prefer_function_declarations_over_variables
final selectablePredicate =
(DateTime d) => !DatePickerUtils.sameDate(d, disabledDate);
(d) => !DatePickerUtils.sameDate(d, disabledDate);

final selectableLogic = DaySelectable(selectedDate, firstDate, lastDate,
selectableDayPredicate: selectablePredicate);
Expand Down
5 changes: 3 additions & 2 deletions test/range_selectable_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ void main() {
final middlePeriodDateType = selectableLogic.getDayType(date);
expect(middlePeriodDateType, DayType.middle,
reason: "Incorrect DayType for the date ${date.toString()} "
"in period ${startPeriod.toString()} - ${endPeriod.toString()}");
"in period ${startPeriod.toString()} "
"- ${endPeriod.toString()}");
}
});
});
Expand Down Expand Up @@ -78,4 +79,4 @@ void main() {
expect(selectableLogic.firstDate, startOfTheFirstDate);
expect(selectableLogic.lastDate, endOfTheLastDate);
});
}
}