From 3e7b7c7d17248133db76648e11f3c116c0afcff3 Mon Sep 17 00:00:00 2001 From: Hans Kokx Date: Tue, 30 Apr 2024 14:00:45 +0200 Subject: [PATCH 1/4] Updated to support the latest version of Flutter. - Fixed linting issues - Added a call to onDayTapped when the depdendencies change for DayBasedChangeablePicker. This allows for changing between day and week pickers using an external toggle and the DatePeriod will be automatically updated instead of requiring user action. Signed-off-by: Hans Kokx --- analysis_options.yaml | 11 +- .../date_pickers_widgets/day_picker_page.dart | 4 +- .../days_picker_page.dart | 4 +- .../month_picker_page.dart | 4 +- .../months_picker_page.dart | 4 +- .../range_picker_page.dart | 2 +- .../range_picker_styled.dart | 2 +- .../week_picker_page.dart | 4 +- .../year_picker_page.dart | 4 +- .../years_picker_page.dart | 4 +- example/lib/main.dart | 2 +- example/pubspec.lock | 145 ++++++++++++------ lib/src/day_based_changable_picker.dart | 5 +- lib/src/i_selectable_picker.dart | 6 +- lib/src/month_picker.dart | 21 +-- lib/src/range_picker.dart | 1 - lib/src/styles/date_picker_styles.dart | 18 +-- lib/src/utils.dart | 2 + lib/src/week_picker.dart | 1 - lib/src/year_picker.dart | 21 +-- pubspec.lock | 131 ++++++++++------ pubspec.yaml | 4 +- test/day_selectable_test.dart | 2 +- test/range_selectable_test.dart | 6 +- 24 files changed, 242 insertions(+), 166 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index d8569d7..e3bb8d3 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -32,10 +32,8 @@ linter: prefer_iterable_whereType: true prefer_function_declarations_over_variables: true unnecessary_lambdas: true - prefer_equal_for_default_values: true avoid_init_to_null: true unnecessary_getters_setters: true - unnecessary_getters: true prefer_expression_function_bodies: true unnecessary_this: true unnecessary_const: true @@ -51,11 +49,10 @@ linter: prefer_final_fields: true use_setters_to_change_properties: true avoid_setters_without_getters: true - avoid_returning_null: true avoid_returning_this: true type_annotate_public_apis: true prefer_typing_uninitialized_variables: true -# omit_local_variable_types: true + # omit_local_variable_types: true avoid_types_on_closure_parameters: true avoid_return_types_on_setters: true prefer_generic_function_type_aliases: true @@ -66,11 +63,9 @@ linter: avoid_equals_and_hash_code_on_mutable_classes: true avoid_null_checks_in_equality_operators: true - # PEDANTIC # (duplicated rules are removed) always_declare_return_types: true - always_require_non_null_named_parameters: true annotate_overrides: true avoid_empty_else: true avoid_shadowing_type_parameters: true @@ -83,7 +78,7 @@ linter: prefer_contains: true prefer_for_elements_to_map_fromIterable: true prefer_if_null_operators: true -# prefer_single_quotes: true + # prefer_single_quotes: true prefer_spread_collections: true recursive_getters: true type_init_formals: true @@ -91,4 +86,4 @@ linter: unnecessary_new: true unnecessary_null_in_if_null_operators: true unrelated_type_equality_checks: true - valid_regexps: true \ No newline at end of file + valid_regexps: true diff --git a/example/lib/date_pickers_widgets/day_picker_page.dart b/example/lib/date_pickers_widgets/day_picker_page.dart index c7ff3a1..0391b38 100644 --- a/example/lib/date_pickers_widgets/day_picker_page.dart +++ b/example/lib/date_pickers_widgets/day_picker_page.dart @@ -44,7 +44,7 @@ class _DayPickerPageState extends State { dp.DatePickerRangeStyles styles = dp.DatePickerRangeStyles( selectedDateStyle: Theme.of(context) .textTheme - .bodyText1 + .bodyLarge ?.copyWith(color: selectedDateStyleColor), selectedSingleDateDecoration: BoxDecoration( color: selectedSingleDateDecorationColor, @@ -88,7 +88,7 @@ class _DayPickerPageState extends State { children: [ Text( "Selected date styles", - style: Theme.of(context).textTheme.subtitle1, + style: Theme.of(context).textTheme.titleMedium, ), Padding( padding: const EdgeInsets.symmetric(vertical: 12.0), diff --git a/example/lib/date_pickers_widgets/days_picker_page.dart b/example/lib/date_pickers_widgets/days_picker_page.dart index dd78dff..a720f44 100644 --- a/example/lib/date_pickers_widgets/days_picker_page.dart +++ b/example/lib/date_pickers_widgets/days_picker_page.dart @@ -52,7 +52,7 @@ class _DaysPickerPageState extends State { dp.DatePickerRangeStyles styles = dp.DatePickerRangeStyles( selectedDateStyle: Theme.of(context) .textTheme - .bodyText1 + .bodyLarge ?.copyWith(color: selectedDateStyleColor), selectedSingleDateDecoration: BoxDecoration( color: selectedSingleDateDecorationColor, shape: BoxShape.circle)); @@ -86,7 +86,7 @@ class _DaysPickerPageState extends State { children: [ Text( "Selected date styles", - style: Theme.of(context).textTheme.subtitle1, + style: Theme.of(context).textTheme.titleMedium, ), Padding( padding: const EdgeInsets.symmetric(vertical: 12.0), diff --git a/example/lib/date_pickers_widgets/month_picker_page.dart b/example/lib/date_pickers_widgets/month_picker_page.dart index 956d707..dc25115 100644 --- a/example/lib/date_pickers_widgets/month_picker_page.dart +++ b/example/lib/date_pickers_widgets/month_picker_page.dart @@ -32,7 +32,7 @@ class _MonthPickerPageState extends State { dp.DatePickerStyles styles = dp.DatePickerStyles( selectedDateStyle: Theme.of(context) .textTheme - .bodyText1 + .bodyLarge ?.copyWith(color: selectedDateStyleColor), selectedSingleDateDecoration: BoxDecoration( color: selectedSingleDateDecorationColor, shape: BoxShape.circle)); @@ -60,7 +60,7 @@ class _MonthPickerPageState extends State { children: [ Text( "Selected date styles", - style: Theme.of(context).textTheme.subtitle1, + style: Theme.of(context).textTheme.titleMedium, ), Padding( padding: const EdgeInsets.symmetric(vertical: 12.0), diff --git a/example/lib/date_pickers_widgets/months_picker_page.dart b/example/lib/date_pickers_widgets/months_picker_page.dart index 06f196c..35a514e 100644 --- a/example/lib/date_pickers_widgets/months_picker_page.dart +++ b/example/lib/date_pickers_widgets/months_picker_page.dart @@ -32,7 +32,7 @@ class _MonthsPickerPageState extends State { dp.DatePickerStyles styles = dp.DatePickerStyles( selectedDateStyle: Theme.of(context) .textTheme - .bodyText1 + .bodyLarge ?.copyWith(color: selectedDateStyleColor), selectedSingleDateDecoration: BoxDecoration( color: selectedSingleDateDecorationColor, shape: BoxShape.circle)); @@ -60,7 +60,7 @@ class _MonthsPickerPageState extends State { children: [ Text( "Selected date styles", - style: Theme.of(context).textTheme.subtitle1, + style: Theme.of(context).textTheme.titleMedium, ), Padding( padding: const EdgeInsets.symmetric(vertical: 12.0), diff --git a/example/lib/date_pickers_widgets/range_picker_page.dart b/example/lib/date_pickers_widgets/range_picker_page.dart index 48f1ac3..e9facd3 100644 --- a/example/lib/date_pickers_widgets/range_picker_page.dart +++ b/example/lib/date_pickers_widgets/range_picker_page.dart @@ -87,7 +87,7 @@ class _RangePickerPageState extends State { children: [ Text( "Selected date styles", - style: Theme.of(context).textTheme.subtitle1, + style: Theme.of(context).textTheme.titleMedium, ), _stylesBlock(), _selectedBlock() diff --git a/example/lib/date_pickers_widgets/range_picker_styled.dart b/example/lib/date_pickers_widgets/range_picker_styled.dart index 2735ceb..da9c1d4 100644 --- a/example/lib/date_pickers_widgets/range_picker_styled.dart +++ b/example/lib/date_pickers_widgets/range_picker_styled.dart @@ -113,7 +113,7 @@ class _RangePickerPageStyledState extends State { children: [ Text( "Selected date styles", - style: Theme.of(context).textTheme.subtitle1, + style: Theme.of(context).textTheme.titleMedium, ), _selectedBlock() ], diff --git a/example/lib/date_pickers_widgets/week_picker_page.dart b/example/lib/date_pickers_widgets/week_picker_page.dart index 64eac10..f062524 100644 --- a/example/lib/date_pickers_widgets/week_picker_page.dart +++ b/example/lib/date_pickers_widgets/week_picker_page.dart @@ -81,7 +81,7 @@ class _WeekPickerPageState extends State { children: [ Text( "Selected date styles", - style: Theme.of(context).textTheme.subtitle1, + style: Theme.of(context).textTheme.titleMedium, ), _stylesBlock(), _selectedBlock() @@ -222,7 +222,7 @@ class _WeekPickerPageState extends State { borderRadius: BorderRadius.all(Radius.circular(3.0))); TextStyle? whiteText = - Theme.of(context).textTheme.bodyText2?.copyWith(color: Colors.white); + Theme.of(context).textTheme.bodyMedium?.copyWith(color: Colors.white); return isEventDate ? EventDecoration(boxDecoration: roundedBorder, textStyle: whiteText) diff --git a/example/lib/date_pickers_widgets/year_picker_page.dart b/example/lib/date_pickers_widgets/year_picker_page.dart index b283904..0a564aa 100644 --- a/example/lib/date_pickers_widgets/year_picker_page.dart +++ b/example/lib/date_pickers_widgets/year_picker_page.dart @@ -32,7 +32,7 @@ class _YearPickerPageState extends State { dp.DatePickerStyles styles = dp.DatePickerStyles( selectedDateStyle: Theme.of(context) .textTheme - .bodyText1 + .bodyLarge ?.copyWith(color: selectedDateStyleColor), selectedSingleDateDecoration: BoxDecoration( color: selectedSingleDateDecorationColor, shape: BoxShape.circle)); @@ -60,7 +60,7 @@ class _YearPickerPageState extends State { children: [ Text( "Selected date styles", - style: Theme.of(context).textTheme.subtitle1, + style: Theme.of(context).textTheme.titleMedium, ), Padding( padding: const EdgeInsets.symmetric(vertical: 12.0), diff --git a/example/lib/date_pickers_widgets/years_picker_page.dart b/example/lib/date_pickers_widgets/years_picker_page.dart index eaca93f..3c588b6 100644 --- a/example/lib/date_pickers_widgets/years_picker_page.dart +++ b/example/lib/date_pickers_widgets/years_picker_page.dart @@ -32,7 +32,7 @@ class _YearsPickerPageState extends State { dp.DatePickerStyles styles = dp.DatePickerStyles( selectedDateStyle: Theme.of(context) .textTheme - .bodyText1 + .bodyLarge ?.copyWith(color: selectedDateStyleColor), selectedSingleDateDecoration: BoxDecoration( color: selectedSingleDateDecorationColor, shape: BoxShape.circle)); @@ -60,7 +60,7 @@ class _YearsPickerPageState extends State { children: [ Text( "Selected date styles", - style: Theme.of(context).textTheme.subtitle1, + style: Theme.of(context).textTheme.titleMedium, ), Padding( padding: const EdgeInsets.symmetric(vertical: 12.0), diff --git a/example/lib/main.dart b/example/lib/main.dart index 01cda00..2ebb14a 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -92,7 +92,7 @@ class _MyHomePageState extends State with TickerProviderStateMixin { data: Theme.of(context).copyWith( canvasColor: Colors.blueGrey, textTheme: Theme.of(context).textTheme.copyWith( - caption: TextStyle(color: Colors.white.withOpacity(0.5)))), + bodySmall: TextStyle(color: Colors.white.withOpacity(0.5)))), child: BottomNavigationBar( type: BottomNavigationBarType.fixed, items: [ diff --git a/example/pubspec.lock b/example/pubspec.lock index a7c4b91..fa36941 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -5,58 +5,58 @@ packages: dependency: transitive description: name: async - url: "https://pub.dartlang.org" + sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" + url: "https://pub.dev" source: hosted - version: "2.8.2" + version: "2.11.0" boolean_selector: dependency: transitive description: name: boolean_selector - url: "https://pub.dartlang.org" + sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.1" characters: dependency: transitive description: name: characters - url: "https://pub.dartlang.org" + sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" + url: "https://pub.dev" source: hosted - version: "1.2.0" - charcode: - dependency: transitive - description: - name: charcode - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.1" + version: "1.3.0" clock: dependency: transitive description: name: clock - url: "https://pub.dartlang.org" + sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf + url: "https://pub.dev" source: hosted - version: "1.1.0" + version: "1.1.1" collection: dependency: transitive description: name: collection - url: "https://pub.dartlang.org" + sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a + url: "https://pub.dev" source: hosted - version: "1.16.0" + version: "1.18.0" cupertino_icons: dependency: "direct main" description: name: cupertino_icons - url: "https://pub.dartlang.org" + sha256: ba631d1c7f7bef6b729a622b7b752645a2d076dba9976925b8f25725a30e1ee6 + url: "https://pub.dev" source: hosted - version: "1.0.2" + version: "1.0.8" fake_async: dependency: transitive description: name: fake_async - url: "https://pub.dartlang.org" + sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78" + url: "https://pub.dev" source: hosted - version: "1.3.0" + version: "1.3.1" flutter: dependency: "direct main" description: flutter @@ -68,7 +68,7 @@ packages: path: ".." relative: true source: path - version: "0.3.0" + version: "0.4.2" flutter_localizations: dependency: "direct main" description: flutter @@ -78,9 +78,10 @@ packages: dependency: "direct main" description: name: flutter_material_color_picker - url: "https://pub.dartlang.org" + sha256: ca1e7749d228c9155ea24bce98e647cdbffa350e6f334f6c001f841cd3d9c987 + url: "https://pub.dev" source: hosted - version: "1.1.0+2" + version: "1.2.0" flutter_test: dependency: "direct dev" description: flutter @@ -90,37 +91,66 @@ packages: dependency: transitive description: name: intl - url: "https://pub.dartlang.org" + sha256: "3bc132a9dbce73a7e4a21a17d06e1878839ffbf975568bc875c60537824b0c4d" + url: "https://pub.dev" source: hosted - version: "0.17.0" + version: "0.18.1" + leak_tracker: + dependency: transitive + description: + name: leak_tracker + sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa" + url: "https://pub.dev" + source: hosted + version: "10.0.0" + leak_tracker_flutter_testing: + dependency: transitive + description: + name: leak_tracker_flutter_testing + sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0 + url: "https://pub.dev" + source: hosted + version: "2.0.1" + leak_tracker_testing: + dependency: transitive + description: + name: leak_tracker_testing + sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47 + url: "https://pub.dev" + source: hosted + version: "2.0.1" matcher: dependency: transitive description: name: matcher - url: "https://pub.dartlang.org" + sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb + url: "https://pub.dev" source: hosted - version: "0.12.11" + version: "0.12.16+1" material_color_utilities: dependency: transitive description: name: material_color_utilities - url: "https://pub.dartlang.org" + sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" + url: "https://pub.dev" source: hosted - version: "0.1.4" + version: "0.8.0" meta: dependency: transitive description: name: meta - url: "https://pub.dartlang.org" + sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04 + url: "https://pub.dev" source: hosted - version: "1.7.0" + version: "1.11.0" path: dependency: transitive description: name: path - url: "https://pub.dartlang.org" + sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" + url: "https://pub.dev" source: hosted - version: "1.8.1" + version: "1.9.0" sky_engine: dependency: transitive description: flutter @@ -130,51 +160,66 @@ packages: dependency: transitive description: name: source_span - url: "https://pub.dartlang.org" + sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" + url: "https://pub.dev" source: hosted - version: "1.8.2" + version: "1.10.0" stack_trace: dependency: transitive description: name: stack_trace - url: "https://pub.dartlang.org" + sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" + url: "https://pub.dev" source: hosted - version: "1.10.0" + version: "1.11.1" stream_channel: dependency: transitive description: name: stream_channel - url: "https://pub.dartlang.org" + sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7 + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.2" string_scanner: dependency: transitive description: name: string_scanner - url: "https://pub.dartlang.org" + sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" + url: "https://pub.dev" source: hosted - version: "1.1.0" + version: "1.2.0" term_glyph: dependency: transitive description: name: term_glyph - url: "https://pub.dartlang.org" + sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 + url: "https://pub.dev" source: hosted - version: "1.2.0" + version: "1.2.1" test_api: dependency: transitive description: name: test_api - url: "https://pub.dartlang.org" + sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" + url: "https://pub.dev" source: hosted - version: "0.4.9" + version: "0.6.1" vector_math: dependency: transitive description: name: vector_math - url: "https://pub.dartlang.org" + sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" + url: "https://pub.dev" source: hosted - version: "2.1.2" + version: "2.1.4" + vm_service: + dependency: transitive + description: + name: vm_service + sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957 + url: "https://pub.dev" + source: hosted + version: "13.0.0" sdks: - dart: ">=2.17.0-0 <3.0.0" - flutter: ">=1.17.0" + dart: ">=3.2.0-0 <4.0.0" + flutter: ">=3.3.0" diff --git a/lib/src/day_based_changable_picker.dart b/lib/src/day_based_changable_picker.dart index 631f82b..c9bf632 100644 --- a/lib/src/day_based_changable_picker.dart +++ b/lib/src/day_based_changable_picker.dart @@ -1,8 +1,9 @@ +// ignore_for_file: comment_references + import 'dart:async'; import 'package:flutter/material.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; - import 'package:intl/intl.dart' as intl; import 'basic_day_based_widget.dart'; @@ -160,6 +161,8 @@ class _DayBasedChangeablePickerState final ThemeData theme = Theme.of(context); _resultStyles = widget.datePickerStyles.fulfillWithTheme(theme); + + widget.selectablePicker.onDayTapped(widget.selection.earliest); } @override diff --git a/lib/src/i_selectable_picker.dart b/lib/src/i_selectable_picker.dart index 2fabb2c..1649dcb 100644 --- a/lib/src/i_selectable_picker.dart +++ b/lib/src/i_selectable_picker.dart @@ -1,3 +1,5 @@ +// ignore_for_file: comment_references + import 'dart:async'; import 'package:flutter/material.dart'; @@ -66,7 +68,9 @@ abstract class ISelectablePicker { /// 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. diff --git a/lib/src/month_picker.dart b/lib/src/month_picker.dart index b9d79d4..a522c96 100644 --- a/lib/src/month_picker.dart +++ b/lib/src/month_picker.dart @@ -191,22 +191,15 @@ class _MonthPickerState extends State> { void didChangeDependencies() { super.didChangeDependencies(); - try { - locale = Localizations.localeOf(context); - - MaterialLocalizations? curLocalizations = - Localizations.of( - context, MaterialLocalizations); - if (curLocalizations != null && localizations != curLocalizations) { - localizations = curLocalizations; - } + locale = Localizations.localeOf(context); - textDirection = Directionality.of(context); + MaterialLocalizations? curLocalizations = + Localizations.of(context, MaterialLocalizations); + if (curLocalizations != null && localizations != curLocalizations) { + localizations = curLocalizations; + } - // No MaterialLocalizations or Directionality or Locale was found - // and ".of" method throws error - // trying to cast null to MaterialLocalizations. - } on TypeError catch (_) {} + textDirection = Directionality.of(context); } @override diff --git a/lib/src/range_picker.dart b/lib/src/range_picker.dart index 10d2429..65b4547 100644 --- a/lib/src/range_picker.dart +++ b/lib/src/range_picker.dart @@ -1,5 +1,4 @@ import 'package:flutter/material.dart'; -import 'package:flutter/rendering.dart'; import 'date_period.dart'; import 'date_picker_keys.dart'; diff --git a/lib/src/styles/date_picker_styles.dart b/lib/src/styles/date_picker_styles.dart index 41b6a37..8f48c18 100644 --- a/lib/src/styles/date_picker_styles.dart +++ b/lib/src/styles/date_picker_styles.dart @@ -101,18 +101,18 @@ class DatePickerStyles { Color accentColor = theme.colorScheme.secondary; TextStyle? _displayedPeriodTitle = - displayedPeriodTitle ?? theme.textTheme.subtitle1; + displayedPeriodTitle ?? theme.textTheme.titleMedium; TextStyle? _currentDateStyle = currentDateStyle ?? - theme.textTheme.bodyText1?.copyWith(color: theme.colorScheme.secondary); + theme.textTheme.bodyLarge?.copyWith(color: theme.colorScheme.secondary); TextStyle? _disabledDateStyle = disabledDateStyle ?? - theme.textTheme.bodyText2?.copyWith(color: theme.disabledColor); + theme.textTheme.bodyMedium?.copyWith(color: theme.disabledColor); TextStyle? _selectedDateStyle = selectedDateStyle ?? - theme.textTheme.bodyText1?.copyWith( + theme.textTheme.bodyLarge?.copyWith( color: theme.colorScheme.onSecondary, ); TextStyle? _defaultDateTextStyle = - defaultDateTextStyle ?? theme.textTheme.bodyText2; + defaultDateTextStyle ?? theme.textTheme.bodyMedium; BoxDecoration _selectedSingleDateDecoration = selectedSingleDateDecoration ?? BoxDecoration( @@ -121,7 +121,7 @@ class DatePickerStyles { DayHeaderStyle? _dayHeaderStyle = dayHeaderStyle; if (dayHeaderStyleBuilder == null && _dayHeaderStyle == null) { - _dayHeaderStyle = DayHeaderStyle(textStyle: theme.textTheme.caption); + _dayHeaderStyle = DayHeaderStyle(textStyle: theme.textTheme.bodySmall); } return DatePickerStyles( @@ -159,7 +159,7 @@ class DatePickerStyles { } @override - int get hashCode => hashValues( + int get hashCode => Object.hash( displayedPeriodTitle, currentDateStyle, disabledDateStyle, @@ -348,7 +348,7 @@ class DatePickerRangeStyles extends DatePickerStyles { } @override - int get hashCode => hashValues( + int get hashCode => Object.hash( selectedPeriodStartDecoration, selectedPeriodStartTextStyle, selectedPeriodLastDecoration, @@ -395,5 +395,5 @@ class DayHeaderStyle { } @override - int get hashCode => hashValues(textStyle, decoration); + int get hashCode => Object.hash(textStyle, decoration); } diff --git a/lib/src/utils.dart b/lib/src/utils.dart index 9c2fc9d..1a14444 100644 --- a/lib/src/utils.dart +++ b/lib/src/utils.dart @@ -1,5 +1,7 @@ /// Bunch of useful functions for date pickers. class DatePickerUtils { + DatePickerUtils._(); + /// Returns if two objects have same year, month and day. /// Time doesn't matter. static bool sameDate(DateTime dateTimeOne, DateTime dateTimeTwo) => diff --git a/lib/src/week_picker.dart b/lib/src/week_picker.dart index db25b79..d4cc88e 100644 --- a/lib/src/week_picker.dart +++ b/lib/src/week_picker.dart @@ -1,5 +1,4 @@ import 'package:flutter/material.dart'; -import 'package:flutter/rendering.dart'; import 'date_period.dart'; import 'date_picker_keys.dart'; diff --git a/lib/src/year_picker.dart b/lib/src/year_picker.dart index af9afeb..6da12ba 100644 --- a/lib/src/year_picker.dart +++ b/lib/src/year_picker.dart @@ -202,22 +202,15 @@ class _YearPickerState extends State> { void didChangeDependencies() { super.didChangeDependencies(); - try { - locale = Localizations.localeOf(context); - - MaterialLocalizations? curLocalizations = - Localizations.of( - context, MaterialLocalizations); - if (curLocalizations != null && localizations != curLocalizations) { - localizations = curLocalizations; - } + locale = Localizations.localeOf(context); - textDirection = Directionality.of(context); + MaterialLocalizations? curLocalizations = + Localizations.of(context, MaterialLocalizations); + if (curLocalizations != null && localizations != curLocalizations) { + localizations = curLocalizations; + } - // No MaterialLocalizations or Directionality or Locale was found - // and ".of" method throws error - // trying to cast null to MaterialLocalizations. - } on TypeError catch (_) {} + textDirection = Directionality.of(context); } @override diff --git a/pubspec.lock b/pubspec.lock index 199d9e6..e288a2c 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -5,51 +5,50 @@ packages: dependency: transitive description: name: async - url: "https://pub.dartlang.org" + sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" + url: "https://pub.dev" source: hosted - version: "2.8.2" + version: "2.11.0" boolean_selector: dependency: transitive description: name: boolean_selector - url: "https://pub.dartlang.org" + sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.1" characters: dependency: transitive description: name: characters - url: "https://pub.dartlang.org" + sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" + url: "https://pub.dev" source: hosted - version: "1.2.0" - charcode: - dependency: transitive - description: - name: charcode - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.1" + version: "1.3.0" clock: dependency: transitive description: name: clock - url: "https://pub.dartlang.org" + sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf + url: "https://pub.dev" source: hosted - version: "1.1.0" + version: "1.1.1" collection: dependency: transitive description: name: collection - url: "https://pub.dartlang.org" + sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a + url: "https://pub.dev" source: hosted - version: "1.16.0" + version: "1.18.0" fake_async: dependency: transitive description: name: fake_async - url: "https://pub.dartlang.org" + sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78" + url: "https://pub.dev" source: hosted - version: "1.3.0" + version: "1.3.1" flutter: dependency: "direct main" description: flutter @@ -69,37 +68,66 @@ packages: dependency: "direct main" description: name: intl - url: "https://pub.dartlang.org" + sha256: "3bc132a9dbce73a7e4a21a17d06e1878839ffbf975568bc875c60537824b0c4d" + url: "https://pub.dev" + source: hosted + version: "0.18.1" + leak_tracker: + dependency: transitive + description: + name: leak_tracker + sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa" + url: "https://pub.dev" + source: hosted + version: "10.0.0" + leak_tracker_flutter_testing: + dependency: transitive + description: + name: leak_tracker_flutter_testing + sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0 + url: "https://pub.dev" + source: hosted + version: "2.0.1" + leak_tracker_testing: + dependency: transitive + description: + name: leak_tracker_testing + sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47 + url: "https://pub.dev" source: hosted - version: "0.17.0" + version: "2.0.1" matcher: dependency: transitive description: name: matcher - url: "https://pub.dartlang.org" + sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb + url: "https://pub.dev" source: hosted - version: "0.12.11" + version: "0.12.16+1" material_color_utilities: dependency: transitive description: name: material_color_utilities - url: "https://pub.dartlang.org" + sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" + url: "https://pub.dev" source: hosted - version: "0.1.4" + version: "0.8.0" meta: dependency: transitive description: name: meta - url: "https://pub.dartlang.org" + sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04 + url: "https://pub.dev" source: hosted - version: "1.7.0" + version: "1.11.0" path: dependency: transitive description: name: path - url: "https://pub.dartlang.org" + sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" + url: "https://pub.dev" source: hosted - version: "1.8.1" + version: "1.9.0" sky_engine: dependency: transitive description: flutter @@ -109,50 +137,65 @@ packages: dependency: transitive description: name: source_span - url: "https://pub.dartlang.org" + sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" + url: "https://pub.dev" source: hosted - version: "1.8.2" + version: "1.10.0" stack_trace: dependency: transitive description: name: stack_trace - url: "https://pub.dartlang.org" + sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" + url: "https://pub.dev" source: hosted - version: "1.10.0" + version: "1.11.1" stream_channel: dependency: transitive description: name: stream_channel - url: "https://pub.dartlang.org" + sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7 + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.2" string_scanner: dependency: transitive description: name: string_scanner - url: "https://pub.dartlang.org" + sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" + url: "https://pub.dev" source: hosted - version: "1.1.0" + version: "1.2.0" term_glyph: dependency: transitive description: name: term_glyph - url: "https://pub.dartlang.org" + sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 + url: "https://pub.dev" source: hosted - version: "1.2.0" + version: "1.2.1" test_api: dependency: transitive description: name: test_api - url: "https://pub.dartlang.org" + sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" + url: "https://pub.dev" source: hosted - version: "0.4.9" + version: "0.6.1" vector_math: dependency: transitive description: name: vector_math - url: "https://pub.dartlang.org" + sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" + url: "https://pub.dev" source: hosted - version: "2.1.2" + version: "2.1.4" + vm_service: + dependency: transitive + description: + name: vm_service + sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957 + url: "https://pub.dev" + source: hosted + version: "13.0.0" sdks: - dart: ">=2.17.0-0 <3.0.0" + dart: ">=3.2.0-0 <4.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 95364fa..371f1f1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,11 +1,11 @@ name: flutter_date_pickers description: Flutter package for day, week, range and month date pickers. -version: 0.4.2 +version: 0.5.0 homepage: https://github.com/MariaMelnik/flutter_date_pickers issue_tracker: https://github.com/MariaMelnik/flutter_date_pickers/issues environment: - sdk: '>=2.12.0 <3.0.0' + sdk: ">=3.0.0 <4.0.0" dependencies: flutter: diff --git a/test/day_selectable_test.dart b/test/day_selectable_test.dart index 200e324..bf991f5 100644 --- a/test/day_selectable_test.dart +++ b/test/day_selectable_test.dart @@ -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); diff --git a/test/range_selectable_test.dart b/test/range_selectable_test.dart index 0e057f5..eb605d7 100644 --- a/test/range_selectable_test.dart +++ b/test/range_selectable_test.dart @@ -2,7 +2,6 @@ import 'package:flutter_date_pickers/flutter_date_pickers.dart'; import 'package:flutter_date_pickers/src/day_type.dart'; import 'package:flutter_date_pickers/src/i_selectable_picker.dart'; import 'package:flutter_date_pickers/src/utils.dart'; - import 'package:flutter_test/flutter_test.dart'; void main() { @@ -48,7 +47,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()}"); } }); }); @@ -78,4 +78,4 @@ void main() { expect(selectableLogic.firstDate, startOfTheFirstDate); expect(selectableLogic.lastDate, endOfTheLastDate); }); -} \ No newline at end of file +} From a11d6bb1c1988dc67a3f106e7b13e977caf907a6 Mon Sep 17 00:00:00 2001 From: Hans Kokx Date: Thu, 2 May 2024 14:44:52 +0200 Subject: [PATCH 2/4] Extend automatic selection on build from day-based picker to month/year pickers Signed-off-by: Hans Kokx --- lib/src/month_picker.dart | 2 ++ lib/src/year_picker.dart | 2 ++ 2 files changed, 4 insertions(+) diff --git a/lib/src/month_picker.dart b/lib/src/month_picker.dart index a522c96..15e8146 100644 --- a/lib/src/month_picker.dart +++ b/lib/src/month_picker.dart @@ -200,6 +200,8 @@ class _MonthPickerState extends State> { } textDirection = Directionality.of(context); + + widget.selectionLogic.onDayTapped(widget.selection.earliest); } @override diff --git a/lib/src/year_picker.dart b/lib/src/year_picker.dart index 6da12ba..2f4a30a 100644 --- a/lib/src/year_picker.dart +++ b/lib/src/year_picker.dart @@ -211,6 +211,8 @@ class _YearPickerState extends State> { } textDirection = Directionality.of(context); + + widget.selectionLogic.onDayTapped(widget.selection.earliest); } @override From ab76c845f117f29279159d0d2566fc1a769ae01a Mon Sep 17 00:00:00 2001 From: Hans Kokx Date: Wed, 18 Sep 2024 11:48:18 +0200 Subject: [PATCH 3/4] Updated dependencies --- example/pubspec.lock | 38 +++++++++++++++++++------------------- pubspec.lock | 35 ++++++++++++++++++----------------- 2 files changed, 37 insertions(+), 36 deletions(-) diff --git a/example/pubspec.lock b/example/pubspec.lock index fa36941..7fcf4d7 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -68,7 +68,7 @@ packages: path: ".." relative: true source: path - version: "0.4.2" + version: "0.5.0" flutter_localizations: dependency: "direct main" description: flutter @@ -91,34 +91,34 @@ packages: dependency: transitive description: name: intl - sha256: "3bc132a9dbce73a7e4a21a17d06e1878839ffbf975568bc875c60537824b0c4d" + sha256: d6f56758b7d3014a48af9701c085700aac781a92a87a62b1333b46d8879661cf url: "https://pub.dev" source: hosted - version: "0.18.1" + version: "0.19.0" leak_tracker: dependency: transitive description: name: leak_tracker - sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa" + sha256: "3f87a60e8c63aecc975dda1ceedbc8f24de75f09e4856ea27daf8958f2f0ce05" url: "https://pub.dev" source: hosted - version: "10.0.0" + version: "10.0.5" leak_tracker_flutter_testing: dependency: transitive description: name: leak_tracker_flutter_testing - sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0 + sha256: "932549fb305594d82d7183ecd9fa93463e9914e1b67cacc34bc40906594a1806" url: "https://pub.dev" source: hosted - version: "2.0.1" + version: "3.0.5" leak_tracker_testing: dependency: transitive description: name: leak_tracker_testing - sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47 + sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3" url: "https://pub.dev" source: hosted - version: "2.0.1" + version: "3.0.1" matcher: dependency: transitive description: @@ -131,18 +131,18 @@ packages: dependency: transitive description: name: material_color_utilities - sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" + sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec url: "https://pub.dev" source: hosted - version: "0.8.0" + version: "0.11.1" meta: dependency: transitive description: name: meta - sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04 + sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7 url: "https://pub.dev" source: hosted - version: "1.11.0" + version: "1.15.0" path: dependency: transitive description: @@ -200,10 +200,10 @@ packages: dependency: transitive description: name: test_api - sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" + sha256: "5b8a98dafc4d5c4c9c72d8b31ab2b23fc13422348d2997120294d3bac86b4ddb" url: "https://pub.dev" source: hosted - version: "0.6.1" + version: "0.7.2" vector_math: dependency: transitive description: @@ -216,10 +216,10 @@ packages: dependency: transitive description: name: vm_service - sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957 + sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d" url: "https://pub.dev" source: hosted - version: "13.0.0" + version: "14.2.5" sdks: - dart: ">=3.2.0-0 <4.0.0" - flutter: ">=3.3.0" + dart: ">=3.3.0 <4.0.0" + flutter: ">=3.18.0-18.0.pre.54" diff --git a/pubspec.lock b/pubspec.lock index e288a2c..a4bb21c 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -68,34 +68,34 @@ packages: dependency: "direct main" description: name: intl - sha256: "3bc132a9dbce73a7e4a21a17d06e1878839ffbf975568bc875c60537824b0c4d" + sha256: d6f56758b7d3014a48af9701c085700aac781a92a87a62b1333b46d8879661cf url: "https://pub.dev" source: hosted - version: "0.18.1" + version: "0.19.0" leak_tracker: dependency: transitive description: name: leak_tracker - sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa" + sha256: "3f87a60e8c63aecc975dda1ceedbc8f24de75f09e4856ea27daf8958f2f0ce05" url: "https://pub.dev" source: hosted - version: "10.0.0" + version: "10.0.5" leak_tracker_flutter_testing: dependency: transitive description: name: leak_tracker_flutter_testing - sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0 + sha256: "932549fb305594d82d7183ecd9fa93463e9914e1b67cacc34bc40906594a1806" url: "https://pub.dev" source: hosted - version: "2.0.1" + version: "3.0.5" leak_tracker_testing: dependency: transitive description: name: leak_tracker_testing - sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47 + sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3" url: "https://pub.dev" source: hosted - version: "2.0.1" + version: "3.0.1" matcher: dependency: transitive description: @@ -108,18 +108,18 @@ packages: dependency: transitive description: name: material_color_utilities - sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" + sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec url: "https://pub.dev" source: hosted - version: "0.8.0" + version: "0.11.1" meta: dependency: transitive description: name: meta - sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04 + sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7 url: "https://pub.dev" source: hosted - version: "1.11.0" + version: "1.15.0" path: dependency: transitive description: @@ -177,10 +177,10 @@ packages: dependency: transitive description: name: test_api - sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" + sha256: "5b8a98dafc4d5c4c9c72d8b31ab2b23fc13422348d2997120294d3bac86b4ddb" url: "https://pub.dev" source: hosted - version: "0.6.1" + version: "0.7.2" vector_math: dependency: transitive description: @@ -193,9 +193,10 @@ packages: dependency: transitive description: name: vm_service - sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957 + sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d" url: "https://pub.dev" source: hosted - version: "13.0.0" + version: "14.2.5" sdks: - dart: ">=3.2.0-0 <4.0.0" + dart: ">=3.3.0 <4.0.0" + flutter: ">=3.18.0-18.0.pre.54" From 444505247973d2a18815d4adc1f6e53cfb9f449d Mon Sep 17 00:00:00 2001 From: Hans Kokx Date: Mon, 7 Oct 2024 14:25:27 +0200 Subject: [PATCH 4/4] Fixed some formatting and linting issues Signed-off-by: Hans Kokx --- analysis_options.yaml | 11 ++-- example/lib/color_picker_dialog.dart | 9 +-- .../range_picker_page.dart | 1 - example/pubspec.lock | 26 ++++----- lib/src/date_picker_mixin.dart | 20 ++----- ...day_based_changeable_picker_presenter.dart | 58 +++++++++---------- lib/src/day_type.dart | 2 +- lib/src/i_selectable_picker.dart | 4 +- lib/src/icon_btn.dart | 28 ++++----- lib/src/month_navigation_row.dart | 24 ++++---- lib/src/range_picker.dart | 3 +- lib/src/styles/event_decoration.dart | 5 +- lib/src/styles/layout_settings.dart | 6 +- lib/src/typedefs.dart | 1 - lib/src/unselectable_period_error.dart | 14 ++--- lib/src/utils.dart | 2 + lib/src/week_picker.dart | 3 +- pubspec.lock | 24 ++++---- test/range_selectable_test.dart | 6 +- test/week_selectable_test.dart | 2 +- 20 files changed, 110 insertions(+), 139 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index d8569d7..349bea6 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -35,7 +35,6 @@ linter: prefer_equal_for_default_values: true avoid_init_to_null: true unnecessary_getters_setters: true - unnecessary_getters: true prefer_expression_function_bodies: true unnecessary_this: true unnecessary_const: true @@ -55,7 +54,7 @@ linter: avoid_returning_this: true type_annotate_public_apis: true prefer_typing_uninitialized_variables: true -# omit_local_variable_types: true + # omit_local_variable_types: true avoid_types_on_closure_parameters: true avoid_return_types_on_setters: true prefer_generic_function_type_aliases: true @@ -66,7 +65,6 @@ linter: avoid_equals_and_hash_code_on_mutable_classes: true avoid_null_checks_in_equality_operators: true - # PEDANTIC # (duplicated rules are removed) always_declare_return_types: true @@ -83,7 +81,7 @@ linter: prefer_contains: true prefer_for_elements_to_map_fromIterable: true prefer_if_null_operators: true -# prefer_single_quotes: true + # prefer_single_quotes: true prefer_spread_collections: true recursive_getters: true type_init_formals: true @@ -91,4 +89,7 @@ linter: unnecessary_new: true unnecessary_null_in_if_null_operators: true unrelated_type_equality_checks: true - valid_regexps: true \ No newline at end of file + valid_regexps: true +analyzer: + errors: + comment_references: ignore diff --git a/example/lib/color_picker_dialog.dart b/example/lib/color_picker_dialog.dart index 1e834d7..88444f4 100644 --- a/example/lib/color_picker_dialog.dart +++ b/example/lib/color_picker_dialog.dart @@ -3,7 +3,6 @@ import 'package:flutter_material_color_picker/flutter_material_color_picker.dart /// Dialog with some Material colors ([materialColors]) to pick one of them. class ColorPickerDialog extends StatefulWidget { - /// Initially selected color. /// /// If pre-selected color is not from [materialColors] [Colors.blue] will be @@ -11,10 +10,8 @@ class ColorPickerDialog extends StatefulWidget { final Color selectedColor; /// - const ColorPickerDialog({ - Key? key, - required this.selectedColor - }) : super(key: key); + const ColorPickerDialog({Key? key, required this.selectedColor}) + : super(key: key); @override State createState() => _ColorPickerDialogState(); @@ -61,7 +58,7 @@ class _ColorPickerDialogState extends State { ); } - void _onMainColorChange (Color? newColor) { + void _onMainColorChange(Color? newColor) { if (newColor == null) return; setState(() { diff --git a/example/lib/date_pickers_widgets/range_picker_page.dart b/example/lib/date_pickers_widgets/range_picker_page.dart index 5fd44c3..eb1262c 100644 --- a/example/lib/date_pickers_widgets/range_picker_page.dart +++ b/example/lib/date_pickers_widgets/range_picker_page.dart @@ -18,7 +18,6 @@ class RangePickerPage extends StatefulWidget { } class _RangePickerPageState extends State { - final DateTime _firstDate = DateTime.now().subtract(Duration(days: 3450)); final DateTime _lastDate = DateTime.now().add(Duration(days: 345)); diff --git a/example/pubspec.lock b/example/pubspec.lock index ef3aa07..6e6a340 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -68,7 +68,7 @@ packages: path: ".." relative: true source: path - version: "0.4.2" + version: "0.4.3" flutter_localizations: dependency: "direct main" description: flutter @@ -99,18 +99,18 @@ packages: dependency: transitive description: name: leak_tracker - sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a" + sha256: "3f87a60e8c63aecc975dda1ceedbc8f24de75f09e4856ea27daf8958f2f0ce05" url: "https://pub.dev" source: hosted - version: "10.0.4" + version: "10.0.5" leak_tracker_flutter_testing: dependency: transitive description: name: leak_tracker_flutter_testing - sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8" + sha256: "932549fb305594d82d7183ecd9fa93463e9914e1b67cacc34bc40906594a1806" url: "https://pub.dev" source: hosted - version: "3.0.3" + version: "3.0.5" leak_tracker_testing: dependency: transitive description: @@ -131,18 +131,18 @@ packages: dependency: transitive description: name: material_color_utilities - sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" + sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec url: "https://pub.dev" source: hosted - version: "0.8.0" + version: "0.11.1" meta: dependency: transitive description: name: meta - sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136" + sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7 url: "https://pub.dev" source: hosted - version: "1.12.0" + version: "1.15.0" path: dependency: transitive description: @@ -200,10 +200,10 @@ packages: dependency: transitive description: name: test_api - sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f" + sha256: "5b8a98dafc4d5c4c9c72d8b31ab2b23fc13422348d2997120294d3bac86b4ddb" url: "https://pub.dev" source: hosted - version: "0.7.0" + version: "0.7.2" vector_math: dependency: transitive description: @@ -216,10 +216,10 @@ packages: dependency: transitive description: name: vm_service - sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec" + sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d" url: "https://pub.dev" source: hosted - version: "14.2.1" + version: "14.2.5" sdks: dart: ">=3.3.0 <4.0.0" flutter: ">=3.18.0-18.0.pre.54" diff --git a/lib/src/date_picker_mixin.dart b/lib/src/date_picker_mixin.dart index 32edb37..431e96e 100644 --- a/lib/src/date_picker_mixin.dart +++ b/lib/src/date_picker_mixin.dart @@ -4,7 +4,6 @@ import 'styles/date_picker_styles.dart'; /// mixin CommonDatePickerFunctions { - /// Builds widgets showing abbreviated days of week. The first widget in the /// returned list corresponds to the first day of week for the current locale. /// @@ -23,11 +22,8 @@ mixin CommonDatePickerFunctions { /// _ _ _ _ 1 2 3 /// 4 5 6 7 8 9 10 /// ``` - List getDayHeaders( - DayHeaderStyleBuilder headerStyleBuilder, - List narrowWeekdays, - int firstDayOfWeekIndex) { - + List getDayHeaders(DayHeaderStyleBuilder headerStyleBuilder, + List narrowWeekdays, int firstDayOfWeekIndex) { final List result = []; for (int i = firstDayOfWeekIndex; true; i = (i + 1) % 7) { @@ -37,12 +33,7 @@ mixin CommonDatePickerFunctions { Widget header = ExcludeSemantics( child: Container( decoration: headerStyle?.decoration, - child: Center( - child: Text( - weekday, - style: headerStyle?.textStyle - ) - ), + child: Center(child: Text(weekday, style: headerStyle?.textStyle)), ), ); @@ -86,8 +77,7 @@ mixin CommonDatePickerFunctions { /// into the [MaterialLocalizations.narrowWeekdays] list. /// - [MaterialLocalizations.narrowWeekdays] list provides localized names of /// days of week, always starting with Sunday and ending with Saturday. - int computeFirstDayOffset( - int year, int month, int firstDayOfWeekFromSunday) { + int computeFirstDayOffset(int year, int month, int firstDayOfWeekFromSunday) { // 0-based day of week, with 0 representing Monday. final int weekdayFromMonday = DateTime(year, month).weekday - 1; // firstDayOfWeekFromSunday recomputed to be Monday-based @@ -96,4 +86,4 @@ mixin CommonDatePickerFunctions { // and the day corresponding to the 1-st of the month. return (weekdayFromMonday - firstDayOfWeekFromMonday) % 7; } -} \ No newline at end of file +} diff --git a/lib/src/day_based_changeable_picker_presenter.dart b/lib/src/day_based_changeable_picker_presenter.dart index b608aa2..289c022 100644 --- a/lib/src/day_based_changeable_picker_presenter.dart +++ b/lib/src/day_based_changeable_picker_presenter.dart @@ -12,10 +12,10 @@ class DayBasedChangeablePickerPresenter { /// Last date user can select. final DateTime lastDate; - + /// Localization. final MaterialLocalizations localizations; - + /// If empty day cells before 1st day of showing month should be filled with /// date from the last week of the previous month. final bool showPrevMonthDates; @@ -23,11 +23,11 @@ class DayBasedChangeablePickerPresenter { /// If empty day cells after last day of showing month should be filled with /// date from the first week of the next month. final bool showNextMonthDates; - + /// Index of the first day in week. /// 0 is Sunday, 6 is Saturday. final int firstDayOfWeekIndex; - + /// View model stream for the [DayBasedChangeablePicker]. Stream get data => _controller.stream; @@ -35,15 +35,15 @@ class DayBasedChangeablePickerPresenter { DayBasedChangeablePickerState? get lastVal => _lastVal; /// Creates presenter to use for [DayBasedChangeablePicker]. - DayBasedChangeablePickerPresenter({ - required this.firstDate, - required this.lastDate, - required this.localizations, - required this.showPrevMonthDates, - required this.showNextMonthDates, - int? firstDayOfWeekIndex - }): firstDayOfWeekIndex = firstDayOfWeekIndex - ?? localizations.firstDayOfWeekIndex; + DayBasedChangeablePickerPresenter( + {required this.firstDate, + required this.lastDate, + required this.localizations, + required this.showPrevMonthDates, + required this.showNextMonthDates, + int? firstDayOfWeekIndex}) + : firstDayOfWeekIndex = + firstDayOfWeekIndex ?? localizations.firstDayOfWeekIndex; /// Update state according to the [selectedDate] if it needs. void setSelectedDate(DateTime selectedDate) { @@ -76,19 +76,19 @@ class DayBasedChangeablePickerPresenter { /// Update state to change month to the [newMonth]. void changeMonth(DateTime newMonth) { - bool sameMonth = _lastVal != null - && DatePickerUtils.sameMonth(_lastVal!.currentMonth, newMonth); + bool sameMonth = _lastVal != null && + DatePickerUtils.sameMonth(_lastVal!.currentMonth, newMonth); if (sameMonth) return; int monthPage = DatePickerUtils.monthDelta(firstDate, newMonth); - DateTime prevMonth = DatePickerUtils - .addMonthsToMonthDate(firstDate, monthPage - 1); + DateTime prevMonth = + DatePickerUtils.addMonthsToMonthDate(firstDate, monthPage - 1); - DateTime curMonth = DatePickerUtils - .addMonthsToMonthDate(firstDate, monthPage); + DateTime curMonth = + DatePickerUtils.addMonthsToMonthDate(firstDate, monthPage); - DateTime nextMonth = DatePickerUtils - .addMonthsToMonthDate(firstDate, monthPage + 1); + DateTime nextMonth = + DatePickerUtils.addMonthsToMonthDate(firstDate, monthPage + 1); String prevMonthStr = localizations.formatMonthYear(prevMonth); String curMonthStr = localizations.formatMonthYear(curMonth); @@ -101,9 +101,8 @@ class DayBasedChangeablePickerPresenter { ? null : "${localizations.previousMonthTooltip} $prevMonthStr"; - String? nextTooltip = isLastMonth - ? null - : "${localizations.nextMonthTooltip} $nextMonthStr"; + String? nextTooltip = + isLastMonth ? null : "${localizations.nextMonthTooltip} $nextMonthStr"; DayBasedChangeablePickerState newState = DayBasedChangeablePickerState( currentMonth: curMonth, @@ -113,14 +112,13 @@ class DayBasedChangeablePickerPresenter { prevTooltip: prevTooltip, nextTooltip: nextTooltip, isFirstMonth: isFirstMonth, - isLastMonth: isLastMonth - ); + isLastMonth: isLastMonth); _updateState(newState); } /// Closes controller. - void dispose () { + void dispose() { _controller.close(); } @@ -130,15 +128,13 @@ class DayBasedChangeablePickerPresenter { } final StreamController _controller = - StreamController.broadcast(); + StreamController.broadcast(); DayBasedChangeablePickerState? _lastVal; } - /// View Model for the [DayBasedChangeablePicker]. class DayBasedChangeablePickerState { - /// Display name of the current month. final String curMonthDis; @@ -174,4 +170,4 @@ class DayBasedChangeablePickerState { this.prevTooltip, this.nextTooltip, }); -} \ No newline at end of file +} diff --git a/lib/src/day_type.dart b/lib/src/day_type.dart index 86ba762..0cef59b 100644 --- a/lib/src/day_type.dart +++ b/lib/src/day_type.dart @@ -17,4 +17,4 @@ enum DayType { /// not selected day (but not disabled) notSelected -} \ No newline at end of file +} diff --git a/lib/src/i_selectable_picker.dart b/lib/src/i_selectable_picker.dart index 2fabb2c..d81dc33 100644 --- a/lib/src/i_selectable_picker.dart +++ b/lib/src/i_selectable_picker.dart @@ -66,7 +66,9 @@ abstract class ISelectablePicker { /// 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. diff --git a/lib/src/icon_btn.dart b/lib/src/icon_btn.dart index 7ddc5d7..81fac87 100644 --- a/lib/src/icon_btn.dart +++ b/lib/src/icon_btn.dart @@ -22,33 +22,25 @@ class IconBtn extends StatelessWidget { /// Creates button with [icon] different /// depends on [MaterialApp] or [CupertinoApp] ancestor. - const IconBtn({ - Key? key, - required this.icon, - this.onTap, - this.tooltip - }) : super(key: key); + const IconBtn({Key? key, required this.icon, this.onTap, this.tooltip}) + : super(key: key); @override Widget build(BuildContext context) { - bool isMaterial = Material.maybeOf(context) != null; + bool isMaterial = Material.maybeOf(context) != null; - return isMaterial - ? _materialBtn() - : _cupertinoBtn(); + return isMaterial ? _materialBtn() : _cupertinoBtn(); } - Widget _cupertinoBtn() => - CupertinoButton( + Widget _cupertinoBtn() => CupertinoButton( padding: const EdgeInsets.all(0.0), child: icon, onPressed: onTap, ); - Widget _materialBtn() => - IconButton( - icon: icon, - tooltip: tooltip ?? "", - onPressed: onTap, - ); + Widget _materialBtn() => IconButton( + icon: icon, + tooltip: tooltip ?? "", + onPressed: onTap, + ); } diff --git a/lib/src/month_navigation_row.dart b/lib/src/month_navigation_row.dart index 188f723..ad1f807 100644 --- a/lib/src/month_navigation_row.dart +++ b/lib/src/month_navigation_row.dart @@ -45,18 +45,18 @@ class MonthNavigationRow extends StatelessWidget { final Widget? title; /// Creates month navigation row. - const MonthNavigationRow({ - Key? key, - this.previousPageIconKey, - this.nextPageIconKey, - this.onNextMonthTapped, - this.onPreviousMonthTapped, - this.nextMonthTooltip, - this.previousMonthTooltip, - this.title, - required this.nextIcon, - required this.prevIcon - }) : super(key: key); + const MonthNavigationRow( + {Key? key, + this.previousPageIconKey, + this.nextPageIconKey, + this.onNextMonthTapped, + this.onPreviousMonthTapped, + this.nextMonthTooltip, + this.previousMonthTooltip, + this.title, + required this.nextIcon, + required this.prevIcon}) + : super(key: key); @override // ignore: prefer_expression_function_bodies diff --git a/lib/src/range_picker.dart b/lib/src/range_picker.dart index 10d2429..7d01054 100644 --- a/lib/src/range_picker.dart +++ b/lib/src/range_picker.dart @@ -1,5 +1,4 @@ import 'package:flutter/material.dart'; -import 'package:flutter/rendering.dart'; import 'date_period.dart'; import 'date_picker_keys.dart'; @@ -114,4 +113,4 @@ class RangePicker extends StatelessWidget { onMonthChanged: onMonthChanged, ); } -} \ No newline at end of file +} diff --git a/lib/src/styles/event_decoration.dart b/lib/src/styles/event_decoration.dart index 680c979..f3bc9bb 100644 --- a/lib/src/styles/event_decoration.dart +++ b/lib/src/styles/event_decoration.dart @@ -4,7 +4,6 @@ import '../day_picker.dart'; import '../range_picker.dart'; import '../week_picker.dart'; - /// Signature for function which is used to set set specific decoration for /// some days in [DayPicker], [WeekPicker] and [RangePicker]. /// @@ -14,11 +13,9 @@ import '../week_picker.dart'; /// * [RangePicker.eventDecorationBuilder] typedef EventDecorationBuilder = EventDecoration? Function(DateTime date); - /// Class to store styles for event (specific day in the date picker). @immutable class EventDecoration { - /// Cell decoration for the specific day in the date picker (event). final BoxDecoration? boxDecoration; @@ -32,4 +29,4 @@ class EventDecoration { /// and [RangePicker.eventDecorationBuilder] to set specific decoration for /// some days. const EventDecoration({this.boxDecoration, this.textStyle}); -} \ No newline at end of file +} diff --git a/lib/src/styles/layout_settings.dart b/lib/src/styles/layout_settings.dart index 4c0dc6e..aeea2b1 100644 --- a/lib/src/styles/layout_settings.dart +++ b/lib/src/styles/layout_settings.dart @@ -14,7 +14,7 @@ const double _kDayPickerRowHeight = 42.0; const int _kMaxDayPickerRowCount = 6; // A 31 day month that starts on Saturday. const double _kMonthPickerPortraitWidth = 330.0; const EdgeInsetsGeometry _kContentPadding = - EdgeInsets.symmetric(horizontal: 8.0); + EdgeInsets.symmetric(horizontal: 8.0); const EdgeInsetsGeometry _kCellContentMargin = EdgeInsets.all(0); /// Settings for the layout of the [DayPicker], [WeekPicker], [RangePicker] @@ -102,8 +102,8 @@ class _DayPickerGridDelegate extends SliverGridDelegate { final double _dayPickerRowHeight; final int _maxDayPickerRowCount; - const _DayPickerGridDelegate(this._dayPickerRowHeight, - this._maxDayPickerRowCount); + const _DayPickerGridDelegate( + this._dayPickerRowHeight, this._maxDayPickerRowCount); @override SliverGridLayout getLayout(SliverConstraints constraints) { diff --git a/lib/src/typedefs.dart b/lib/src/typedefs.dart index d361ea1..3f76e88 100644 --- a/lib/src/typedefs.dart +++ b/lib/src/typedefs.dart @@ -2,7 +2,6 @@ import 'range_picker.dart'; import 'unselectable_period_error.dart'; import 'week_picker.dart'; - /// Signature for function that can be used to handle incorrect selections. /// /// See also: diff --git a/lib/src/unselectable_period_error.dart b/lib/src/unselectable_period_error.dart index 938b09e..e46d96f 100644 --- a/lib/src/unselectable_period_error.dart +++ b/lib/src/unselectable_period_error.dart @@ -2,7 +2,6 @@ import 'date_period.dart'; import 'range_picker.dart'; import 'week_picker.dart'; - /// Exception thrown when selected period contains custom disabled days. class UnselectablePeriodException implements Exception { /// Dates inside selected period what can't be selected @@ -20,11 +19,10 @@ class UnselectablePeriodException implements Exception { UnselectablePeriodException(this.customDisabledDates, this.period); @override - String toString() => - "UnselectablePeriodException:" - " ${customDisabledDates.length} dates inside selected period " - "(${period.start} - ${period.end}) " - "can't be selected according custom rules (selectable pridicate). " - "Check 'customDisabledDates' property " - "to get entire list of such dates."; + String toString() => "UnselectablePeriodException:" + " ${customDisabledDates.length} dates inside selected period " + "(${period.start} - ${period.end}) " + "can't be selected according custom rules (selectable pridicate). " + "Check 'customDisabledDates' property " + "to get entire list of such dates."; } diff --git a/lib/src/utils.dart b/lib/src/utils.dart index 9c2fc9d..c157655 100644 --- a/lib/src/utils.dart +++ b/lib/src/utils.dart @@ -1,5 +1,7 @@ /// Bunch of useful functions for date pickers. class DatePickerUtils { + DatePickerUtils._internal(); + /// Returns if two objects have same year, month and day. /// Time doesn't matter. static bool sameDate(DateTime dateTimeOne, DateTime dateTimeTwo) => diff --git a/lib/src/week_picker.dart b/lib/src/week_picker.dart index db25b79..4acb274 100644 --- a/lib/src/week_picker.dart +++ b/lib/src/week_picker.dart @@ -1,5 +1,4 @@ import 'package:flutter/material.dart'; -import 'package:flutter/rendering.dart'; import 'date_period.dart'; import 'date_picker_keys.dart'; @@ -120,4 +119,4 @@ class WeekPicker extends StatelessWidget { onMonthChanged: onMonthChanged, ); } -} \ No newline at end of file +} diff --git a/pubspec.lock b/pubspec.lock index bf31818..a4bb21c 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -76,18 +76,18 @@ packages: dependency: transitive description: name: leak_tracker - sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a" + sha256: "3f87a60e8c63aecc975dda1ceedbc8f24de75f09e4856ea27daf8958f2f0ce05" url: "https://pub.dev" source: hosted - version: "10.0.4" + version: "10.0.5" leak_tracker_flutter_testing: dependency: transitive description: name: leak_tracker_flutter_testing - sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8" + sha256: "932549fb305594d82d7183ecd9fa93463e9914e1b67cacc34bc40906594a1806" url: "https://pub.dev" source: hosted - version: "3.0.3" + version: "3.0.5" leak_tracker_testing: dependency: transitive description: @@ -108,18 +108,18 @@ packages: dependency: transitive description: name: material_color_utilities - sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" + sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec url: "https://pub.dev" source: hosted - version: "0.8.0" + version: "0.11.1" meta: dependency: transitive description: name: meta - sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136" + sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7 url: "https://pub.dev" source: hosted - version: "1.12.0" + version: "1.15.0" path: dependency: transitive description: @@ -177,10 +177,10 @@ packages: dependency: transitive description: name: test_api - sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f" + sha256: "5b8a98dafc4d5c4c9c72d8b31ab2b23fc13422348d2997120294d3bac86b4ddb" url: "https://pub.dev" source: hosted - version: "0.7.0" + version: "0.7.2" vector_math: dependency: transitive description: @@ -193,10 +193,10 @@ packages: dependency: transitive description: name: vm_service - sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec" + sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d" url: "https://pub.dev" source: hosted - version: "14.2.1" + version: "14.2.5" sdks: dart: ">=3.3.0 <4.0.0" flutter: ">=3.18.0-18.0.pre.54" diff --git a/test/range_selectable_test.dart b/test/range_selectable_test.dart index 0e057f5..43eb940 100644 --- a/test/range_selectable_test.dart +++ b/test/range_selectable_test.dart @@ -2,7 +2,6 @@ import 'package:flutter_date_pickers/flutter_date_pickers.dart'; import 'package:flutter_date_pickers/src/day_type.dart'; import 'package:flutter_date_pickers/src/i_selectable_picker.dart'; import 'package:flutter_date_pickers/src/utils.dart'; - import 'package:flutter_test/flutter_test.dart'; void main() { @@ -48,7 +47,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()}"); } }); }); @@ -78,4 +78,4 @@ void main() { expect(selectableLogic.firstDate, startOfTheFirstDate); expect(selectableLogic.lastDate, endOfTheLastDate); }); -} \ No newline at end of file +} diff --git a/test/week_selectable_test.dart b/test/week_selectable_test.dart index 315e347..f162f8c 100644 --- a/test/week_selectable_test.dart +++ b/test/week_selectable_test.dart @@ -77,4 +77,4 @@ void main() { expect(selectableLogic.firstDate, startOfTheFirstDate); expect(selectableLogic.lastDate, endOfTheLastDate); }); -} \ No newline at end of file +}