From da61ba796c1baa02717e91afc5b79e4a8461b8a3 Mon Sep 17 00:00:00 2001 From: Jan Zimola Date: Sat, 29 Apr 2023 12:58:26 +0200 Subject: [PATCH 1/4] adding czech locale --- README.md | 8 +++++--- example/lib/utils.dart | 1 + lib/src/localization.dart | 22 ++++++++++++++++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 494eb57..9f782ec 100644 --- a/README.md +++ b/README.md @@ -9,12 +9,15 @@ | ![](https://github.com/JonasWanke/timetable/raw/main/doc/demo-callbacks.webp?raw=true) | ![](https://github.com/JonasWanke/timetable/raw/main/doc/demo-visibleDateRange.webp?raw=true) | - [Available Layouts](#available-layouts) + - [`MultiDateTimetable`](#multidatetimetable) + - [`RecurringMultiDateTimetable`](#recurringmultidatetimetable) + - [`CompactMonthTimetable`](#compactmonthtimetable) - [Getting started](#getting-started) - [0. General Information](#0-general-information) - [1. Define your `Event`s](#1-define-your-events) - [2. Create a `DateController` (optional)](#2-create-a-datecontroller-optional) - [3. Create a `TimeController` (optional)](#3-create-a-timecontroller-optional) - - [4. Create your Timetable](#4-create-your-timetable) + - [4. Create your Timetable widget](#4-create-your-timetable-widget) - [Theming](#theming) - [Advanced Features](#advanced-features) - [Drag and Drop](#drag-and-drop) @@ -46,7 +49,6 @@ A Timetable widget that displays [`MonthWidget`]s in a page view. | :------------------------------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------------------------: | | ![](https://github.com/JonasWanke/timetable/raw/main/doc/screenshot-CompactMonthTimetable-light.webp?raw=true) | ![](https://github.com/JonasWanke/timetable/raw/main/doc/screenshot-CompactMonthTimetable-dark.webp?raw=true) | - ## Getting started ### 0. General Information @@ -61,7 +63,7 @@ Some date/time-related parameters also have special suffixes: - `timeOfDay`: A `Duration` between zero and 24 hours. - `dayOfWeek`: An `int` between one and seven ([`DateTime.monday`](https://api.flutter.dev/flutter/dart-core/DateTime/monday-constant.html) through [`DateTime.sunday`](https://api.flutter.dev/flutter/dart-core/DateTime/sunday-constant.html)). -Timetable currently offers localizations for Chinese, English, French, German, Hungarian, Italian, Japanese, Portuguese, and Spanish. +Timetable currently offers localizations for Czech, Chinese, English, French, German, Hungarian, Italian, Japanese, Portuguese, and Spanish. Even if you're just supporting English in your app, you have to add Timetable's localization delegate to your `MaterialApp`/`CupertinoApp`/`WidgetsApp`: ```dart diff --git a/example/lib/utils.dart b/example/lib/utils.dart index 2323a3f..b3aa403 100644 --- a/example/lib/utils.dart +++ b/example/lib/utils.dart @@ -8,6 +8,7 @@ import 'package:timetable/timetable.dart'; final _mediaOverrideState = ValueNotifier(MediaOverrideState()); final _supportedLocales = [ + const Locale('cs'), const Locale('de'), const Locale('en'), const Locale('es'), diff --git a/lib/src/localization.dart b/lib/src/localization.dart index a78594c..5459b74 100644 --- a/lib/src/localization.dart +++ b/lib/src/localization.dart @@ -8,6 +8,8 @@ import 'week.dart'; /// /// Supported [Locale.languageCode]s: /// +/// * `cs` – Czech +/// * `de` – German /// * `de` – German /// * `en` – English /// * `es` – Spanish @@ -89,6 +91,8 @@ class TimetableLocalizationsDelegate return const TimetableLocalizationDe(); case 'en': return const TimetableLocalizationEn(); + case 'cs': + return const TimetableLocalizationCs(); case 'es': return const TimetableLocalizationEs(); case 'fr': @@ -218,6 +222,24 @@ class TimetableLocalizationEn extends TimetableLocalizations { 'Week ${week.weekOfYear}, ${week.weekBasedYear}'; } +class TimetableLocalizationCs extends TimetableLocalizations { + const TimetableLocalizationCs(); + + @override + List weekLabels(Week week) { + return [ + weekOfYear(week), + 'Týden ${week.weekOfYear}', + 'T ${week.weekOfYear}', + '${week.weekOfYear}', + ]; + } + + @override + String weekOfYear(Week week) => + 'Týden ${week.weekOfYear}, ${week.weekBasedYear}'; +} + class TimetableLocalizationEs extends TimetableLocalizations { const TimetableLocalizationEs(); From bbec188fb34c6f299c195193751b279680b061ba Mon Sep 17 00:00:00 2001 From: Jan Zimola Date: Sun, 30 Apr 2023 18:12:02 +0200 Subject: [PATCH 2/4] check if mounted --- lib/src/components/multi_date_content.dart | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/src/components/multi_date_content.dart b/lib/src/components/multi_date_content.dart index 9590339..bb5b0e1 100644 --- a/lib/src/components/multi_date_content.dart +++ b/lib/src/components/multi_date_content.dart @@ -324,10 +324,12 @@ class _PartDayDraggableEventState extends State { return; } - final adjustedOffset = _pointerToWidgetTopCenter(_lastOffset!); - final geometry = _findGeometry(context, adjustedOffset); - widget.onDragCanceled?.call(geometry.key, _wasMoved); - _resetState(); + if (context.mounted) { + final adjustedOffset = _pointerToWidgetTopCenter(_lastOffset!); + final geometry = _findGeometry(context, adjustedOffset); + widget.onDragCanceled?.call(geometry.key, _wasMoved); + _resetState(); + } } Offset _pointerToWidgetTopCenter(Offset offset) { From 56b5ebb0e483a61af09f297a2979bb945c4a3700 Mon Sep 17 00:00:00 2001 From: Jan Zimola Date: Sun, 30 Apr 2023 18:17:44 +0200 Subject: [PATCH 3/4] checking for mounted --- lib/src/components/multi_date_content.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/components/multi_date_content.dart b/lib/src/components/multi_date_content.dart index bb5b0e1..3c91713 100644 --- a/lib/src/components/multi_date_content.dart +++ b/lib/src/components/multi_date_content.dart @@ -324,7 +324,7 @@ class _PartDayDraggableEventState extends State { return; } - if (context.mounted) { + if (mounted) { final adjustedOffset = _pointerToWidgetTopCenter(_lastOffset!); final geometry = _findGeometry(context, adjustedOffset); widget.onDragCanceled?.call(geometry.key, _wasMoved); From 7905dab4feaecce5c3cbd673d08214635cb45d01 Mon Sep 17 00:00:00 2001 From: Jan Zimola Date: Sun, 30 Apr 2023 18:23:19 +0200 Subject: [PATCH 4/4] call on drag cancel --- lib/src/components/multi_date_content.dart | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/src/components/multi_date_content.dart b/lib/src/components/multi_date_content.dart index 3c91713..3608a42 100644 --- a/lib/src/components/multi_date_content.dart +++ b/lib/src/components/multi_date_content.dart @@ -329,6 +329,9 @@ class _PartDayDraggableEventState extends State { final geometry = _findGeometry(context, adjustedOffset); widget.onDragCanceled?.call(geometry.key, _wasMoved); _resetState(); + } else { + widget.onDragCanceled?.call(null, _wasMoved); + _resetState(); } }