diff --git a/CHANGELOG.md b/CHANGELOG.md index fee608d..c5d3c66 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## [0.4.6] - 2024-08-12 +* New callback for logging + ## [0.4.5] - 2024-08-11 * Two new callback functions * onListViewStateChanged diff --git a/README.md b/README.md index cc87ac7..17a8186 100644 --- a/README.md +++ b/README.md @@ -156,6 +156,15 @@ final ValueChanged>>? This callback function gets executed, when the `eventsMap` gets updated. This happens in the `initState` method. This callback function can be used to pass the content of the `eventsMap` to the parent widget. There are some cases, where this is useful. +#### `onPrintLog` + +```dart + + final ValueChanged? onPrintLog; +``` + +This callback can be used to pass Strings with logging messages from the widget to its parent widget. By doing so can use your apps logging class to output the messages of the calendar. The only thing you need to do is to implement your allback message and call your logger with the passed String object. + ### Options ### `isExpandable` diff --git a/example/lib/main.dart b/example/lib/main.dart index 7d86b32..bb5c669 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -16,7 +16,7 @@ class MyApp extends StatelessWidget { darkTheme: ThemeData.dark(), themeMode: ThemeMode.system, home: CalendarScreen(), - localizationsDelegates: [GlobalMaterialLocalizations.delegate], + localizationsDelegates: GlobalMaterialLocalizations.delegates, supportedLocales: [ const Locale('en'), const Locale('fr'), diff --git a/example/pubspec.lock b/example/pubspec.lock index c2df47f..06a31f6 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -89,7 +89,7 @@ packages: path: ".." relative: true source: path - version: "0.4.3" + version: "0.4.6" flutter_platform_widgets: dependency: transitive description: diff --git a/lib/flutter_neat_and_clean_calendar.dart b/lib/flutter_neat_and_clean_calendar.dart index 5d5b6c0..231fcf1 100644 --- a/lib/flutter_neat_and_clean_calendar.dart +++ b/lib/flutter_neat_and_clean_calendar.dart @@ -110,6 +110,7 @@ class Calendar extends StatefulWidget { final ValueChanged? onListViewStateChanged; final ValueChanged>>? onEventsUpdated; + final ValueChanged? onPrintLog; final bool isExpandable; final DayBuilder? dayBuilder; final EventListBuilder? eventListBuilder; @@ -158,6 +159,7 @@ class Calendar extends StatefulWidget { this.onEventLongPressed, this.onListViewStateChanged, this.onEventsUpdated, + this.onPrintLog, this.isExpandable = false, this.eventsList, this.dayBuilder, @@ -328,7 +330,9 @@ class _CalendarState extends State { _selectedDate.year, _selectedDate.month, _selectedDate.day)] ?? []; - print('eventsMap has ${eventsMap?.length} entries'); + widget.onPrintLog != null + ? widget.onPrintLog!('eventsMap has ${eventsMap?.length} entries') + : print('eventsMap has ${eventsMap?.length} entries'); // If the eventsMap is updated, the eventsUpdated callback is invoked. In some cases it is useful // to have a copy of the eventsMap in the parent widget. This can be done by providing a callback @@ -438,7 +442,10 @@ class _CalendarState extends State { // _selectedDate is updated. This must be done after the callback methods are invoked, // otherwise the callback methods will not trigger, if the current date is equal to the // selected date. - print('Date chosen: ${_selectedDate.toIso8601String()}'); + widget.onPrintLog != null + ? widget.onPrintLog!( + 'Date chosen: ${_selectedDate.toIso8601String()}') + : print('Date chosen: ${_selectedDate.toIso8601String()}'); onJumpToDateSelected(date); setState(() { _selectedDate = date; @@ -692,7 +699,9 @@ class _CalendarState extends State { } Column singleDayTimeWidget(String start, String end) { - print('SingleDayEvent'); + widget.onPrintLog != null + ? widget.onPrintLog!('SingleDayEvent') + : print('SingleDayEvent'); return Column( crossAxisAlignment: CrossAxisAlignment.end, mainAxisAlignment: MainAxisAlignment.center, @@ -704,11 +713,15 @@ class _CalendarState extends State { } Column allOrMultiDayDayTimeWidget(NeatCleanCalendarEvent event) { - print('=== Summary: ${event.summary}'); + widget.onPrintLog != null + ? widget.onPrintLog!('=== Summary: ${event.summary}') + : print('=== Summary: ${event.summary}'); String start = DateFormat('HH:mm').format(event.startTime).toString(); String end = DateFormat('HH:mm').format(event.endTime).toString(); if (event.isAllDay) { - print('AllDayEvent - ${event.summary}'); + widget.onPrintLog != null + ? widget.onPrintLog!('AllDayEvent - ${event.summary}') + : print('AllDayEvent - ${event.summary}'); return Column( crossAxisAlignment: CrossAxisAlignment.end, mainAxisAlignment: MainAxisAlignment.center, @@ -723,16 +736,22 @@ class _CalendarState extends State { if (event.multiDaySegement == MultiDaySegement.first) { // The event begins on the selcted day. // Just show the start time, no end time. - print('MultiDayEvent: start - ${event.summary}'); + widget.onPrintLog != null + ? widget.onPrintLog!('MultiDayEvent: start - ${event.summary}') + : print('MultiDayEvent: start - ${event.summary}'); end = ''; } else if (event.multiDaySegement == MultiDaySegement.last) { // The event ends on the selcted day. // Just show the end time, no start time. - print('MultiDayEvent: end - ${event.summary}'); + widget.onPrintLog != null + ? widget.onPrintLog!('MultiDayEvent: end - ${event.summary}') + : print('MultiDayEvent: end - ${event.summary}'); start = widget.multiDayEndText; } else { // The event spans multiple days. - print('MultiDayEvent: middle - ${event.summary}'); + widget.onPrintLog != null + ? widget.onPrintLog!('MultiDayEvent: middle - ${event.summary}') + : print('MultiDayEvent: middle - ${event.summary}'); start = widget.allDayEventText; end = ''; } @@ -1144,7 +1163,9 @@ class _CalendarState extends State { // but typically this method will store the selected date and then call a // user-defined callback function based on this date. void handleSelectedDateAndUserCallback(DateTime day) { - print('daySelected: $day'); + widget.onPrintLog != null + ? widget.onPrintLog!('daySelected: $day') + : print('daySelected: $day'); // Fire onDateSelected callback and onMonthChanged callback. _launchDateSelectionCallback(day); diff --git a/pubspec.yaml b/pubspec.yaml index bdbac2e..c74c844 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -3,7 +3,7 @@ description: >- Simple and clean flutter calendar with ability to slide up/down to show weekly/monthly calendar. Fork of https://pub.dev/packages/flutter_clean_calendar -version: 0.4.5 +version: 0.4.6 homepage: https://github.com/rwbr/flutter_neat_and_clean_calendar environment: