diff --git a/CHANGELOG.md b/CHANGELOG.md index b2e8d69..8a24917 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,17 @@ +## 1.0.0 + +**BREAKING CHANGES**: +> +> Removed `initialize` method -> use `SDTFScope` instead +> +> Removed `dateFormat` getter -> use `getDatePattern()` instead +> +> Removed `mediumDateFormat` getter -> use `getMediumDatePattern()` instead +> +> Removed `longDateFormat` getter -> use `getLongDatePattern()` instead +> +> Removed `timeFormat` getter -> use `getTimePattern()` instead + ## 0.7.2 Updated the SDK constraint to '>=2.18.6 <4.0.0' diff --git a/example/pubspec.lock b/example/pubspec.lock index 85f147c..290bc3a 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -171,7 +171,7 @@ packages: path: ".." relative: true source: path - version: "0.7.2" + version: "1.0.0" term_glyph: dependency: transitive description: diff --git a/example_with_tests/pubspec.lock b/example_with_tests/pubspec.lock index 324270d..9c0d460 100644 --- a/example_with_tests/pubspec.lock +++ b/example_with_tests/pubspec.lock @@ -179,7 +179,7 @@ packages: path: ".." relative: true source: path - version: "0.7.2" + version: "1.0.0" term_glyph: dependency: transitive description: diff --git a/lib/src/errors/not_initialized_error.dart b/lib/src/errors/not_initialized_error.dart deleted file mode 100644 index 7a4647a..0000000 --- a/lib/src/errors/not_initialized_error.dart +++ /dev/null @@ -1,11 +0,0 @@ -/// Error that will be thrown when trying to use a plugin before initialization. -class NotInitializedError extends Error { - NotInitializedError(this.name); - - final String name; - - @override - String toString() { - return '$name was called before initialization\n\n\nDid you forget to call:\n\nSystemDateTimeFormat().initialize()\n\n'; - } -} diff --git a/lib/src/fallbacks.dart b/lib/src/fallbacks.dart deleted file mode 100644 index ee36662..0000000 --- a/lib/src/fallbacks.dart +++ /dev/null @@ -1,10 +0,0 @@ -/// Fallback values in case of platform errors. -/// They can be overwritten on initialization of the plugin. -abstract class Fallbacks { - Fallbacks._(); - - static const dateFormat = 'M/d/yy'; - static const mediumDateFormat = 'MMM d,y'; - static const longDateFormat = 'MMMM d,y'; - static const timeFormat = 'h:mm a'; -} diff --git a/lib/system_date_time_format.dart b/lib/system_date_time_format.dart index 400d2e6..5f32936 100644 --- a/lib/system_date_time_format.dart +++ b/lib/system_date_time_format.dart @@ -1,8 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:system_date_time_format/src/errors/not_initialized_error.dart'; import 'package:system_date_time_format/src/errors/sdtf_scope_not_found_error.dart'; -import 'package:system_date_time_format/src/fallbacks.dart'; import 'package:system_date_time_format/src/patterns.dart'; import 'package:system_date_time_format/src/widgets/sdtf_scope_inherited.dart'; @@ -64,101 +62,4 @@ class SystemDateTimeFormat { return sDTFScope.patterns; } - - /// Initializes the plugin. - /// Call this method before using the plugin further. - /// It will be removed in 1.0.0 - @Deprecated("Use SDTFScope instead.") - Future initialize({ - String dateFormatFallback = Fallbacks.dateFormat, - String mediumDateFormatFallback = Fallbacks.mediumDateFormat, - String longDateFormatFallback = Fallbacks.longDateFormat, - String timeFormatFallback = Fallbacks.timeFormat, - }) async { - final platform = SystemDateTimeFormatPlatformInterface.instance; - _dateFormat = await _try( - platform.getDatePattern, - fallback: dateFormatFallback, - ); - _mediumDateFormat = await _try( - platform.getMediumDatePattern, - fallback: mediumDateFormatFallback, - ); - _longDateFormat = await _try( - platform.getLongDatePattern, - fallback: longDateFormatFallback, - ); - _timeFormat = await _try( - platform.getTimePattern, - fallback: timeFormatFallback, - ); - } - - /// Returns a short version of date format. - /// Throws [NotInitializedError] when plugin was not initialized - /// It will be removed in 1.0.0 - @Deprecated("Use getDatePattern() instead.") - String get dateFormat { - if (_dateFormat == null) { - throw NotInitializedError('dateFormat'); - } - return _dateFormat!; - } - - /// Returns a medium version of date format. - /// Throws [NotInitializedError] when plugin was not initialized - /// It will be removed in 1.0.0 - @Deprecated("Use getMediumDatePattern() instead.") - String get mediumDateFormat { - if (_mediumDateFormat == null) { - throw NotInitializedError('mediumDateFormat'); - } - return _mediumDateFormat!; - } - - /// Returns a long version of date format. - /// Throws [NotInitializedError] when plugin was not initialized - /// It will be removed in 1.0.0 - @Deprecated("Use getLongDatePattern() instead.") - String get longDateFormat { - if (_longDateFormat == null) { - throw NotInitializedError('longDateFormat'); - } - return _longDateFormat!; - } - - /// Returns time format. - /// Throws [NotInitializedError] when plugin was not initialized - /// It will be removed in 1.0.0 - @Deprecated("Use getTimePattern() instead.") - String get timeFormat { - if (_timeFormat == null) { - throw NotInitializedError('timeFormat'); - } - return _timeFormat!; - } - - /// Helper function for catching [PlatformException] and returning a fallback when that happen - Future _try( - Future Function() function, { - required String fallback, - }) async { - try { - return await function() ?? fallback; - } on PlatformException { - return fallback; - } - } - - /// Holds (dateFormat) value after plugin initialization - String? _dateFormat; - - /// Holds (mediumDateFormat) value after plugin initialization - String? _mediumDateFormat; - - /// Holds (longDateFormat) value after plugin initialization - String? _longDateFormat; - - /// Holds (timeFormat) value after plugin initialization - String? _timeFormat; } diff --git a/pubspec.yaml b/pubspec.yaml index cd1f69f..86aaea2 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: system_date_time_format description: A plugin for getting date and time format patterns from device system settings. -version: 0.7.2 +version: 1.0.0 repository: https://github.com/Nikoro/system_date_time_format issue_tracker: https://github.com/Nikoro/system_date_time_format/issues diff --git a/test/src/errors/not_ititialized_error_test.dart b/test/src/errors/not_ititialized_error_test.dart deleted file mode 100644 index 890ba63..0000000 --- a/test/src/errors/not_ititialized_error_test.dart +++ /dev/null @@ -1,14 +0,0 @@ -import 'package:flutter_test/flutter_test.dart'; -import 'package:system_date_time_format/src/errors/not_initialized_error.dart'; - -void main() { - group('NotInitializedError', () { - test('toString returns correct message', () { - const name = 'name'; - final error = NotInitializedError(name); - const expected = - '$name was called before initialization\n\n\nDid you forget to call:\n\nSystemDateTimeFormat().initialize()\n\n'; - expect(error.toString(), expected); - }); - }); -} diff --git a/test/system_date_time_format/system_date_time_format_error_test.dart b/test/system_date_time_format/system_date_time_format_error_test.dart deleted file mode 100644 index 6207b18..0000000 --- a/test/system_date_time_format/system_date_time_format_error_test.dart +++ /dev/null @@ -1,36 +0,0 @@ -import 'package:flutter_test/flutter_test.dart'; -import 'package:system_date_time_format/src/errors/not_initialized_error.dart'; -import 'package:system_date_time_format/system_date_time_format.dart'; - -void main() { - group('SystemDateTimeFormat', () { - test('dateFormat throws NotInitializedError when not initialized', () { - expect( - () => SystemDateTimeFormat().dateFormat, - throwsA(isA()), - ); - }); - - test('mediumDateFormat throws NotInitializedError when not initialized', - () { - expect( - () => SystemDateTimeFormat().mediumDateFormat, - throwsA(isA()), - ); - }); - - test('longDateFormat throws NotInitializedError when not initialized', () { - expect( - () => SystemDateTimeFormat().longDateFormat, - throwsA(isA()), - ); - }); - - test('timeFormat throws NotInitializedError when not initialized', () { - expect( - () => SystemDateTimeFormat().timeFormat, - throwsA(isA()), - ); - }); - }); -} diff --git a/test/system_date_time_format/system_date_time_format_exception_test.dart b/test/system_date_time_format/system_date_time_format_exception_test.dart deleted file mode 100644 index 6ac07dd..0000000 --- a/test/system_date_time_format/system_date_time_format_exception_test.dart +++ /dev/null @@ -1,56 +0,0 @@ -import 'package:flutter/services.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:mocktail/mocktail.dart'; -import 'package:system_date_time_format/src/fallbacks.dart'; -import 'package:system_date_time_format/src/system_date_time_format_platform_interface.dart'; -import 'package:system_date_time_format/system_date_time_format.dart'; - -import '../_tools/tools.dart'; - -void main() { - setUp(() { - final platform = MockSystemDateTimeFormatPlatform(); - - asyncPlatformException(_) async => throw PlatformException(code: ''); - - when(() => platform.getDatePattern()).thenAnswer(asyncPlatformException); - when(() => platform.getMediumDatePattern()) - .thenAnswer(asyncPlatformException); - when(() => platform.getLongDatePattern()) - .thenAnswer(asyncPlatformException); - when(() => platform.getTimePattern()).thenAnswer(asyncPlatformException); - - SystemDateTimeFormatPlatformInterface.instance = platform; - }); - - group('SystemDateTimeFormat', () { - test( - 'dateFormat returns fallback format: [${Fallbacks.dateFormat}] on PlatformException', - () async { - await SystemDateTimeFormat().initialize(); - expect(SystemDateTimeFormat().dateFormat, Fallbacks.dateFormat); - }); - - test( - 'mediumDateFormat returns fallback format: [${Fallbacks.mediumDateFormat}] on PlatformException', - () async { - await SystemDateTimeFormat().initialize(); - expect( - SystemDateTimeFormat().mediumDateFormat, Fallbacks.mediumDateFormat); - }); - - test( - 'longDateFormat returns fallback format: [${Fallbacks.longDateFormat}] on PlatformException', - () async { - await SystemDateTimeFormat().initialize(); - expect(SystemDateTimeFormat().longDateFormat, Fallbacks.longDateFormat); - }); - - test( - 'timeFormat returns fallback format: [${Fallbacks.timeFormat}] on PlatformException', - () async { - await SystemDateTimeFormat().initialize(); - expect(SystemDateTimeFormat().timeFormat, Fallbacks.timeFormat); - }); - }); -} diff --git a/test/system_date_time_format/system_date_time_format_test.dart b/test/system_date_time_format/system_date_time_format_test.dart index 811bfb0..f1b7806 100644 --- a/test/system_date_time_format/system_date_time_format_test.dart +++ b/test/system_date_time_format/system_date_time_format_test.dart @@ -68,30 +68,5 @@ void main() { final patterns = SystemDateTimeFormat.of(context); expect(patterns, Stubs.allPatterns); }); - - test('dateFormat returns correct pattern: [${Stubs.datePattern}]', - () async { - await SystemDateTimeFormat().initialize(); - expect(SystemDateTimeFormat().dateFormat, Stubs.datePattern); - }); - - test( - 'mediumDateFormat returns correct pattern: [${Stubs.mediumDatePattern}]', - () async { - await SystemDateTimeFormat().initialize(); - expect(SystemDateTimeFormat().mediumDateFormat, Stubs.mediumDatePattern); - }); - - test('longDateFormat returns correct pattern: [${Stubs.longDatePattern}]', - () async { - await SystemDateTimeFormat().initialize(); - expect(SystemDateTimeFormat().longDateFormat, Stubs.longDatePattern); - }); - - test('timeFormat returns correct pattern: [${Stubs.timePattern}]', - () async { - await SystemDateTimeFormat().initialize(); - expect(SystemDateTimeFormat().timeFormat, Stubs.timePattern); - }); }); }