From 08e62ef998af93a71877ba20a9b985cd535b05a3 Mon Sep 17 00:00:00 2001 From: Nikolas Rimikis Date: Tue, 28 Feb 2023 12:01:40 +0100 Subject: [PATCH 1/3] add linting --- analysis_options.yaml | 25 +++++++++++ example/pubspec.lock | 92 ++++++++++++++++++++++++++-------------- pubspec.lock | 97 +++++++++++++++++++++++++++++-------------- pubspec.yaml | 1 + 4 files changed, 152 insertions(+), 63 deletions(-) create mode 100644 analysis_options.yaml diff --git a/analysis_options.yaml b/analysis_options.yaml new file mode 100644 index 00000000..d7855022 --- /dev/null +++ b/analysis_options.yaml @@ -0,0 +1,25 @@ +# This file configures the analyzer to use the lint rule set from `package:lint` + +# include: package:lint/strict.yaml # For production apps +# include: package:lint/casual.yaml # For code samples, hackathons and other non-production code +include: package:lint/package.yaml # Use this for packages with public API + +# You might want to exclude auto-generated files from dart analysis +analyzer: + exclude: + #- '**.freezed.dart' + #- '**.g.dart' + +# You can customize the lint rules set to your own liking. A list of all rules +# can be found at https://dart-lang.github.io/linter/lints/options/options.html +linter: + rules: + # Util classes are awesome! + # avoid_classes_with_only_static_members: false + + # Make constructors the first thing in every class + # sort_constructors_first: true + + # Choose wisely, but you don't have to + # prefer_double_quotes: true + # prefer_single_quotes: true diff --git a/example/pubspec.lock b/example/pubspec.lock index 40582f4c..4a159ee5 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -5,49 +5,56 @@ packages: dependency: transitive description: name: async - url: "https://pub.dartlang.org" + sha256: bfe67ef28df125b7dddcea62755991f807aa39a2492a23e1550161692950bbe0 + url: "https://pub.dev" source: hosted - version: "2.9.0" + version: "2.10.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: e6a326c8af69605aec75ed6c187d06b349707a27fbff8222ca9cc2cff167975c + url: "https://pub.dev" source: hosted version: "1.2.1" clock: dependency: transitive description: name: clock - url: "https://pub.dartlang.org" + sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf + url: "https://pub.dev" source: hosted version: "1.1.1" collection: dependency: transitive description: name: collection - url: "https://pub.dartlang.org" + sha256: cfc915e6923fe5ce6e153b0723c753045de46de1b4d63771530504004a45fae0 + url: "https://pub.dev" source: hosted - version: "1.16.0" + version: "1.17.0" cupertino_icons: dependency: "direct main" description: name: cupertino_icons - url: "https://pub.dartlang.org" + sha256: caac504f942f41dfadcf45229ce8c47065b93919a12739f20d6173a883c5ec73 + url: "https://pub.dev" source: hosted version: "1.0.2" fake_async: dependency: transitive description: name: fake_async - url: "https://pub.dartlang.org" + sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78" + url: "https://pub.dev" source: hosted version: "1.3.1" flutter: @@ -64,42 +71,56 @@ packages: dependency: transitive description: name: intl - url: "https://pub.dartlang.org" + sha256: a3715e3bc90294e971cb7dc063fbf3cd9ee0ebf8604ffeafabd9e6f16abbdbe6 + url: "https://pub.dev" source: hosted version: "0.18.0" + js: + dependency: transitive + description: + name: js + sha256: "5528c2f391ededb7775ec1daa69e65a2d61276f7552de2b5f7b8d34ee9fd4ab7" + url: "https://pub.dev" + source: hosted + version: "0.6.5" matcher: dependency: transitive description: name: matcher - url: "https://pub.dartlang.org" + sha256: "16db949ceee371e9b99d22f88fa3a73c4e59fd0afed0bd25fc336eb76c198b72" + url: "https://pub.dev" source: hosted - version: "0.12.12" + version: "0.12.13" material_color_utilities: dependency: transitive description: name: material_color_utilities - url: "https://pub.dartlang.org" + sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724 + url: "https://pub.dev" source: hosted - version: "0.1.5" + version: "0.2.0" meta: dependency: transitive description: name: meta - url: "https://pub.dartlang.org" + sha256: "6c268b42ed578a53088d834796959e4a1814b5e9e164f147f580a386e5decf42" + url: "https://pub.dev" source: hosted version: "1.8.0" path: dependency: transitive description: name: path - url: "https://pub.dartlang.org" + sha256: db9d4f58c908a4ba5953fcee2ae317c94889433e5024c27ce74a37f94267945b + url: "https://pub.dev" source: hosted version: "1.8.2" simple_gesture_detector: dependency: transitive description: name: simple_gesture_detector - url: "https://pub.dartlang.org" + sha256: "86d08f85f1f58583b7b4b941d989f48ea6ce08c1724a1d10954a277c2ec36592" + url: "https://pub.dev" source: hosted version: "0.2.0" sky_engine: @@ -111,30 +132,34 @@ packages: dependency: transitive description: name: source_span - url: "https://pub.dartlang.org" + sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250 + url: "https://pub.dev" source: hosted - version: "1.9.0" + version: "1.9.1" stack_trace: dependency: transitive description: name: stack_trace - url: "https://pub.dartlang.org" + sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5 + url: "https://pub.dev" source: hosted - version: "1.10.0" + version: "1.11.0" stream_channel: dependency: transitive description: name: stream_channel - url: "https://pub.dartlang.org" + sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8" + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.1" string_scanner: dependency: transitive description: name: string_scanner - url: "https://pub.dartlang.org" + sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" + url: "https://pub.dev" source: hosted - version: "1.1.1" + version: "1.2.0" table_calendar: dependency: "direct main" description: @@ -146,23 +171,26 @@ packages: dependency: transitive description: name: term_glyph - url: "https://pub.dartlang.org" + sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 + url: "https://pub.dev" source: hosted version: "1.2.1" test_api: dependency: transitive description: name: test_api - url: "https://pub.dartlang.org" + sha256: ad540f65f92caa91bf21dfc8ffb8c589d6e4dc0c2267818b4cc2792857706206 + url: "https://pub.dev" source: hosted - version: "0.4.12" + version: "0.4.16" 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" sdks: - dart: ">=2.17.0-0 <3.0.0" + dart: ">=2.18.0 <3.0.0" flutter: ">=1.17.0" diff --git a/pubspec.lock b/pubspec.lock index f13096b0..eb4e05e8 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -5,42 +5,48 @@ packages: dependency: transitive description: name: async - url: "https://pub.dartlang.org" + sha256: bfe67ef28df125b7dddcea62755991f807aa39a2492a23e1550161692950bbe0 + url: "https://pub.dev" source: hosted - version: "2.9.0" + version: "2.10.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: e6a326c8af69605aec75ed6c187d06b349707a27fbff8222ca9cc2cff167975c + url: "https://pub.dev" source: hosted version: "1.2.1" clock: dependency: transitive description: name: clock - url: "https://pub.dartlang.org" + sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf + url: "https://pub.dev" source: hosted version: "1.1.1" collection: dependency: transitive description: name: collection - url: "https://pub.dartlang.org" + sha256: cfc915e6923fe5ce6e153b0723c753045de46de1b4d63771530504004a45fae0 + url: "https://pub.dev" source: hosted - version: "1.16.0" + version: "1.17.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.1" flutter: @@ -57,42 +63,64 @@ packages: dependency: "direct main" description: name: intl - url: "https://pub.dartlang.org" + sha256: a3715e3bc90294e971cb7dc063fbf3cd9ee0ebf8604ffeafabd9e6f16abbdbe6 + url: "https://pub.dev" source: hosted version: "0.18.0" + js: + dependency: transitive + description: + name: js + sha256: "5528c2f391ededb7775ec1daa69e65a2d61276f7552de2b5f7b8d34ee9fd4ab7" + url: "https://pub.dev" + source: hosted + version: "0.6.5" + lint: + dependency: "direct dev" + description: + name: lint + sha256: "3e9343b1cededcfb1e8b40d0dbd3592b7a1c6c0121545663a991433390c2bc97" + url: "https://pub.dev" + source: hosted + version: "2.0.1" matcher: dependency: transitive description: name: matcher - url: "https://pub.dartlang.org" + sha256: "16db949ceee371e9b99d22f88fa3a73c4e59fd0afed0bd25fc336eb76c198b72" + url: "https://pub.dev" source: hosted - version: "0.12.12" + version: "0.12.13" material_color_utilities: dependency: transitive description: name: material_color_utilities - url: "https://pub.dartlang.org" + sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724 + url: "https://pub.dev" source: hosted - version: "0.1.5" + version: "0.2.0" meta: dependency: transitive description: name: meta - url: "https://pub.dartlang.org" + sha256: "6c268b42ed578a53088d834796959e4a1814b5e9e164f147f580a386e5decf42" + url: "https://pub.dev" source: hosted version: "1.8.0" path: dependency: transitive description: name: path - url: "https://pub.dartlang.org" + sha256: db9d4f58c908a4ba5953fcee2ae317c94889433e5024c27ce74a37f94267945b + url: "https://pub.dev" source: hosted version: "1.8.2" simple_gesture_detector: dependency: "direct main" description: name: simple_gesture_detector - url: "https://pub.dartlang.org" + sha256: "86d08f85f1f58583b7b4b941d989f48ea6ce08c1724a1d10954a277c2ec36592" + url: "https://pub.dev" source: hosted version: "0.2.0" sky_engine: @@ -104,51 +132,58 @@ packages: dependency: transitive description: name: source_span - url: "https://pub.dartlang.org" + sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250 + url: "https://pub.dev" source: hosted - version: "1.9.0" + version: "1.9.1" stack_trace: dependency: transitive description: name: stack_trace - url: "https://pub.dartlang.org" + sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5 + url: "https://pub.dev" source: hosted - version: "1.10.0" + version: "1.11.0" stream_channel: dependency: transitive description: name: stream_channel - url: "https://pub.dartlang.org" + sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8" + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.1" string_scanner: dependency: transitive description: name: string_scanner - url: "https://pub.dartlang.org" + sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" + url: "https://pub.dev" source: hosted - version: "1.1.1" + 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.1" test_api: dependency: transitive description: name: test_api - url: "https://pub.dartlang.org" + sha256: ad540f65f92caa91bf21dfc8ffb8c589d6e4dc0c2267818b4cc2792857706206 + url: "https://pub.dev" source: hosted - version: "0.4.12" + version: "0.4.16" 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" sdks: - dart: ">=2.17.0-0 <3.0.0" + dart: ">=2.18.0 <3.0.0" flutter: ">=1.17.0" diff --git a/pubspec.yaml b/pubspec.yaml index f87cfdc8..a3822010 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -18,5 +18,6 @@ dependencies: dev_dependencies: flutter_test: sdk: flutter + lint: ^2.0.1 flutter: From 546bf7bd49855d0105d64bc2684c681fe39c6650 Mon Sep 17 00:00:00 2001 From: Nikolas Rimikis Date: Tue, 28 Feb 2023 15:33:20 +0100 Subject: [PATCH 2/3] fix lints --- lib/src/customization/calendar_builders.dart | 8 +- lib/src/customization/calendar_style.dart | 36 ++++----- lib/src/customization/days_of_week_style.dart | 6 +- lib/src/customization/header_style.dart | 8 +- lib/src/shared/utils.dart | 2 +- lib/src/table_calendar.dart | 60 ++++++++------- lib/src/table_calendar_base.dart | 35 ++++----- lib/src/widgets/calendar_core.dart | 35 ++++----- lib/src/widgets/calendar_header.dart | 13 ++-- lib/src/widgets/calendar_page.dart | 35 +++++---- lib/src/widgets/cell_content.dart | 10 +-- lib/src/widgets/custom_icon_button.dart | 6 +- lib/src/widgets/format_button.dart | 6 +- test/calendar_header_test.dart | 6 +- test/calendar_page_test.dart | 10 +-- test/cell_content_test.dart | 2 +- test/common.dart | 2 +- test/custom_icon_button_test.dart | 2 +- test/format_button_test.dart | 16 ++-- test/table_calendar_base_test.dart | 10 +-- test/table_calendar_test.dart | 74 +++++++++---------- 21 files changed, 180 insertions(+), 202 deletions(-) diff --git a/lib/src/customization/calendar_builders.dart b/lib/src/customization/calendar_builders.dart index af69c23e..bfc30b8d 100644 --- a/lib/src/customization/calendar_builders.dart +++ b/lib/src/customization/calendar_builders.dart @@ -3,24 +3,24 @@ import 'package:flutter/widgets.dart'; -import '../shared/utils.dart' show DayBuilder, FocusedDayBuilder; +import 'package:table_calendar/src/shared/utils.dart' show DayBuilder, FocusedDayBuilder; /// Signature for a function that creates a single event marker for a given `day`. /// Contains a single `event` associated with that `day`. typedef SingleMarkerBuilder = Widget? Function( - BuildContext context, DateTime day, T event); + BuildContext context, DateTime day, T event,); /// Signature for a function that creates an event marker for a given `day`. /// Contains a list of `events` associated with that `day`. typedef MarkerBuilder = Widget? Function( - BuildContext context, DateTime day, List events); + BuildContext context, DateTime day, List events,); /// Signature for a function that creates a background highlight for a given `day`. /// /// Used for highlighting current range selection. /// Contains a value determining if the given `day` falls within the selected range. typedef HighlightBuilder = Widget? Function( - BuildContext context, DateTime day, bool isWithinRange); + BuildContext context, DateTime day, bool isWithinRange,); /// Class containing all custom builders for `TableCalendar`. class CalendarBuilders { diff --git a/lib/src/customization/calendar_style.dart b/lib/src/customization/calendar_style.dart index c052540b..52b2404a 100644 --- a/lib/src/customization/calendar_style.dart +++ b/lib/src/customization/calendar_style.dart @@ -165,68 +165,68 @@ class CalendarStyle { this.markersAlignment = Alignment.bottomCenter, this.markersMaxCount = 4, this.cellMargin = const EdgeInsets.all(6.0), - this.cellPadding = const EdgeInsets.all(0), + this.cellPadding = EdgeInsets.zero, this.cellAlignment = Alignment.center, this.markersOffset = const PositionedOffset(), this.rangeHighlightColor = const Color(0xFFBBDDFF), this.markerDecoration = const BoxDecoration( - color: const Color(0xFF263238), + color: Color(0xFF263238), shape: BoxShape.circle, ), this.todayTextStyle = const TextStyle( - color: const Color(0xFFFAFAFA), + color: Color(0xFFFAFAFA), fontSize: 16.0, ), // this.todayDecoration = const BoxDecoration( - color: const Color(0xFF9FA8DA), + color: Color(0xFF9FA8DA), shape: BoxShape.circle, ), this.selectedTextStyle = const TextStyle( - color: const Color(0xFFFAFAFA), + color: Color(0xFFFAFAFA), fontSize: 16.0, ), this.selectedDecoration = const BoxDecoration( - color: const Color(0xFF5C6BC0), + color: Color(0xFF5C6BC0), shape: BoxShape.circle, ), this.rangeStartTextStyle = const TextStyle( - color: const Color(0xFFFAFAFA), + color: Color(0xFFFAFAFA), fontSize: 16.0, ), this.rangeStartDecoration = const BoxDecoration( - color: const Color(0xFF6699FF), + color: Color(0xFF6699FF), shape: BoxShape.circle, ), this.rangeEndTextStyle = const TextStyle( - color: const Color(0xFFFAFAFA), + color: Color(0xFFFAFAFA), fontSize: 16.0, ), this.rangeEndDecoration = const BoxDecoration( - color: const Color(0xFF6699FF), + color: Color(0xFF6699FF), shape: BoxShape.circle, ), this.withinRangeTextStyle = const TextStyle(), this.withinRangeDecoration = const BoxDecoration(shape: BoxShape.circle), - this.outsideTextStyle = const TextStyle(color: const Color(0xFFAEAEAE)), + this.outsideTextStyle = const TextStyle(color: Color(0xFFAEAEAE)), this.outsideDecoration = const BoxDecoration(shape: BoxShape.circle), - this.disabledTextStyle = const TextStyle(color: const Color(0xFFBFBFBF)), + this.disabledTextStyle = const TextStyle(color: Color(0xFFBFBFBF)), this.disabledDecoration = const BoxDecoration(shape: BoxShape.circle), - this.holidayTextStyle = const TextStyle(color: const Color(0xFF5C6BC0)), + this.holidayTextStyle = const TextStyle(color: Color(0xFF5C6BC0)), this.holidayDecoration = const BoxDecoration( - border: const Border.fromBorderSide( - const BorderSide(color: const Color(0xFF9FA8DA), width: 1.4), + border: Border.fromBorderSide( + BorderSide(color: Color(0xFF9FA8DA), width: 1.4), ), shape: BoxShape.circle, ), - this.weekendTextStyle = const TextStyle(color: const Color(0xFF5A5A5A)), + this.weekendTextStyle = const TextStyle(color: Color(0xFF5A5A5A)), this.weekendDecoration = const BoxDecoration(shape: BoxShape.circle), this.weekNumberTextStyle = - const TextStyle(fontSize: 12, color: const Color(0xFFBFBFBF)), + const TextStyle(fontSize: 12, color: Color(0xFFBFBFBF)), this.defaultTextStyle = const TextStyle(), this.defaultDecoration = const BoxDecoration(shape: BoxShape.circle), this.rowDecoration = const BoxDecoration(), this.tableBorder = const TableBorder(), - this.tablePadding = const EdgeInsets.all(0), + this.tablePadding = EdgeInsets.zero, }); } diff --git a/lib/src/customization/days_of_week_style.dart b/lib/src/customization/days_of_week_style.dart index b379ba94..a3ac65d9 100644 --- a/lib/src/customization/days_of_week_style.dart +++ b/lib/src/customization/days_of_week_style.dart @@ -3,7 +3,7 @@ import 'package:flutter/widgets.dart'; -import '../shared/utils.dart' show TextFormatter; +import 'package:table_calendar/src/shared/utils.dart' show TextFormatter; /// Class containing styling for `TableCalendar`'s days of week panel. class DaysOfWeekStyle { @@ -30,7 +30,7 @@ class DaysOfWeekStyle { const DaysOfWeekStyle({ this.dowTextFormatter, this.decoration = const BoxDecoration(), - this.weekdayStyle = const TextStyle(color: const Color(0xFF4F4F4F)), - this.weekendStyle = const TextStyle(color: const Color(0xFF6A6A6A)), + this.weekdayStyle = const TextStyle(color: Color(0xFF4F4F4F)), + this.weekendStyle = const TextStyle(color: Color(0xFF6A6A6A)), }); } diff --git a/lib/src/customization/header_style.dart b/lib/src/customization/header_style.dart index 3fcc1089..3ebf47e4 100644 --- a/lib/src/customization/header_style.dart +++ b/lib/src/customization/header_style.dart @@ -3,7 +3,7 @@ import 'package:flutter/material.dart'; -import '../shared/utils.dart' show TextFormatter; +import 'package:table_calendar/src/shared/utils.dart' show TextFormatter; /// Class containing styling and configuration of `TableCalendar`'s header. class HeaderStyle { @@ -88,10 +88,10 @@ class HeaderStyle { this.titleTextStyle = const TextStyle(fontSize: 17.0), this.formatButtonTextStyle = const TextStyle(fontSize: 14.0), this.formatButtonDecoration = const BoxDecoration( - border: const Border.fromBorderSide(BorderSide()), - borderRadius: const BorderRadius.all(Radius.circular(12.0)), + border: Border.fromBorderSide(BorderSide()), + borderRadius: BorderRadius.all(Radius.circular(12.0)), ), - this.headerMargin = const EdgeInsets.all(0.0), + this.headerMargin = EdgeInsets.zero, this.headerPadding = const EdgeInsets.symmetric(vertical: 8.0), this.formatButtonPadding = const EdgeInsets.symmetric(horizontal: 10.0, vertical: 4.0), diff --git a/lib/src/shared/utils.dart b/lib/src/shared/utils.dart index accc4497..39d363ab 100644 --- a/lib/src/shared/utils.dart +++ b/lib/src/shared/utils.dart @@ -9,7 +9,7 @@ typedef DayBuilder = Widget? Function(BuildContext context, DateTime day); /// Signature for a function that creates a widget for a given `day`. /// Additionally, contains the currently focused day. typedef FocusedDayBuilder = Widget? Function( - BuildContext context, DateTime day, DateTime focusedDay); + BuildContext context, DateTime day, DateTime focusedDay,); /// Signature for a function returning text that can be localized and formatted with `DateFormat`. typedef TextFormatter = String Function(DateTime date, dynamic locale); diff --git a/lib/src/table_calendar.dart b/lib/src/table_calendar.dart index bcd52656..5fc6454f 100644 --- a/lib/src/table_calendar.dart +++ b/lib/src/table_calendar.dart @@ -1,29 +1,31 @@ // Copyright 2019 Aleksander Woźniak // SPDX-License-Identifier: Apache-2.0 +// ignore_for_file: library_private_types_in_public_api + import 'dart:math'; import 'package:flutter/widgets.dart'; import 'package:intl/intl.dart'; import 'package:simple_gesture_detector/simple_gesture_detector.dart'; -import 'customization/calendar_builders.dart'; -import 'customization/calendar_style.dart'; -import 'customization/days_of_week_style.dart'; -import 'customization/header_style.dart'; -import 'shared/utils.dart'; -import 'table_calendar_base.dart'; -import 'widgets/calendar_header.dart'; -import 'widgets/cell_content.dart'; +import 'package:table_calendar/src/customization/calendar_builders.dart'; +import 'package:table_calendar/src/customization/calendar_style.dart'; +import 'package:table_calendar/src/customization/days_of_week_style.dart'; +import 'package:table_calendar/src/customization/header_style.dart'; +import 'package:table_calendar/src/shared/utils.dart'; +import 'package:table_calendar/src/table_calendar_base.dart'; +import 'package:table_calendar/src/widgets/calendar_header.dart'; +import 'package:table_calendar/src/widgets/cell_content.dart'; /// Signature for `onDaySelected` callback. Contains the selected day and focused day. typedef OnDaySelected = void Function( - DateTime selectedDay, DateTime focusedDay); + DateTime selectedDay, DateTime focusedDay,); /// Signature for `onRangeSelected` callback. /// Contains start and end of the selected range, as well as currently focused day. typedef OnRangeSelected = void Function( - DateTime? start, DateTime? end, DateTime focusedDay); + DateTime? start, DateTime? end, DateTime focusedDay,); /// Modes that range selection can operate in. enum RangeSelectionMode { disabled, toggledOff, toggledOn, enforced } @@ -206,7 +208,7 @@ class TableCalendar extends StatefulWidget { /// Creates a `TableCalendar` widget. TableCalendar({ - Key? key, + super.key, required DateTime focusedDay, required DateTime firstDay, required DateTime lastDay, @@ -263,14 +265,12 @@ class TableCalendar extends StatefulWidget { }) : assert(availableCalendarFormats.keys.contains(calendarFormat)), assert(availableCalendarFormats.length <= CalendarFormat.values.length), assert(weekendDays.isNotEmpty - ? weekendDays.every( - (day) => day >= DateTime.monday && day <= DateTime.sunday) - : true), + && weekendDays.every( + (day) => day >= DateTime.monday && day <= DateTime.sunday,),), focusedDay = normalizeDate(focusedDay), firstDay = normalizeDate(firstDay), lastDay = normalizeDate(lastDay), - currentDay = currentDay ?? DateTime.now(), - super(key: key); + currentDay = currentDay ?? DateTime.now(); @override _TableCalendarState createState() => _TableCalendarState(); @@ -512,11 +512,10 @@ class _TableCalendarState extends State> { weekNumbersVisible: widget.weekNumbersVisible, weekNumberBuilder: (BuildContext context, DateTime day) { final weekNumber = _calculateWeekNumber(day); - Widget? cell = widget.calendarBuilders.weekNumberBuilder + final cell = widget.calendarBuilders.weekNumberBuilder ?.call(context, weekNumber); - if (cell == null) { - cell = Padding( + return cell ?? Padding( padding: const EdgeInsets.symmetric(horizontal: 4), child: Center( child: Text( @@ -525,9 +524,6 @@ class _TableCalendarState extends State> { ), ), ); - } - - return cell; }, dowBuilder: (BuildContext context, DateTime day) { Widget? dowCell = @@ -619,7 +615,7 @@ class _TableCalendarState extends State> { final isDisabled = _isDayDisabled(day); final isWeekend = _isWeekend(day, weekendDays: widget.weekendDays); - Widget content = CellContent( + final content = CellContent( key: ValueKey('CellContent-${day.year}-${day.month}-${day.day}'), day: day, focusedDay: focusedDay, @@ -686,10 +682,10 @@ class _TableCalendarState extends State> { return Stack( alignment: widget.calendarStyle.markersAlignment, - children: children, clipBehavior: widget.calendarStyle.canMarkersOverflow ? Clip.none : Clip.hardEdge, + children: children, ); }, ); @@ -715,7 +711,7 @@ class _TableCalendarState extends State> { int _dayOfYear(DateTime date) { return normalizeDate(date) - .difference(DateTime.utc(date.year, 1, 1)) + .difference(DateTime.utc(date.year)) .inDays + 1; } @@ -739,19 +735,21 @@ class _TableCalendarState extends State> { } bool _isDayAvailable(DateTime day) { - return widget.enabledDayPredicate == null - ? true - : widget.enabledDayPredicate!(day); + if (widget.enabledDayPredicate == null){ + return true; + } + + return widget.enabledDayPredicate!(day); } DateTime _firstDayOfMonth(DateTime month) { - return DateTime.utc(month.year, month.month, 1); + return DateTime.utc(month.year, month.month); } DateTime _lastDayOfMonth(DateTime month) { final date = month.month < 12 - ? DateTime.utc(month.year, month.month + 1, 1) - : DateTime.utc(month.year + 1, 1, 1); + ? DateTime.utc(month.year, month.month + 1) + : DateTime.utc(month.year + 1); return date.subtract(const Duration(days: 1)); } diff --git a/lib/src/table_calendar_base.dart b/lib/src/table_calendar_base.dart index 659a43a7..71429a18 100644 --- a/lib/src/table_calendar_base.dart +++ b/lib/src/table_calendar_base.dart @@ -1,11 +1,13 @@ // Copyright 2019 Aleksander Woźniak // SPDX-License-Identifier: Apache-2.0 +// ignore_for_file: library_private_types_in_public_api + import 'package:flutter/material.dart'; import 'package:simple_gesture_detector/simple_gesture_detector.dart'; -import 'shared/utils.dart'; -import 'widgets/calendar_core.dart'; +import 'package:table_calendar/src/shared/utils.dart'; +import 'package:table_calendar/src/widgets/calendar_core.dart'; class TableCalendarBase extends StatefulWidget { final DateTime firstDay; @@ -38,7 +40,7 @@ class TableCalendarBase extends StatefulWidget { final void Function(PageController pageController)? onCalendarCreated; TableCalendarBase({ - Key? key, + super.key, required this.firstDay, required this.lastDay, required this.focusedDay, @@ -76,8 +78,7 @@ class TableCalendarBase extends StatefulWidget { this.onCalendarCreated, }) : assert(!dowVisible || (dowHeight != null && dowBuilder != null)), assert(isSameDay(focusedDay, firstDay) || focusedDay.isAfter(firstDay)), - assert(isSameDay(focusedDay, lastDay) || focusedDay.isBefore(lastDay)), - super(key: key); + assert(isSameDay(focusedDay, lastDay) || focusedDay.isBefore(lastDay)); @override _TableCalendarBaseState createState() => _TableCalendarBaseState(); @@ -99,7 +100,7 @@ class _TableCalendarBaseState extends State { _pageHeight = ValueNotifier(_getPageHeight(rowCount)); final initialPage = _calculateFocusedPage( - widget.calendarFormat, widget.firstDay, _focusedDay); + widget.calendarFormat, widget.firstDay, _focusedDay,); _pageController = PageController(initialPage: initialPage); widget.onCalendarCreated?.call(_pageController); @@ -147,10 +148,10 @@ class _TableCalendarBaseState extends State { void _updatePage({bool shouldAnimate = false}) { final currentIndex = _calculateFocusedPage( - widget.calendarFormat, widget.firstDay, _focusedDay); + widget.calendarFormat, widget.firstDay, _focusedDay,); final endIndex = _calculateFocusedPage( - widget.calendarFormat, widget.firstDay, widget.lastDay); + widget.calendarFormat, widget.firstDay, widget.lastDay,); if (currentIndex != _previousIndex || currentIndex == 0 || @@ -209,8 +210,8 @@ class _TableCalendarBaseState extends State { constraints: constraints, pageController: _pageController, scrollPhysics: _canScrollHorizontally - ? PageScrollPhysics() - : NeverScrollableScrollPhysics(), + ? const PageScrollPhysics() + : const NeverScrollableScrollPhysics(), firstDay: widget.firstDay, lastDay: widget.lastDay, startingDayOfWeek: widget.startingDayOfWeek, @@ -265,7 +266,7 @@ class _TableCalendarBaseState extends State { } int _calculateFocusedPage( - CalendarFormat format, DateTime startDay, DateTime focusedDay) { + CalendarFormat format, DateTime startDay, DateTime focusedDay,) { switch (format) { case CalendarFormat.month: return _getMonthCount(startDay, focusedDay); @@ -319,12 +320,12 @@ class _TableCalendarBaseState extends State { } int _getDaysAfter(DateTime lastDay) { - int invertedStartingWeekday = + final invertedStartingWeekday = 8 - getWeekdayNumber(widget.startingDayOfWeek); - int daysAfter = 7 - ((lastDay.weekday + invertedStartingWeekday) % 7); + final daysAfter = 7 - ((lastDay.weekday + invertedStartingWeekday) % 7); if (daysAfter == 7) { - daysAfter = 0; + return 0; } return daysAfter; @@ -336,13 +337,13 @@ class _TableCalendarBaseState extends State { } DateTime _firstDayOfMonth(DateTime month) { - return DateTime.utc(month.year, month.month, 1); + return DateTime.utc(month.year, month.month); } DateTime _lastDayOfMonth(DateTime month) { final date = month.month < 12 - ? DateTime.utc(month.year, month.month + 1, 1) - : DateTime.utc(month.year + 1, 1, 1); + ? DateTime.utc(month.year, month.month + 1) + : DateTime.utc(month.year + 1); return date.subtract(const Duration(days: 1)); } } diff --git a/lib/src/widgets/calendar_core.dart b/lib/src/widgets/calendar_core.dart index d196296f..ceb83e3d 100644 --- a/lib/src/widgets/calendar_core.dart +++ b/lib/src/widgets/calendar_core.dart @@ -3,11 +3,9 @@ import 'package:flutter/material.dart'; -import '../shared/utils.dart'; -import 'calendar_page.dart'; +import 'package:table_calendar/src/shared/utils.dart'; +import 'package:table_calendar/src/widgets/calendar_page.dart'; -typedef _OnCalendarPageChanged = void Function( - int pageIndex, DateTime focusedDay); class CalendarCore extends StatelessWidget { final DateTime? focusedDay; @@ -31,10 +29,10 @@ class CalendarCore extends StatelessWidget { final StartingDayOfWeek startingDayOfWeek; final PageController? pageController; final ScrollPhysics? scrollPhysics; - final _OnCalendarPageChanged onPageChanged; + final void Function(int, DateTime) onPageChanged; const CalendarCore({ - Key? key, + super.key, this.dowBuilder, required this.dayBuilder, required this.onPageChanged, @@ -57,8 +55,7 @@ class CalendarCore extends StatelessWidget { this.tableBorder, this.tablePadding, this.scrollPhysics, - }) : assert(!dowVisible || (dowHeight != null && dowBuilder != null)), - super(key: key); + }) : assert(!dowVisible || (dowHeight != null && dowBuilder != null)); @override Widget build(BuildContext context) { @@ -158,7 +155,7 @@ class CalendarCore extends StatelessWidget { } DateTime _getFocusedDay( - CalendarFormat format, DateTime prevFocusedDay, int pageIndex) { + CalendarFormat format, DateTime prevFocusedDay, int pageIndex,) { if (pageIndex == previousIndex) { return prevFocusedDay; } @@ -172,11 +169,11 @@ class CalendarCore extends StatelessWidget { break; case CalendarFormat.twoWeeks: day = DateTime.utc(prevFocusedDay.year, prevFocusedDay.month, - prevFocusedDay.day + pageDif * 14); + prevFocusedDay.day + pageDif * 14,); break; case CalendarFormat.week: day = DateTime.utc(prevFocusedDay.year, prevFocusedDay.month, - prevFocusedDay.day + pageDif * 7); + prevFocusedDay.day + pageDif * 7,); break; } @@ -198,11 +195,11 @@ class CalendarCore extends StatelessWidget { break; case CalendarFormat.twoWeeks: day = DateTime.utc( - firstDay.year, firstDay.month, firstDay.day + pageIndex * 14); + firstDay.year, firstDay.month, firstDay.day + pageIndex * 14,); break; case CalendarFormat.week: day = DateTime.utc( - firstDay.year, firstDay.month, firstDay.day + pageIndex * 7); + firstDay.year, firstDay.month, firstDay.day + pageIndex * 7,); break; } @@ -273,13 +270,13 @@ class CalendarCore extends StatelessWidget { } DateTime _firstDayOfMonth(DateTime month) { - return DateTime.utc(month.year, month.month, 1); + return DateTime.utc(month.year, month.month); } DateTime _lastDayOfMonth(DateTime month) { final date = month.month < 12 - ? DateTime.utc(month.year, month.month + 1, 1) - : DateTime.utc(month.year + 1, 1, 1); + ? DateTime.utc(month.year, month.month + 1) + : DateTime.utc(month.year + 1); return date.subtract(const Duration(days: 1)); } @@ -308,11 +305,11 @@ class CalendarCore extends StatelessWidget { } int _getDaysAfter(DateTime lastDay) { - int invertedStartingWeekday = 8 - getWeekdayNumber(startingDayOfWeek); + final invertedStartingWeekday = 8 - getWeekdayNumber(startingDayOfWeek); - int daysAfter = 7 - ((lastDay.weekday + invertedStartingWeekday) % 7); + final daysAfter = 7 - ((lastDay.weekday + invertedStartingWeekday) % 7); if (daysAfter == 7) { - daysAfter = 0; + return 0; } return daysAfter; diff --git a/lib/src/widgets/calendar_header.dart b/lib/src/widgets/calendar_header.dart index cce74329..903e1791 100644 --- a/lib/src/widgets/calendar_header.dart +++ b/lib/src/widgets/calendar_header.dart @@ -4,10 +4,10 @@ import 'package:flutter/widgets.dart'; import 'package:intl/intl.dart'; -import '../customization/header_style.dart'; -import '../shared/utils.dart' show CalendarFormat, DayBuilder; -import 'custom_icon_button.dart'; -import 'format_button.dart'; +import 'package:table_calendar/src/customization/header_style.dart'; +import 'package:table_calendar/src/shared/utils.dart' show CalendarFormat, DayBuilder; +import 'package:table_calendar/src/widgets/custom_icon_button.dart'; +import 'package:table_calendar/src/widgets/format_button.dart'; class CalendarHeader extends StatelessWidget { final dynamic locale; @@ -23,7 +23,7 @@ class CalendarHeader extends StatelessWidget { final DayBuilder? headerTitleBuilder; const CalendarHeader({ - Key? key, + super.key, this.locale, required this.focusedMonth, required this.calendarFormat, @@ -35,7 +35,7 @@ class CalendarHeader extends StatelessWidget { required this.onFormatButtonTap, required this.availableCalendarFormats, this.headerTitleBuilder, - }) : super(key: key); + }); @override Widget build(BuildContext context) { @@ -47,7 +47,6 @@ class CalendarHeader extends StatelessWidget { margin: headerStyle.headerMargin, padding: headerStyle.headerPadding, child: Row( - mainAxisSize: MainAxisSize.max, children: [ if (headerStyle.leftChevronVisible) CustomIconButton( diff --git a/lib/src/widgets/calendar_page.dart b/lib/src/widgets/calendar_page.dart index a13cb62b..470b9f9f 100644 --- a/lib/src/widgets/calendar_page.dart +++ b/lib/src/widgets/calendar_page.dart @@ -17,7 +17,7 @@ class CalendarPage extends StatelessWidget { final double? dowHeight; const CalendarPage({ - Key? key, + super.key, required this.visibleDays, this.dowBuilder, required this.dayBuilder, @@ -30,8 +30,7 @@ class CalendarPage extends StatelessWidget { this.weekNumberVisible = false, this.dowHeight, }) : assert(!dowVisible || (dowHeight != null && dowBuilder != null)), - assert(!weekNumberVisible || weekNumberBuilder != null), - super(key: key); + assert(!weekNumberVisible || weekNumberBuilder != null); @override Widget build(BuildContext context) { @@ -61,11 +60,12 @@ class CalendarPage extends StatelessWidget { return Column( children: [ if (dowVisible) SizedBox(height: dowHeight ?? 0), - ...List.generate(rowAmount, (index) => index * 7) - .map((index) => Expanded( - child: weekNumberBuilder!(context, visibleDays[index]), - )) - .toList() + ...List.generate( + rowAmount, + (index) => Expanded( + child: weekNumberBuilder!(context, visibleDays[index * 7]), + ), + ) ], ); } @@ -76,21 +76,20 @@ class CalendarPage extends StatelessWidget { children: List.generate( 7, (index) => dowBuilder!(context, visibleDays[index]), - ).toList(), + ), ); } List _buildCalendarDays(BuildContext context) { final rowAmount = visibleDays.length ~/ 7; - return List.generate(rowAmount, (index) => index * 7) - .map((index) => TableRow( - decoration: rowDecoration, - children: List.generate( - 7, - (id) => dayBuilder(context, visibleDays[index + id]), - ), - )) - .toList(); + return List.generate(rowAmount, (index) => TableRow( + decoration: rowDecoration, + children: List.generate( + 7, + (id) => dayBuilder(context, visibleDays[index * 7 + id]), + ), + ), + ); } } diff --git a/lib/src/widgets/cell_content.dart b/lib/src/widgets/cell_content.dart index eb75716c..89fd7311 100644 --- a/lib/src/widgets/cell_content.dart +++ b/lib/src/widgets/cell_content.dart @@ -4,8 +4,8 @@ import 'package:flutter/widgets.dart'; import 'package:intl/intl.dart'; -import '../customization/calendar_builders.dart'; -import '../customization/calendar_style.dart'; +import 'package:table_calendar/src/customization/calendar_builders.dart'; +import 'package:table_calendar/src/customization/calendar_style.dart'; class CellContent extends StatelessWidget { final DateTime day; @@ -25,7 +25,7 @@ class CellContent extends StatelessWidget { final CalendarBuilders calendarBuilders; const CellContent({ - Key? key, + super.key, required this.day, required this.focusedDay, required this.calendarStyle, @@ -41,7 +41,7 @@ class CellContent extends StatelessWidget { required this.isHoliday, required this.isWeekend, this.locale, - }) : super(key: key); + }); @override Widget build(BuildContext context) { @@ -64,7 +64,7 @@ class CellContent extends StatelessWidget { final margin = calendarStyle.cellMargin; final padding = calendarStyle.cellPadding; final alignment = calendarStyle.cellAlignment; - final duration = const Duration(milliseconds: 250); + const duration = Duration(milliseconds: 250); if (isDisabled) { cell = calendarBuilders.disabledBuilder?.call(context, day, focusedDay) ?? diff --git a/lib/src/widgets/custom_icon_button.dart b/lib/src/widgets/custom_icon_button.dart index 9e652c60..0b31b98a 100644 --- a/lib/src/widgets/custom_icon_button.dart +++ b/lib/src/widgets/custom_icon_button.dart @@ -12,12 +12,12 @@ class CustomIconButton extends StatelessWidget { final EdgeInsets padding; const CustomIconButton({ - Key? key, + super.key, required this.icon, required this.onTap, - this.margin = const EdgeInsets.all(0.0), + this.margin = EdgeInsets.zero, this.padding = const EdgeInsets.all(8.0), - }) : super(key: key); + }); @override Widget build(BuildContext context) { diff --git a/lib/src/widgets/format_button.dart b/lib/src/widgets/format_button.dart index 1c11c643..e8b03f49 100644 --- a/lib/src/widgets/format_button.dart +++ b/lib/src/widgets/format_button.dart @@ -5,7 +5,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; -import '../shared/utils.dart' show CalendarFormat; +import 'package:table_calendar/src/shared/utils.dart' show CalendarFormat; class FormatButton extends StatelessWidget { final CalendarFormat calendarFormat; @@ -17,7 +17,7 @@ class FormatButton extends StatelessWidget { final Map availableCalendarFormats; const FormatButton({ - Key? key, + super.key, required this.calendarFormat, required this.onTap, required this.textStyle, @@ -25,7 +25,7 @@ class FormatButton extends StatelessWidget { required this.padding, required this.showsNextFormat, required this.availableCalendarFormats, - }) : super(key: key); + }); @override Widget build(BuildContext context) { diff --git a/test/calendar_header_test.dart b/test/calendar_header_test.dart index ad91c8af..0df34d6d 100644 --- a/test/calendar_header_test.dart +++ b/test/calendar_header_test.dart @@ -124,7 +124,7 @@ void main() { (tester) async { await tester.pumpWidget( setupTestWidget( - headerStyle: HeaderStyle( + headerStyle: const HeaderStyle( leftChevronVisible: false, ), ), @@ -150,7 +150,7 @@ void main() { (tester) async { await tester.pumpWidget( setupTestWidget( - headerStyle: HeaderStyle( + headerStyle: const HeaderStyle( rightChevronVisible: false, ), ), @@ -190,7 +190,7 @@ void main() { (tester) async { await tester.pumpWidget( setupTestWidget( - headerStyle: HeaderStyle(formatButtonVisible: false), + headerStyle: const HeaderStyle(formatButtonVisible: false), ), ); diff --git a/test/calendar_page_test.dart b/test/calendar_page_test.dart index f9d15020..78b0ebda 100644 --- a/test/calendar_page_test.dart +++ b/test/calendar_page_test.dart @@ -57,7 +57,6 @@ void main() { dayBuilder: (context, day) { return Text('${day.day}'); }, - dowVisible: true, dowBuilder: (context, day) { return Text('${day.weekday}'); }, @@ -67,7 +66,7 @@ void main() { ); final expectedCellCount = visibleDays.length; - final expectedDowLabels = 7; + const expectedDowLabels = 7; expect( find.byType(Text), @@ -87,11 +86,10 @@ void main() { dayBuilder: (context, day) { return Text('${day.day}'); }, - dowVisible: true, ), ), ); - }, throwsAssertionError); + }, throwsAssertionError,); }, ); @@ -105,7 +103,6 @@ void main() { dayBuilder: (context, day) { return Text('${day.day}'); }, - dowVisible: true, dowBuilder: (context, day) { return Text('${day.weekday}'); }, @@ -130,7 +127,6 @@ void main() { dayBuilder: (context, day) { return Text('${day.day}'); }, - dowVisible: true, dowBuilder: (context, day) { return Text('${day.weekday}'); }, @@ -140,7 +136,7 @@ void main() { return Text(day.weekday.toString()); }, ), - )); + ),); expect( find.byType(Column), diff --git a/test/cell_content_test.dart b/test/cell_content_test.dart index 514c129d..dc1106d8 100644 --- a/test/cell_content_test.dart +++ b/test/cell_content_test.dart @@ -20,7 +20,7 @@ Widget setupTestWidget( bool isHoliday = false, bool isTodayHighlighted = true, }) { - final calendarStyle = CalendarStyle(); + const calendarStyle = CalendarStyle(); return Directionality( textDirection: TextDirection.ltr, diff --git a/test/common.dart b/test/common.dart index e351cea2..7e869196 100644 --- a/test/common.dart +++ b/test/common.dart @@ -8,7 +8,7 @@ ValueKey dateToKey(DateTime date, {String prefix = ''}) { return ValueKey('$prefix${date.year}-${date.month}-${date.day}'); } -const calendarFormatMap = const { +const calendarFormatMap = { CalendarFormat.month: 'Month', CalendarFormat.twoWeeks: 'Two weeks', CalendarFormat.week: 'week', diff --git a/test/custom_icon_button_test.dart b/test/custom_icon_button_test.dart index b608f978..de53539b 100644 --- a/test/custom_icon_button_test.dart +++ b/test/custom_icon_button_test.dart @@ -21,7 +21,7 @@ void main() { await tester.pumpWidget( setupTestWidget( CustomIconButton( - icon: Icon(Icons.chevron_left), + icon: const Icon(Icons.chevron_left), onTap: () { buttonTapped = true; }, diff --git a/test/format_button_test.dart b/test/format_button_test.dart index d562260d..61c4bdeb 100644 --- a/test/format_button_test.dart +++ b/test/format_button_test.dart @@ -20,7 +20,7 @@ void main() { testWidgets( 'Initial format month returns twoWeeks when tapped', (tester) async { - final headerStyle = HeaderStyle(); + const headerStyle = HeaderStyle(); CalendarFormat? calendarFormat; await tester.pumpWidget( @@ -51,7 +51,7 @@ void main() { testWidgets( 'Initial format twoWeeks returns week when tapped', (tester) async { - final headerStyle = HeaderStyle(); + const headerStyle = HeaderStyle(); CalendarFormat? calendarFormat; await tester.pumpWidget( @@ -82,7 +82,7 @@ void main() { testWidgets( 'Initial format week return month when tapped', (tester) async { - final headerStyle = HeaderStyle(); + const headerStyle = HeaderStyle(); CalendarFormat? calendarFormat; await tester.pumpWidget( @@ -115,15 +115,15 @@ void main() { testWidgets( 'true - display next calendar format', (tester) async { - final headerStyle = HeaderStyle(formatButtonShowsNext: true); + const headerStyle = HeaderStyle(); - final currentFormatIndex = 0; + const currentFormatIndex = 0; final currentFormat = calendarFormatMap.keys.elementAt(currentFormatIndex); final currentFormatText = calendarFormatMap.values.elementAt(currentFormatIndex); - final nextFormatIndex = 1; + const nextFormatIndex = 1; final nextFormatText = calendarFormatMap.values.elementAt(nextFormatIndex); @@ -152,9 +152,9 @@ void main() { testWidgets( 'false - display current calendar format', (tester) async { - final headerStyle = HeaderStyle(formatButtonShowsNext: false); + const headerStyle = HeaderStyle(formatButtonShowsNext: false); - final currentFormatIndex = 0; + const currentFormatIndex = 0; final currentFormat = calendarFormatMap.keys.elementAt(currentFormatIndex); final currentFormatText = diff --git a/test/table_calendar_base_test.dart b/test/table_calendar_base_test.dart index 4076a540..f0d35bd7 100644 --- a/test/table_calendar_base_test.dart +++ b/test/table_calendar_base_test.dart @@ -37,8 +37,6 @@ void main() { }, rowHeight: 52, dowVisible: false, - calendarFormat: CalendarFormat.month, - startingDayOfWeek: StartingDayOfWeek.sunday, ), ), ); @@ -84,7 +82,6 @@ void main() { rowHeight: 52, dowVisible: false, calendarFormat: CalendarFormat.twoWeeks, - startingDayOfWeek: StartingDayOfWeek.sunday, ), ), ); @@ -130,7 +127,6 @@ void main() { rowHeight: 52, dowVisible: false, calendarFormat: CalendarFormat.week, - startingDayOfWeek: StartingDayOfWeek.sunday, ), ), ); @@ -175,14 +171,13 @@ void main() { }, rowHeight: 52, dowVisible: false, - calendarFormat: CalendarFormat.month, startingDayOfWeek: StartingDayOfWeek.monday, ), ), ); final firstVisibleDay = DateTime.utc(2021, 6, 28); - final lastVisibleDay = DateTime.utc(2021, 8, 1); + final lastVisibleDay = DateTime.utc(2021, 8); final focusedDayKey = dateToKey(focusedDay); final firstVisibleDayKey = dateToKey(firstVisibleDay); @@ -368,14 +363,13 @@ void main() { ); }, rowHeight: 52, - dowVisible: true, dowBuilder: (context, day) { return Text('${day.weekday}'); }, ), ), ); - }, throwsAssertionError); + }, throwsAssertionError,); }, ); } diff --git a/test/table_calendar_test.dart b/test/table_calendar_test.dart index 3361255b..313eb9f8 100644 --- a/test/table_calendar_test.dart +++ b/test/table_calendar_test.dart @@ -255,7 +255,7 @@ void main() { ), ); - var dayCells = tester.widgetList(find.byType(CellContent)); + final dayCells = tester.widgetList(find.byType(CellContent)); expect(dayCells.length, 7); }, ); @@ -269,7 +269,7 @@ void main() { ), ); - var dayCells = tester.widgetList(find.byType(CellContent)); + final dayCells = tester.widgetList(find.byType(CellContent)); expect(dayCells.length, 14); }, ); @@ -279,11 +279,11 @@ void main() { (tester) async { await tester.pumpWidget( createTableCalendar( - calendarFormat: CalendarFormat.month, + ), ); - var dayCells = tester.widgetList(find.byType(CellContent)); + final dayCells = tester.widgetList(find.byType(CellContent)); expect(dayCells.length, 35); }, ); @@ -293,12 +293,11 @@ void main() { (tester) async { await tester.pumpWidget( createTableCalendar( - calendarFormat: CalendarFormat.month, sixWeekMonthsEnforced: true, ), ); - var dayCells = tester.widgetList(find.byType(CellContent)); + final dayCells = tester.widgetList(find.byType(CellContent)); expect(dayCells.length, 42); }, ); @@ -437,7 +436,7 @@ void main() { return []; }, ), - )); + ),); final eventDayKey = cellContentKey(eventDay); final eventDayCellContent = find.byKey(eventDayKey); @@ -470,7 +469,7 @@ void main() { lastDay: lastDay, currentDay: today, ), - )); + ),); final currentDayKey = cellContentKey(today); final currentDayCellContent = @@ -493,7 +492,7 @@ void main() { firstDay: firstDay, lastDay: lastDay, ), - )); + ),); final currentDayKey = cellContentKey(now); final currentDayCellContent = @@ -518,7 +517,7 @@ void main() { return isSameDay(day, selectedDay); }, ), - )); + ),); final selectedDayKey = cellContentKey(selectedDay); final selectedDayCellContent = @@ -543,7 +542,7 @@ void main() { return isSameDay(day, holiday); }, ), - )); + ),); final holidayKey = cellContentKey(holiday); final holidayCellContent = @@ -645,7 +644,7 @@ void main() { calendarFormat = format; }, ), - )); + ),); await tester.drag(find.byType(CellContent).first, const Offset(0, -500)); await tester.pumpAndSettle(); @@ -670,7 +669,7 @@ void main() { calendarFormat = format; }, ), - )); + ),); await tester.drag(find.byType(CellContent).first, const Offset(0, -500)); await tester.pumpAndSettle(); @@ -695,7 +694,7 @@ void main() { calendarFormat = format; }, ), - )); + ),); await tester.drag(find.byType(CellContent).first, const Offset(0, -500)); await tester.pumpAndSettle(); @@ -723,7 +722,7 @@ void main() { selectedDay = selected; }, ), - )); + ),); expect(selectedDay, isNull); @@ -751,7 +750,7 @@ void main() { focusedDay = focused; }, ), - )); + ),); expect(focusedDay, isNull); @@ -781,7 +780,7 @@ void main() { focusedDay = focused; }, ), - )); + ),); expect(selectedDay, isNull); expect(focusedDay, isNull); @@ -789,7 +788,7 @@ void main() { final tappedDay = DateTime.utc(2021, 6, 30); final tappedDayKey = cellContentKey(tappedDay); - final expectedFocusedDay = DateTime.utc(2021, 7, 1); + final expectedFocusedDay = DateTime.utc(2021, 7); await tester.tap(find.byKey(tappedDayKey)); await tester.pumpAndSettle(); @@ -815,12 +814,12 @@ void main() { focusedDay = focused; }, ), - )); + ),); expect(selectedDay, isNull); expect(focusedDay, isNull); - final tappedDay = DateTime.utc(2021, 9, 1); + final tappedDay = DateTime.utc(2021, 9); final tappedDayKey = cellContentKey(tappedDay); final expectedFocusedDay = DateTime.utc(2021, 8, 31); @@ -849,7 +848,7 @@ void main() { selectedDay = selected; }, ), - )); + ),); expect(selectedDay, isNull); @@ -877,7 +876,7 @@ void main() { focusedDay = focused; }, ), - )); + ),); expect(focusedDay, isNull); @@ -907,7 +906,7 @@ void main() { focusedDay = focused; }, ), - )); + ),); expect(selectedDay, isNull); expect(focusedDay, isNull); @@ -915,7 +914,7 @@ void main() { final longPressedDay = DateTime.utc(2021, 6, 30); final longPressedDayKey = cellContentKey(longPressedDay); - final expectedFocusedDay = DateTime.utc(2021, 7, 1); + final expectedFocusedDay = DateTime.utc(2021, 7); await tester.longPress(find.byKey(longPressedDayKey)); await tester.pumpAndSettle(); @@ -941,12 +940,12 @@ void main() { focusedDay = focused; }, ), - )); + ),); expect(selectedDay, isNull); expect(focusedDay, isNull); - final longPressedDay = DateTime.utc(2021, 9, 1); + final longPressedDay = DateTime.utc(2021, 9); final longPressedDayKey = cellContentKey(longPressedDay); final expectedFocusedDay = DateTime.utc(2021, 8, 31); @@ -980,7 +979,7 @@ void main() { focusedDay = focused; }, ), - )); + ),); expect(rangeStart, isNull); expect(rangeEnd, isNull); @@ -1024,7 +1023,7 @@ void main() { focusedDay = focused; }, ), - )); + ),); expect(rangeStart, isNull); expect(rangeEnd, isNull); @@ -1062,7 +1061,6 @@ void main() { firstDay: firstDay, lastDay: lastDay, currentDay: today, - rangeSelectionMode: RangeSelectionMode.toggledOff, onDaySelected: (selected, focused) { selectedDay = selected; focusedDay = focused; @@ -1072,9 +1070,8 @@ void main() { rangeEnd = end; focusedDay = focused; }, - onDayLongPressed: null, ), - )); + ),); expect(rangeStart, isNull); expect(rangeEnd, isNull); @@ -1127,9 +1124,8 @@ void main() { rangeEnd = end; focusedDay = focused; }, - onDayLongPressed: null, ), - )); + ),); expect(rangeStart, isNull); expect(rangeEnd, isNull); @@ -1182,9 +1178,8 @@ void main() { rangeEnd = end; focusedDay = focused; }, - onDayLongPressed: null, ), - )); + ),); expect(rangeStart, isNull); expect(rangeEnd, isNull); @@ -1237,9 +1232,8 @@ void main() { rangeEnd = end; focusedDay = focused; }, - onDayLongPressed: null, ), - )); + ),); expect(rangeStart, isNull); expect(rangeEnd, isNull); @@ -1285,7 +1279,7 @@ void main() { rangeStartDay: rangeStart, rangeEndDay: rangeEnd, ), - )); + ),); final rangeStartKey = cellContentKey(rangeStart); final rangeStartCellContent = @@ -1320,7 +1314,7 @@ void main() { rangeStartDay: rangeStart, rangeEndDay: rangeEnd, ), - )); + ),); final dayCount = rangeEnd.difference(rangeStart).inDays - 1; expect(dayCount, 4); @@ -1355,7 +1349,7 @@ void main() { rangeStartDay: rangeStart, rangeEndDay: rangeEnd, ), - )); + ),); final oobStart = rangeStart.subtract(const Duration(days: 1)); final oobEnd = rangeEnd.add(const Duration(days: 1)); From 60750709d05e6ff16b9c443a8ebfea07d389e143 Mon Sep 17 00:00:00 2001 From: Nikolas Rimikis Date: Tue, 28 Feb 2023 12:17:27 +0100 Subject: [PATCH 3/3] format code --- lib/src/customization/calendar_builders.dart | 18 +- lib/src/shared/utils.dart | 5 +- lib/src/table_calendar.dart | 42 +- lib/src/table_calendar_base.dart | 20 +- lib/src/widgets/calendar_core.dart | 30 +- lib/src/widgets/calendar_header.dart | 3 +- lib/src/widgets/calendar_page.dart | 18 +- test/calendar_page_test.dart | 58 +- test/table_calendar_base_test.dart | 43 +- test/table_calendar_test.dart | 622 ++++++++++--------- 10 files changed, 481 insertions(+), 378 deletions(-) diff --git a/lib/src/customization/calendar_builders.dart b/lib/src/customization/calendar_builders.dart index bfc30b8d..6649e0fc 100644 --- a/lib/src/customization/calendar_builders.dart +++ b/lib/src/customization/calendar_builders.dart @@ -3,24 +3,34 @@ import 'package:flutter/widgets.dart'; -import 'package:table_calendar/src/shared/utils.dart' show DayBuilder, FocusedDayBuilder; +import 'package:table_calendar/src/shared/utils.dart' + show DayBuilder, FocusedDayBuilder; /// Signature for a function that creates a single event marker for a given `day`. /// Contains a single `event` associated with that `day`. typedef SingleMarkerBuilder = Widget? Function( - BuildContext context, DateTime day, T event,); + BuildContext context, + DateTime day, + T event, +); /// Signature for a function that creates an event marker for a given `day`. /// Contains a list of `events` associated with that `day`. typedef MarkerBuilder = Widget? Function( - BuildContext context, DateTime day, List events,); + BuildContext context, + DateTime day, + List events, +); /// Signature for a function that creates a background highlight for a given `day`. /// /// Used for highlighting current range selection. /// Contains a value determining if the given `day` falls within the selected range. typedef HighlightBuilder = Widget? Function( - BuildContext context, DateTime day, bool isWithinRange,); + BuildContext context, + DateTime day, + bool isWithinRange, +); /// Class containing all custom builders for `TableCalendar`. class CalendarBuilders { diff --git a/lib/src/shared/utils.dart b/lib/src/shared/utils.dart index 39d363ab..7e63f1ec 100644 --- a/lib/src/shared/utils.dart +++ b/lib/src/shared/utils.dart @@ -9,7 +9,10 @@ typedef DayBuilder = Widget? Function(BuildContext context, DateTime day); /// Signature for a function that creates a widget for a given `day`. /// Additionally, contains the currently focused day. typedef FocusedDayBuilder = Widget? Function( - BuildContext context, DateTime day, DateTime focusedDay,); + BuildContext context, + DateTime day, + DateTime focusedDay, +); /// Signature for a function returning text that can be localized and formatted with `DateFormat`. typedef TextFormatter = String Function(DateTime date, dynamic locale); diff --git a/lib/src/table_calendar.dart b/lib/src/table_calendar.dart index 5fc6454f..67a0a2ca 100644 --- a/lib/src/table_calendar.dart +++ b/lib/src/table_calendar.dart @@ -20,12 +20,17 @@ import 'package:table_calendar/src/widgets/cell_content.dart'; /// Signature for `onDaySelected` callback. Contains the selected day and focused day. typedef OnDaySelected = void Function( - DateTime selectedDay, DateTime focusedDay,); + DateTime selectedDay, + DateTime focusedDay, +); /// Signature for `onRangeSelected` callback. /// Contains start and end of the selected range, as well as currently focused day. typedef OnRangeSelected = void Function( - DateTime? start, DateTime? end, DateTime focusedDay,); + DateTime? start, + DateTime? end, + DateTime focusedDay, +); /// Modes that range selection can operate in. enum RangeSelectionMode { disabled, toggledOff, toggledOn, enforced } @@ -264,9 +269,12 @@ class TableCalendar extends StatefulWidget { this.onCalendarCreated, }) : assert(availableCalendarFormats.keys.contains(calendarFormat)), assert(availableCalendarFormats.length <= CalendarFormat.values.length), - assert(weekendDays.isNotEmpty - && weekendDays.every( - (day) => day >= DateTime.monday && day <= DateTime.sunday,),), + assert( + weekendDays.isNotEmpty && + weekendDays.every( + (day) => day >= DateTime.monday && day <= DateTime.sunday, + ), + ), focusedDay = normalizeDate(focusedDay), firstDay = normalizeDate(firstDay), lastDay = normalizeDate(lastDay), @@ -515,15 +523,16 @@ class _TableCalendarState extends State> { final cell = widget.calendarBuilders.weekNumberBuilder ?.call(context, weekNumber); - return cell ?? Padding( - padding: const EdgeInsets.symmetric(horizontal: 4), - child: Center( - child: Text( - weekNumber.toString(), - style: widget.calendarStyle.weekNumberTextStyle, + return cell ?? + Padding( + padding: const EdgeInsets.symmetric(horizontal: 4), + child: Center( + child: Text( + weekNumber.toString(), + style: widget.calendarStyle.weekNumberTextStyle, + ), ), - ), - ); + ); }, dowBuilder: (BuildContext context, DateTime day) { Widget? dowCell = @@ -710,10 +719,7 @@ class _TableCalendarState extends State> { } int _dayOfYear(DateTime date) { - return normalizeDate(date) - .difference(DateTime.utc(date.year)) - .inDays + - 1; + return normalizeDate(date).difference(DateTime.utc(date.year)).inDays + 1; } bool _isWithinRange(DateTime day, DateTime start, DateTime end) { @@ -735,7 +741,7 @@ class _TableCalendarState extends State> { } bool _isDayAvailable(DateTime day) { - if (widget.enabledDayPredicate == null){ + if (widget.enabledDayPredicate == null) { return true; } diff --git a/lib/src/table_calendar_base.dart b/lib/src/table_calendar_base.dart index 71429a18..c0a56cbc 100644 --- a/lib/src/table_calendar_base.dart +++ b/lib/src/table_calendar_base.dart @@ -100,7 +100,10 @@ class _TableCalendarBaseState extends State { _pageHeight = ValueNotifier(_getPageHeight(rowCount)); final initialPage = _calculateFocusedPage( - widget.calendarFormat, widget.firstDay, _focusedDay,); + widget.calendarFormat, + widget.firstDay, + _focusedDay, + ); _pageController = PageController(initialPage: initialPage); widget.onCalendarCreated?.call(_pageController); @@ -148,10 +151,16 @@ class _TableCalendarBaseState extends State { void _updatePage({bool shouldAnimate = false}) { final currentIndex = _calculateFocusedPage( - widget.calendarFormat, widget.firstDay, _focusedDay,); + widget.calendarFormat, + widget.firstDay, + _focusedDay, + ); final endIndex = _calculateFocusedPage( - widget.calendarFormat, widget.firstDay, widget.lastDay,); + widget.calendarFormat, + widget.firstDay, + widget.lastDay, + ); if (currentIndex != _previousIndex || currentIndex == 0 || @@ -266,7 +275,10 @@ class _TableCalendarBaseState extends State { } int _calculateFocusedPage( - CalendarFormat format, DateTime startDay, DateTime focusedDay,) { + CalendarFormat format, + DateTime startDay, + DateTime focusedDay, + ) { switch (format) { case CalendarFormat.month: return _getMonthCount(startDay, focusedDay); diff --git a/lib/src/widgets/calendar_core.dart b/lib/src/widgets/calendar_core.dart index ceb83e3d..e2ef0fb9 100644 --- a/lib/src/widgets/calendar_core.dart +++ b/lib/src/widgets/calendar_core.dart @@ -6,7 +6,6 @@ import 'package:flutter/material.dart'; import 'package:table_calendar/src/shared/utils.dart'; import 'package:table_calendar/src/widgets/calendar_page.dart'; - class CalendarCore extends StatelessWidget { final DateTime? focusedDay; final DateTime firstDay; @@ -155,7 +154,10 @@ class CalendarCore extends StatelessWidget { } DateTime _getFocusedDay( - CalendarFormat format, DateTime prevFocusedDay, int pageIndex,) { + CalendarFormat format, + DateTime prevFocusedDay, + int pageIndex, + ) { if (pageIndex == previousIndex) { return prevFocusedDay; } @@ -168,12 +170,18 @@ class CalendarCore extends StatelessWidget { day = DateTime.utc(prevFocusedDay.year, prevFocusedDay.month + pageDif); break; case CalendarFormat.twoWeeks: - day = DateTime.utc(prevFocusedDay.year, prevFocusedDay.month, - prevFocusedDay.day + pageDif * 14,); + day = DateTime.utc( + prevFocusedDay.year, + prevFocusedDay.month, + prevFocusedDay.day + pageDif * 14, + ); break; case CalendarFormat.week: - day = DateTime.utc(prevFocusedDay.year, prevFocusedDay.month, - prevFocusedDay.day + pageDif * 7,); + day = DateTime.utc( + prevFocusedDay.year, + prevFocusedDay.month, + prevFocusedDay.day + pageDif * 7, + ); break; } @@ -195,11 +203,17 @@ class CalendarCore extends StatelessWidget { break; case CalendarFormat.twoWeeks: day = DateTime.utc( - firstDay.year, firstDay.month, firstDay.day + pageIndex * 14,); + firstDay.year, + firstDay.month, + firstDay.day + pageIndex * 14, + ); break; case CalendarFormat.week: day = DateTime.utc( - firstDay.year, firstDay.month, firstDay.day + pageIndex * 7,); + firstDay.year, + firstDay.month, + firstDay.day + pageIndex * 7, + ); break; } diff --git a/lib/src/widgets/calendar_header.dart b/lib/src/widgets/calendar_header.dart index 903e1791..e6c8047a 100644 --- a/lib/src/widgets/calendar_header.dart +++ b/lib/src/widgets/calendar_header.dart @@ -5,7 +5,8 @@ import 'package:flutter/widgets.dart'; import 'package:intl/intl.dart'; import 'package:table_calendar/src/customization/header_style.dart'; -import 'package:table_calendar/src/shared/utils.dart' show CalendarFormat, DayBuilder; +import 'package:table_calendar/src/shared/utils.dart' + show CalendarFormat, DayBuilder; import 'package:table_calendar/src/widgets/custom_icon_button.dart'; import 'package:table_calendar/src/widgets/format_button.dart'; diff --git a/lib/src/widgets/calendar_page.dart b/lib/src/widgets/calendar_page.dart index 470b9f9f..b9663fdd 100644 --- a/lib/src/widgets/calendar_page.dart +++ b/lib/src/widgets/calendar_page.dart @@ -83,13 +83,15 @@ class CalendarPage extends StatelessWidget { List _buildCalendarDays(BuildContext context) { final rowAmount = visibleDays.length ~/ 7; - return List.generate(rowAmount, (index) => TableRow( - decoration: rowDecoration, - children: List.generate( - 7, - (id) => dayBuilder(context, visibleDays[index * 7 + id]), - ), - ), - ); + return List.generate( + rowAmount, + (index) => TableRow( + decoration: rowDecoration, + children: List.generate( + 7, + (id) => dayBuilder(context, visibleDays[index * 7 + id]), + ), + ), + ); } } diff --git a/test/calendar_page_test.dart b/test/calendar_page_test.dart index 78b0ebda..19fc8267 100644 --- a/test/calendar_page_test.dart +++ b/test/calendar_page_test.dart @@ -78,18 +78,21 @@ void main() { testWidgets( 'Throw AssertionError when CalendarPage is built with dowVisible set to true, but dowBuilder is absent', (tester) async { - expect(() async { - await tester.pumpWidget( - setupTestWidget( - CalendarPage( - visibleDays: visibleDays, - dayBuilder: (context, day) { - return Text('${day.day}'); - }, + expect( + () async { + await tester.pumpWidget( + setupTestWidget( + CalendarPage( + visibleDays: visibleDays, + dayBuilder: (context, day) { + return Text('${day.day}'); + }, + ), ), - ), - ); - }, throwsAssertionError,); + ); + }, + throwsAssertionError, + ); }, ); @@ -121,22 +124,24 @@ void main() { testWidgets( 'Week numbers are visible', (tester) async { - await tester.pumpWidget(setupTestWidget( - CalendarPage( - visibleDays: visibleDays, - dayBuilder: (context, day) { - return Text('${day.day}'); - }, - dowBuilder: (context, day) { - return Text('${day.weekday}'); - }, - dowHeight: 5, - weekNumberVisible: true, - weekNumberBuilder: (BuildContext context, DateTime day) { - return Text(day.weekday.toString()); - }, + await tester.pumpWidget( + setupTestWidget( + CalendarPage( + visibleDays: visibleDays, + dayBuilder: (context, day) { + return Text('${day.day}'); + }, + dowBuilder: (context, day) { + return Text('${day.weekday}'); + }, + dowHeight: 5, + weekNumberVisible: true, + weekNumberBuilder: (BuildContext context, DateTime day) { + return Text(day.weekday.toString()); + }, + ), ), - ),); + ); expect( find.byType(Column), @@ -144,5 +149,4 @@ void main() { ); }, ); - } diff --git a/test/table_calendar_base_test.dart b/test/table_calendar_base_test.dart index f0d35bd7..c0fddf66 100644 --- a/test/table_calendar_base_test.dart +++ b/test/table_calendar_base_test.dart @@ -349,27 +349,30 @@ void main() { testWidgets( 'Throw AssertionError when TableCalendarBase is built with dowVisible and dowBuilder, but dowHeight is absent', (tester) async { - expect(() async { - await tester.pumpWidget( - setupTestWidget( - TableCalendarBase( - firstDay: DateTime.utc(2021, 5, 15), - lastDay: DateTime.utc(2021, 8, 18), - focusedDay: DateTime.utc(2021, 7, 15), - dayBuilder: (context, day, focusedDay) { - return Text( - '${day.day}', - key: dateToKey(day), - ); - }, - rowHeight: 52, - dowBuilder: (context, day) { - return Text('${day.weekday}'); - }, + expect( + () async { + await tester.pumpWidget( + setupTestWidget( + TableCalendarBase( + firstDay: DateTime.utc(2021, 5, 15), + lastDay: DateTime.utc(2021, 8, 18), + focusedDay: DateTime.utc(2021, 7, 15), + dayBuilder: (context, day, focusedDay) { + return Text( + '${day.day}', + key: dateToKey(day), + ); + }, + rowHeight: 52, + dowBuilder: (context, day) { + return Text('${day.weekday}'); + }, + ), ), - ), - ); - }, throwsAssertionError,); + ); + }, + throwsAssertionError, + ); }, ); } diff --git a/test/table_calendar_test.dart b/test/table_calendar_test.dart index 313eb9f8..69418e2a 100644 --- a/test/table_calendar_test.dart +++ b/test/table_calendar_test.dart @@ -278,9 +278,7 @@ void main() { '35 day cells in month format for July 2021', (tester) async { await tester.pumpWidget( - createTableCalendar( - - ), + createTableCalendar(), ); final dayCells = tester.widgetList(find.byType(CellContent)); @@ -422,21 +420,23 @@ void main() { (tester) async { final eventDay = DateTime.utc(2021, 7, 20); - await tester.pumpWidget(setupTestWidget( - TableCalendar( - focusedDay: initialFocusedDay, - firstDay: firstDay, - lastDay: lastDay, - currentDay: today, - eventLoader: (day) { - if (day.day == eventDay.day && day.month == eventDay.month) { - return ['Event 1', 'Event 2', 'Event 3']; - } - - return []; - }, + await tester.pumpWidget( + setupTestWidget( + TableCalendar( + focusedDay: initialFocusedDay, + firstDay: firstDay, + lastDay: lastDay, + currentDay: today, + eventLoader: (day) { + if (day.day == eventDay.day && day.month == eventDay.month) { + return ['Event 1', 'Event 2', 'Event 3']; + } + + return []; + }, + ), ), - ),); + ); final eventDayKey = cellContentKey(eventDay); final eventDayCellContent = find.byKey(eventDayKey); @@ -462,14 +462,16 @@ void main() { testWidgets( 'currentDay correctly marks given day as today', (tester) async { - await tester.pumpWidget(setupTestWidget( - TableCalendar( - focusedDay: initialFocusedDay, - firstDay: firstDay, - lastDay: lastDay, - currentDay: today, + await tester.pumpWidget( + setupTestWidget( + TableCalendar( + focusedDay: initialFocusedDay, + firstDay: firstDay, + lastDay: lastDay, + currentDay: today, + ), ), - ),); + ); final currentDayKey = cellContentKey(today); final currentDayCellContent = @@ -486,13 +488,15 @@ void main() { final firstDay = DateTime.utc(now.year, now.month - 3, now.day); final lastDay = DateTime.utc(now.year, now.month + 3, now.day); - await tester.pumpWidget(setupTestWidget( - TableCalendar( - focusedDay: now, - firstDay: firstDay, - lastDay: lastDay, + await tester.pumpWidget( + setupTestWidget( + TableCalendar( + focusedDay: now, + firstDay: firstDay, + lastDay: lastDay, + ), ), - ),); + ); final currentDayKey = cellContentKey(now); final currentDayCellContent = @@ -507,17 +511,19 @@ void main() { (tester) async { final selectedDay = DateTime.utc(2021, 7, 20); - await tester.pumpWidget(setupTestWidget( - TableCalendar( - focusedDay: initialFocusedDay, - firstDay: firstDay, - lastDay: lastDay, - currentDay: today, - selectedDayPredicate: (day) { - return isSameDay(day, selectedDay); - }, + await tester.pumpWidget( + setupTestWidget( + TableCalendar( + focusedDay: initialFocusedDay, + firstDay: firstDay, + lastDay: lastDay, + currentDay: today, + selectedDayPredicate: (day) { + return isSameDay(day, selectedDay); + }, + ), ), - ),); + ); final selectedDayKey = cellContentKey(selectedDay); final selectedDayCellContent = @@ -532,17 +538,19 @@ void main() { (tester) async { final holiday = DateTime.utc(2021, 7, 20); - await tester.pumpWidget(setupTestWidget( - TableCalendar( - focusedDay: initialFocusedDay, - firstDay: firstDay, - lastDay: lastDay, - currentDay: today, - holidayPredicate: (day) { - return isSameDay(day, holiday); - }, + await tester.pumpWidget( + setupTestWidget( + TableCalendar( + focusedDay: initialFocusedDay, + firstDay: firstDay, + lastDay: lastDay, + currentDay: today, + holidayPredicate: (day) { + return isSameDay(day, holiday); + }, + ), ), - ),); + ); final holidayKey = cellContentKey(holiday); final holidayCellContent = @@ -633,18 +641,20 @@ void main() { testWidgets('when initial format is month', (tester) async { CalendarFormat calendarFormat = CalendarFormat.month; - await tester.pumpWidget(setupTestWidget( - TableCalendar( - focusedDay: today, - firstDay: firstDay, - lastDay: lastDay, - currentDay: today, - calendarFormat: calendarFormat, - onFormatChanged: (format) { - calendarFormat = format; - }, + await tester.pumpWidget( + setupTestWidget( + TableCalendar( + focusedDay: today, + firstDay: firstDay, + lastDay: lastDay, + currentDay: today, + calendarFormat: calendarFormat, + onFormatChanged: (format) { + calendarFormat = format; + }, + ), ), - ),); + ); await tester.drag(find.byType(CellContent).first, const Offset(0, -500)); await tester.pumpAndSettle(); @@ -658,18 +668,20 @@ void main() { testWidgets('when initial format is two weeks', (tester) async { CalendarFormat calendarFormat = CalendarFormat.twoWeeks; - await tester.pumpWidget(setupTestWidget( - TableCalendar( - focusedDay: today, - firstDay: firstDay, - lastDay: lastDay, - currentDay: today, - calendarFormat: calendarFormat, - onFormatChanged: (format) { - calendarFormat = format; - }, + await tester.pumpWidget( + setupTestWidget( + TableCalendar( + focusedDay: today, + firstDay: firstDay, + lastDay: lastDay, + currentDay: today, + calendarFormat: calendarFormat, + onFormatChanged: (format) { + calendarFormat = format; + }, + ), ), - ),); + ); await tester.drag(find.byType(CellContent).first, const Offset(0, -500)); await tester.pumpAndSettle(); @@ -683,18 +695,20 @@ void main() { testWidgets('when initial format is week', (tester) async { CalendarFormat calendarFormat = CalendarFormat.week; - await tester.pumpWidget(setupTestWidget( - TableCalendar( - focusedDay: today, - firstDay: firstDay, - lastDay: lastDay, - currentDay: today, - calendarFormat: calendarFormat, - onFormatChanged: (format) { - calendarFormat = format; - }, + await tester.pumpWidget( + setupTestWidget( + TableCalendar( + focusedDay: today, + firstDay: firstDay, + lastDay: lastDay, + currentDay: today, + calendarFormat: calendarFormat, + onFormatChanged: (format) { + calendarFormat = format; + }, + ), ), - ),); + ); await tester.drag(find.byType(CellContent).first, const Offset(0, -500)); await tester.pumpAndSettle(); @@ -712,17 +726,19 @@ void main() { (tester) async { DateTime? selectedDay; - await tester.pumpWidget(setupTestWidget( - TableCalendar( - focusedDay: initialFocusedDay, - firstDay: firstDay, - lastDay: lastDay, - currentDay: today, - onDaySelected: (selected, focused) { - selectedDay = selected; - }, + await tester.pumpWidget( + setupTestWidget( + TableCalendar( + focusedDay: initialFocusedDay, + firstDay: firstDay, + lastDay: lastDay, + currentDay: today, + onDaySelected: (selected, focused) { + selectedDay = selected; + }, + ), ), - ),); + ); expect(selectedDay, isNull); @@ -740,17 +756,19 @@ void main() { (tester) async { DateTime? focusedDay; - await tester.pumpWidget(setupTestWidget( - TableCalendar( - focusedDay: initialFocusedDay, - firstDay: firstDay, - lastDay: lastDay, - currentDay: today, - onDaySelected: (selected, focused) { - focusedDay = focused; - }, + await tester.pumpWidget( + setupTestWidget( + TableCalendar( + focusedDay: initialFocusedDay, + firstDay: firstDay, + lastDay: lastDay, + currentDay: today, + onDaySelected: (selected, focused) { + focusedDay = focused; + }, + ), ), - ),); + ); expect(focusedDay, isNull); @@ -769,18 +787,20 @@ void main() { DateTime? selectedDay; DateTime? focusedDay; - await tester.pumpWidget(setupTestWidget( - TableCalendar( - focusedDay: initialFocusedDay, - firstDay: firstDay, - lastDay: lastDay, - currentDay: today, - onDaySelected: (selected, focused) { - selectedDay = selected; - focusedDay = focused; - }, + await tester.pumpWidget( + setupTestWidget( + TableCalendar( + focusedDay: initialFocusedDay, + firstDay: firstDay, + lastDay: lastDay, + currentDay: today, + onDaySelected: (selected, focused) { + selectedDay = selected; + focusedDay = focused; + }, + ), ), - ),); + ); expect(selectedDay, isNull); expect(focusedDay, isNull); @@ -803,18 +823,20 @@ void main() { DateTime? selectedDay; DateTime? focusedDay; - await tester.pumpWidget(setupTestWidget( - TableCalendar( - focusedDay: DateTime.utc(2021, 8, 16), - firstDay: firstDay, - lastDay: lastDay, - currentDay: DateTime.utc(2021, 8, 16), - onDaySelected: (selected, focused) { - selectedDay = selected; - focusedDay = focused; - }, + await tester.pumpWidget( + setupTestWidget( + TableCalendar( + focusedDay: DateTime.utc(2021, 8, 16), + firstDay: firstDay, + lastDay: lastDay, + currentDay: DateTime.utc(2021, 8, 16), + onDaySelected: (selected, focused) { + selectedDay = selected; + focusedDay = focused; + }, + ), ), - ),); + ); expect(selectedDay, isNull); expect(focusedDay, isNull); @@ -838,17 +860,19 @@ void main() { (tester) async { DateTime? selectedDay; - await tester.pumpWidget(setupTestWidget( - TableCalendar( - focusedDay: initialFocusedDay, - firstDay: firstDay, - lastDay: lastDay, - currentDay: today, - onDayLongPressed: (selected, focused) { - selectedDay = selected; - }, + await tester.pumpWidget( + setupTestWidget( + TableCalendar( + focusedDay: initialFocusedDay, + firstDay: firstDay, + lastDay: lastDay, + currentDay: today, + onDayLongPressed: (selected, focused) { + selectedDay = selected; + }, + ), ), - ),); + ); expect(selectedDay, isNull); @@ -866,17 +890,19 @@ void main() { (tester) async { DateTime? focusedDay; - await tester.pumpWidget(setupTestWidget( - TableCalendar( - focusedDay: initialFocusedDay, - firstDay: firstDay, - lastDay: lastDay, - currentDay: today, - onDayLongPressed: (selected, focused) { - focusedDay = focused; - }, + await tester.pumpWidget( + setupTestWidget( + TableCalendar( + focusedDay: initialFocusedDay, + firstDay: firstDay, + lastDay: lastDay, + currentDay: today, + onDayLongPressed: (selected, focused) { + focusedDay = focused; + }, + ), ), - ),); + ); expect(focusedDay, isNull); @@ -895,18 +921,20 @@ void main() { DateTime? selectedDay; DateTime? focusedDay; - await tester.pumpWidget(setupTestWidget( - TableCalendar( - focusedDay: initialFocusedDay, - firstDay: firstDay, - lastDay: lastDay, - currentDay: today, - onDayLongPressed: (selected, focused) { - selectedDay = selected; - focusedDay = focused; - }, + await tester.pumpWidget( + setupTestWidget( + TableCalendar( + focusedDay: initialFocusedDay, + firstDay: firstDay, + lastDay: lastDay, + currentDay: today, + onDayLongPressed: (selected, focused) { + selectedDay = selected; + focusedDay = focused; + }, + ), ), - ),); + ); expect(selectedDay, isNull); expect(focusedDay, isNull); @@ -929,18 +957,20 @@ void main() { DateTime? selectedDay; DateTime? focusedDay; - await tester.pumpWidget(setupTestWidget( - TableCalendar( - focusedDay: DateTime.utc(2021, 8, 16), - firstDay: firstDay, - lastDay: lastDay, - currentDay: DateTime.utc(2021, 8, 16), - onDayLongPressed: (selected, focused) { - selectedDay = selected; - focusedDay = focused; - }, + await tester.pumpWidget( + setupTestWidget( + TableCalendar( + focusedDay: DateTime.utc(2021, 8, 16), + firstDay: firstDay, + lastDay: lastDay, + currentDay: DateTime.utc(2021, 8, 16), + onDayLongPressed: (selected, focused) { + selectedDay = selected; + focusedDay = focused; + }, + ), ), - ),); + ); expect(selectedDay, isNull); expect(focusedDay, isNull); @@ -966,20 +996,22 @@ void main() { DateTime? rangeEnd; DateTime? focusedDay; - await tester.pumpWidget(setupTestWidget( - TableCalendar( - focusedDay: initialFocusedDay, - firstDay: firstDay, - lastDay: lastDay, - currentDay: today, - rangeSelectionMode: RangeSelectionMode.enforced, - onRangeSelected: (start, end, focused) { - rangeStart = start; - rangeEnd = end; - focusedDay = focused; - }, + await tester.pumpWidget( + setupTestWidget( + TableCalendar( + focusedDay: initialFocusedDay, + firstDay: firstDay, + lastDay: lastDay, + currentDay: today, + rangeSelectionMode: RangeSelectionMode.enforced, + onRangeSelected: (start, end, focused) { + rangeStart = start; + rangeEnd = end; + focusedDay = focused; + }, + ), ), - ),); + ); expect(rangeStart, isNull); expect(rangeEnd, isNull); @@ -1010,20 +1042,22 @@ void main() { DateTime? rangeEnd; DateTime? focusedDay; - await tester.pumpWidget(setupTestWidget( - TableCalendar( - focusedDay: initialFocusedDay, - firstDay: firstDay, - lastDay: lastDay, - currentDay: today, - rangeSelectionMode: RangeSelectionMode.enforced, - onRangeSelected: (start, end, focused) { - rangeStart = start; - rangeEnd = end; - focusedDay = focused; - }, + await tester.pumpWidget( + setupTestWidget( + TableCalendar( + focusedDay: initialFocusedDay, + firstDay: firstDay, + lastDay: lastDay, + currentDay: today, + rangeSelectionMode: RangeSelectionMode.enforced, + onRangeSelected: (start, end, focused) { + rangeStart = start; + rangeEnd = end; + focusedDay = focused; + }, + ), ), - ),); + ); expect(rangeStart, isNull); expect(rangeEnd, isNull); @@ -1055,23 +1089,25 @@ void main() { DateTime? focusedDay; DateTime? selectedDay; - await tester.pumpWidget(setupTestWidget( - TableCalendar( - focusedDay: initialFocusedDay, - firstDay: firstDay, - lastDay: lastDay, - currentDay: today, - onDaySelected: (selected, focused) { - selectedDay = selected; - focusedDay = focused; - }, - onRangeSelected: (start, end, focused) { - rangeStart = start; - rangeEnd = end; - focusedDay = focused; - }, + await tester.pumpWidget( + setupTestWidget( + TableCalendar( + focusedDay: initialFocusedDay, + firstDay: firstDay, + lastDay: lastDay, + currentDay: today, + onDaySelected: (selected, focused) { + selectedDay = selected; + focusedDay = focused; + }, + onRangeSelected: (start, end, focused) { + rangeStart = start; + rangeEnd = end; + focusedDay = focused; + }, + ), ), - ),); + ); expect(rangeStart, isNull); expect(rangeEnd, isNull); @@ -1108,24 +1144,26 @@ void main() { DateTime? focusedDay; DateTime? selectedDay; - await tester.pumpWidget(setupTestWidget( - TableCalendar( - focusedDay: initialFocusedDay, - firstDay: firstDay, - lastDay: lastDay, - currentDay: today, - rangeSelectionMode: RangeSelectionMode.toggledOn, - onDaySelected: (selected, focused) { - selectedDay = selected; - focusedDay = focused; - }, - onRangeSelected: (start, end, focused) { - rangeStart = start; - rangeEnd = end; - focusedDay = focused; - }, + await tester.pumpWidget( + setupTestWidget( + TableCalendar( + focusedDay: initialFocusedDay, + firstDay: firstDay, + lastDay: lastDay, + currentDay: today, + rangeSelectionMode: RangeSelectionMode.toggledOn, + onDaySelected: (selected, focused) { + selectedDay = selected; + focusedDay = focused; + }, + onRangeSelected: (start, end, focused) { + rangeStart = start; + rangeEnd = end; + focusedDay = focused; + }, + ), ), - ),); + ); expect(rangeStart, isNull); expect(rangeEnd, isNull); @@ -1162,24 +1200,26 @@ void main() { DateTime? focusedDay; DateTime? selectedDay; - await tester.pumpWidget(setupTestWidget( - TableCalendar( - focusedDay: initialFocusedDay, - firstDay: firstDay, - lastDay: lastDay, - currentDay: today, - rangeSelectionMode: RangeSelectionMode.enforced, - onDaySelected: (selected, focused) { - selectedDay = selected; - focusedDay = focused; - }, - onRangeSelected: (start, end, focused) { - rangeStart = start; - rangeEnd = end; - focusedDay = focused; - }, + await tester.pumpWidget( + setupTestWidget( + TableCalendar( + focusedDay: initialFocusedDay, + firstDay: firstDay, + lastDay: lastDay, + currentDay: today, + rangeSelectionMode: RangeSelectionMode.enforced, + onDaySelected: (selected, focused) { + selectedDay = selected; + focusedDay = focused; + }, + onRangeSelected: (start, end, focused) { + rangeStart = start; + rangeEnd = end; + focusedDay = focused; + }, + ), ), - ),); + ); expect(rangeStart, isNull); expect(rangeEnd, isNull); @@ -1216,24 +1256,26 @@ void main() { DateTime? focusedDay; DateTime? selectedDay; - await tester.pumpWidget(setupTestWidget( - TableCalendar( - focusedDay: initialFocusedDay, - firstDay: firstDay, - lastDay: lastDay, - currentDay: today, - rangeSelectionMode: RangeSelectionMode.disabled, - onDaySelected: (selected, focused) { - selectedDay = selected; - focusedDay = focused; - }, - onRangeSelected: (start, end, focused) { - rangeStart = start; - rangeEnd = end; - focusedDay = focused; - }, + await tester.pumpWidget( + setupTestWidget( + TableCalendar( + focusedDay: initialFocusedDay, + firstDay: firstDay, + lastDay: lastDay, + currentDay: today, + rangeSelectionMode: RangeSelectionMode.disabled, + onDaySelected: (selected, focused) { + selectedDay = selected; + focusedDay = focused; + }, + onRangeSelected: (start, end, focused) { + rangeStart = start; + rangeEnd = end; + focusedDay = focused; + }, + ), ), - ),); + ); expect(rangeStart, isNull); expect(rangeEnd, isNull); @@ -1270,16 +1312,18 @@ void main() { final rangeStart = DateTime.utc(2021, 7, 8); final rangeEnd = DateTime.utc(2021, 7, 21); - await tester.pumpWidget(setupTestWidget( - TableCalendar( - focusedDay: initialFocusedDay, - firstDay: firstDay, - lastDay: lastDay, - currentDay: today, - rangeStartDay: rangeStart, - rangeEndDay: rangeEnd, + await tester.pumpWidget( + setupTestWidget( + TableCalendar( + focusedDay: initialFocusedDay, + firstDay: firstDay, + lastDay: lastDay, + currentDay: today, + rangeStartDay: rangeStart, + rangeEndDay: rangeEnd, + ), ), - ),); + ); final rangeStartKey = cellContentKey(rangeStart); final rangeStartCellContent = @@ -1305,16 +1349,18 @@ void main() { final rangeStart = DateTime.utc(2021, 7, 8); final rangeEnd = DateTime.utc(2021, 7, 13); - await tester.pumpWidget(setupTestWidget( - TableCalendar( - focusedDay: initialFocusedDay, - firstDay: firstDay, - lastDay: lastDay, - currentDay: today, - rangeStartDay: rangeStart, - rangeEndDay: rangeEnd, + await tester.pumpWidget( + setupTestWidget( + TableCalendar( + focusedDay: initialFocusedDay, + firstDay: firstDay, + lastDay: lastDay, + currentDay: today, + rangeStartDay: rangeStart, + rangeEndDay: rangeEnd, + ), ), - ),); + ); final dayCount = rangeEnd.difference(rangeStart).inDays - 1; expect(dayCount, 4); @@ -1340,16 +1386,18 @@ void main() { final rangeStart = DateTime.utc(2021, 7, 8); final rangeEnd = DateTime.utc(2021, 7, 13); - await tester.pumpWidget(setupTestWidget( - TableCalendar( - focusedDay: initialFocusedDay, - firstDay: firstDay, - lastDay: lastDay, - currentDay: today, - rangeStartDay: rangeStart, - rangeEndDay: rangeEnd, + await tester.pumpWidget( + setupTestWidget( + TableCalendar( + focusedDay: initialFocusedDay, + firstDay: firstDay, + lastDay: lastDay, + currentDay: today, + rangeStartDay: rangeStart, + rangeEndDay: rangeEnd, + ), ), - ),); + ); final oobStart = rangeStart.subtract(const Duration(days: 1)); final oobEnd = rangeEnd.add(const Duration(days: 1));