diff --git a/CHANGELOG.md b/CHANGELOG.md index 05acda51..8c8fa09e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## [3.1.2] + +* Added dayTextFormatter property to CalendarStyle that allows to customize the text within day cells +* Reverted the default day cell's text formatting to just the day's number + ## [3.1.1] * Added cell text localization based on current locale diff --git a/README.md b/README.md index f89a6fbb..dd8f2293 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ Add the following line to `pubspec.yaml`: ```yaml dependencies: - table_calendar: ^3.1.1 + table_calendar: ^3.1.2 ``` ### Basic setup diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index c90f8af2..b6b288b8 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -1,3 +1,9 @@ +plugins { + id "com.android.application" + id "kotlin-android" + id "dev.flutter.flutter-gradle-plugin" +} + def localProperties = new Properties() def localPropertiesFile = rootProject.file('local.properties') if (localPropertiesFile.exists()) { @@ -6,11 +12,6 @@ if (localPropertiesFile.exists()) { } } -def flutterRoot = localProperties.getProperty('flutter.sdk') -if (flutterRoot == null) { - throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") -} - def flutterVersionCode = localProperties.getProperty('flutter.versionCode') if (flutterVersionCode == null) { flutterVersionCode = '1' @@ -21,10 +22,6 @@ if (flutterVersionName == null) { flutterVersionName = '1.0' } -apply plugin: 'com.android.application' -apply plugin: 'kotlin-android' -apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" - android { compileSdkVersion 31 @@ -58,6 +55,3 @@ flutter { source '../..' } -dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" -} diff --git a/example/android/build.gradle b/example/android/build.gradle index 05744a00..8f31e8ca 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -1,20 +1,7 @@ -buildscript { - ext.kotlin_version = '1.6.10' - repositories { - google() - jcenter() - } - - dependencies { - classpath 'com.android.tools.build:gradle:4.1.0' - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - } -} - allprojects { repositories { google() - jcenter() + mavenCentral() } } @@ -28,4 +15,4 @@ subprojects { tasks.register("clean", Delete) { delete rootProject.buildDir -} +} \ No newline at end of file diff --git a/example/android/gradle/wrapper/gradle-wrapper.properties b/example/android/gradle/wrapper/gradle-wrapper.properties index bc6a58af..cfe88f69 100644 --- a/example/android/gradle/wrapper/gradle-wrapper.properties +++ b/example/android/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-all.zip diff --git a/example/android/settings.gradle b/example/android/settings.gradle index 44e62bcf..960ad4a9 100644 --- a/example/android/settings.gradle +++ b/example/android/settings.gradle @@ -1,11 +1,25 @@ -include ':app' +pluginManagement { + def flutterSdkPath = { + def properties = new Properties() + file("local.properties").withInputStream { properties.load(it) } + def flutterSdkPath = properties.getProperty("flutter.sdk") + assert flutterSdkPath != null, "flutter.sdk not set in local.properties" + return flutterSdkPath + }() -def localPropertiesFile = new File(rootProject.projectDir, "local.properties") -def properties = new Properties() + includeBuild("$flutterSdkPath/packages/flutter_tools/gradle") -assert localPropertiesFile.exists() -localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) } + repositories { + google() + mavenCentral() + gradlePluginPortal() + } +} -def flutterSdkPath = properties.getProperty("flutter.sdk") -assert flutterSdkPath != null, "flutter.sdk not set in local.properties" -apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle" +plugins { + id "dev.flutter.flutter-plugin-loader" version "1.0.0" + id "com.android.application" version "7.0.0" apply false + id "org.jetbrains.kotlin.android" version "1.6.10" apply false +} + +include ":app" \ No newline at end of file diff --git a/example/pubspec.lock b/example/pubspec.lock index 618525e4..5505275a 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -45,10 +45,10 @@ packages: dependency: "direct main" description: name: cupertino_icons - sha256: d57953e10f9f8327ce64a508a355f0b1ec902193f66288e8cb5070e7c47eeb2d + sha256: ba631d1c7f7bef6b729a622b7b752645a2d076dba9976925b8f25725a30e1ee6 url: "https://pub.dev" source: hosted - version: "1.0.6" + version: "1.0.8" fake_async: dependency: transitive description: @@ -75,38 +75,62 @@ packages: url: "https://pub.dev" source: hosted version: "0.19.0" + leak_tracker: + dependency: transitive + description: + name: leak_tracker + sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a" + url: "https://pub.dev" + source: hosted + version: "10.0.4" + leak_tracker_flutter_testing: + dependency: transitive + description: + name: leak_tracker_flutter_testing + sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8" + url: "https://pub.dev" + source: hosted + version: "3.0.3" + leak_tracker_testing: + dependency: transitive + description: + name: leak_tracker_testing + sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3" + url: "https://pub.dev" + source: hosted + version: "3.0.1" matcher: dependency: transitive description: name: matcher - sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e" + sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb url: "https://pub.dev" source: hosted - version: "0.12.16" + version: "0.12.16+1" material_color_utilities: dependency: transitive description: name: material_color_utilities - sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41" + sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" url: "https://pub.dev" source: hosted - version: "0.5.0" + version: "0.8.0" meta: dependency: transitive description: name: meta - sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e + sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136" url: "https://pub.dev" source: hosted - version: "1.10.0" + version: "1.12.0" path: dependency: transitive description: name: path - sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" + sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" url: "https://pub.dev" source: hosted - version: "1.8.3" + version: "1.9.0" simple_gesture_detector: dependency: transitive description: @@ -158,7 +182,7 @@ packages: path: ".." relative: true source: path - version: "3.1.1" + version: "3.1.2" term_glyph: dependency: transitive description: @@ -171,10 +195,10 @@ packages: dependency: transitive description: name: test_api - sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" + sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f" url: "https://pub.dev" source: hosted - version: "0.6.1" + version: "0.7.0" vector_math: dependency: transitive description: @@ -183,14 +207,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.4" - web: + vm_service: dependency: transitive description: - name: web - sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152 + name: vm_service + sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec" url: "https://pub.dev" source: hosted - version: "0.3.0" + version: "14.2.1" sdks: - dart: ">=3.2.0-194.0.dev <4.0.0" - flutter: ">=1.17.0" + dart: ">=3.3.0 <4.0.0" + flutter: ">=3.18.0-18.0.pre.54" diff --git a/lib/src/customization/calendar_style.dart b/lib/src/customization/calendar_style.dart index c052540b..abc00151 100644 --- a/lib/src/customization/calendar_style.dart +++ b/lib/src/customization/calendar_style.dart @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import 'package:flutter/widgets.dart'; +import 'package:table_calendar/table_calendar.dart'; /// Class containing styling and configuration for `TableCalendar`'s content. class CalendarStyle { @@ -151,6 +152,15 @@ class CalendarStyle { /// Padding for the internal `Table` widget. final EdgeInsets tablePadding; + /// Use to customize the text within each day cell. + /// Defaults to `'${date.day}'`, to show just the day number. + /// + /// Example usage: + /// ```dart + /// dayTextFormatter: (date, locale) => DateFormat.d(locale).format(date), + /// ``` + final TextFormatter? dayTextFormatter; + /// Creates a `CalendarStyle` used by `TableCalendar` widget. const CalendarStyle({ this.isTodayHighlighted = true, @@ -227,6 +237,7 @@ class CalendarStyle { this.rowDecoration = const BoxDecoration(), this.tableBorder = const TableBorder(), this.tablePadding = const EdgeInsets.all(0), + this.dayTextFormatter, }); } diff --git a/lib/src/widgets/cell_content.dart b/lib/src/widgets/cell_content.dart index a3276d5b..ba4d4ce7 100644 --- a/lib/src/widgets/cell_content.dart +++ b/lib/src/widgets/cell_content.dart @@ -60,7 +60,8 @@ class CellContent extends StatelessWidget { ); } - final text = DateFormat.d(locale).format(day); + final text = + calendarStyle.dayTextFormatter?.call(day, locale) ?? '${day.day}'; final margin = calendarStyle.cellMargin; final padding = calendarStyle.cellPadding; final alignment = calendarStyle.cellAlignment; diff --git a/pubspec.lock b/pubspec.lock index 115e68f9..19725456 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -67,38 +67,62 @@ packages: url: "https://pub.dev" source: hosted version: "0.19.0" + leak_tracker: + dependency: transitive + description: + name: leak_tracker + sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a" + url: "https://pub.dev" + source: hosted + version: "10.0.4" + leak_tracker_flutter_testing: + dependency: transitive + description: + name: leak_tracker_flutter_testing + sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8" + url: "https://pub.dev" + source: hosted + version: "3.0.3" + leak_tracker_testing: + dependency: transitive + description: + name: leak_tracker_testing + sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3" + url: "https://pub.dev" + source: hosted + version: "3.0.1" matcher: dependency: transitive description: name: matcher - sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e" + sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb url: "https://pub.dev" source: hosted - version: "0.12.16" + version: "0.12.16+1" material_color_utilities: dependency: transitive description: name: material_color_utilities - sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41" + sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" url: "https://pub.dev" source: hosted - version: "0.5.0" + version: "0.8.0" meta: dependency: transitive description: name: meta - sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e + sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136" url: "https://pub.dev" source: hosted - version: "1.10.0" + version: "1.12.0" path: dependency: transitive description: name: path - sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" + sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" url: "https://pub.dev" source: hosted - version: "1.8.3" + version: "1.9.0" simple_gesture_detector: dependency: "direct main" description: @@ -156,10 +180,10 @@ packages: dependency: transitive description: name: test_api - sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" + sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f" url: "https://pub.dev" source: hosted - version: "0.6.1" + version: "0.7.0" vector_math: dependency: transitive description: @@ -168,14 +192,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.4" - web: + vm_service: dependency: transitive description: - name: web - sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152 + name: vm_service + sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec" url: "https://pub.dev" source: hosted - version: "0.3.0" + version: "14.2.1" sdks: - dart: ">=3.2.0-194.0.dev <4.0.0" - flutter: ">=1.17.0" + dart: ">=3.3.0 <4.0.0" + flutter: ">=3.18.0-18.0.pre.54" diff --git a/pubspec.yaml b/pubspec.yaml index d7999699..6c032a95 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: table_calendar description: Highly customizable, feature-packed calendar widget for Flutter. -version: 3.1.1 +version: 3.1.2 author: Aleksander Woźniak homepage: https://github.com/aleksanderwozniak/table_calendar diff --git a/test/cell_content_test.dart b/test/cell_content_test.dart index 40ade637..a147707e 100644 --- a/test/cell_content_test.dart +++ b/test/cell_content_test.dart @@ -11,6 +11,7 @@ import 'package:table_calendar/table_calendar.dart'; Widget setupTestWidget( DateTime cellDay, { CalendarBuilders calendarBuilders = const CalendarBuilders(), + CalendarStyle calendarStyle = const CalendarStyle(), bool isDisabled = false, bool isToday = false, bool isWeekend = false, @@ -23,8 +24,6 @@ Widget setupTestWidget( bool isTodayHighlighted = true, String? locale, }) { - final calendarStyle = CalendarStyle(); - return Directionality( textDirection: TextDirection.ltr, child: CellContent( @@ -316,7 +315,23 @@ void main() { }); group('CalendarBuilders Locale test:', () { - testWidgets('en locale', (tester) async { + testWidgets('en locale with default dayTextFormatter', (tester) async { + final locale = 'en'; + initializeDateFormatting(locale, null); + + final cellDay = DateTime.utc(2021, 7, 15); + await tester.pumpWidget( + setupTestWidget( + cellDay, + locale: locale, + ), + ); + + final dayFinder = find.text('${cellDay.day}'); + expect(dayFinder, findsOneWidget); + }); + + testWidgets('en locale with custom dayTextFormatter', (tester) async { final locale = 'en'; initializeDateFormatting(locale, null); @@ -325,6 +340,10 @@ void main() { setupTestWidget( cellDay, locale: locale, + calendarStyle: CalendarStyle( + dayTextFormatter: (date, locale) => + DateFormat.d(locale).format(date), + ), ), ); @@ -332,7 +351,7 @@ void main() { expect(dayFinder, findsOneWidget); }); - testWidgets('ar locale', (tester) async { + testWidgets('ar locale with default dayTextFormatter', (tester) async { final locale = 'ar'; initializeDateFormatting(locale, null); @@ -344,6 +363,26 @@ void main() { ), ); + final dayFinder = find.text('${cellDay.day}'); + expect(dayFinder, findsOneWidget); + }); + + testWidgets('ar locale with custom dayTextFormatter', (tester) async { + final locale = 'ar'; + initializeDateFormatting(locale, null); + + final cellDay = DateTime.utc(2021, 7, 15); + await tester.pumpWidget( + setupTestWidget( + cellDay, + locale: locale, + calendarStyle: CalendarStyle( + dayTextFormatter: (date, locale) => + DateFormat.d(locale).format(date), + ), + ), + ); + final dayFinder = find.text(DateFormat.d(locale).format(cellDay)); expect(dayFinder, findsOneWidget); });