diff --git a/update_available/CHANGELOG.md b/update_available/CHANGELOG.md index 1742194..fb87a25 100644 --- a/update_available/CHANGELOG.md +++ b/update_available/CHANGELOG.md @@ -1,3 +1,12 @@ +## 3.0.0 + +- Require Dart 3.0 or later +- Add `base`, `final`, and `sealed` modifiers to some classes +- Remove `when` and `whenOrElse` methods from `Availability` + - Now that `Availability` is `sealed`, you should use `switch` instead +- Use `HttpClient` instead of the `http` package, removing the later from the dependencies +- Provide more tests + ## 2.3.0 - Bumped Kotlin version to 1.5.31, as required by Flutter 2.10 and greater (fixes #28) diff --git a/update_available/README.md b/update_available/README.md index f50690d..2620b29 100644 --- a/update_available/README.md +++ b/update_available/README.md @@ -7,7 +7,8 @@ * Provide a simple, single function to get update availability for your Android or iOS app. * Version checking based on published app version. - * Foldable structure so that you have compile-time exhaustive check. + * ~~Foldable structure so that you have compile-time exhaustive check.~~ + * Since version 3.0 (with Dart 3.0), exhaustive check is done by using `switch`, as `Availability` is now a `sealed class`. ## Getting started @@ -15,7 +16,7 @@ ```yaml dependencies: - update_available: ^2.0.0 + update_available: ^3.0.0 ``` Update your packages with `flutter pub get`. @@ -32,7 +33,7 @@ You can also set the named parameter `iosAppStoreRegion` for that function to specify the region (according to ISO 3166-1 alpha-2) in which the iOS version will be checked. -To exhaustively check against these three possibilities, `Availability` provides the `fold` and `foldElse` functions, which receive functions for each case and thus guarantee compile-time exhaustive check. +To exhaustively check against these three possibilities, use a `switch`, as `Availability` is a `sealed class`. You can get more details about `Availability` in the [source code](https://github.com/mateusfccp/update_available/blob/master/update_available_platform_interface/lib/src/availability.dart). @@ -42,13 +43,13 @@ You can get more details about `Availability` in the [source code](https://githu void printAvailability() async { final updateAvailability = await getUpdateAvailability(); - final text = updateAvailability.fold( - available: () => "There's an update to you app! Please, update it " - "so you have access to the latest features!", - notAvailable: () => 'No update is available for your app.', - unknown: () => "It was not possible to determine if there is or not " - "an update for your app.", - ); + final text = switch (availability) { + UpdateAvailable() => "There's an update to you app! Please, update it " + "so you have access to the latest features!", + NoUpdateAvailable() => 'No update is available for your app.', + UnknownAvailability() => "It was not possible to determine if there is or not " + "an update for your app.", + }; print(text); } diff --git a/update_available/example/lib/main.dart b/update_available/example/lib/main.dart index b4b0743..9ff1d29 100644 --- a/update_available/example/lib/main.dart +++ b/update_available/example/lib/main.dart @@ -68,11 +68,11 @@ class _UpdateAvailableExampleState extends State { final availability = await getUpdateAvailability(); setState(() { - text = availability.fold( - available: () => "There's an update available!", - notAvailable: () => "There's no update available!", - unknown: () => "Sorry, couldn't determine if there is or not an available update!", - ); + text = switch (availability) { + UpdateAvailable() => "There's an update available!", + NoUpdateAvailable() => "There's no update available!", + UnknownAvailability() => "Sorry, couldn't determine if there is or not an available update!", + }; }); } } diff --git a/update_available/example/lib/shared/button.dart b/update_available/example/lib/shared/button.dart index 3696400..7077957 100644 --- a/update_available/example/lib/shared/button.dart +++ b/update_available/example/lib/shared/button.dart @@ -19,7 +19,7 @@ class Button extends StatelessWidget { child: Container( decoration: BoxDecoration( color: red, - borderRadius: BorderRadius.circular(100), + borderRadius: BorderRadius.circular(100.0), ), alignment: Alignment.center, child: child, diff --git a/update_available/example/pubspec.yaml b/update_available/example/pubspec.yaml index 8cdff82..06606d0 100644 --- a/update_available/example/pubspec.yaml +++ b/update_available/example/pubspec.yaml @@ -1,12 +1,12 @@ name: update_available_example description: Example for update_available package. -version: 1.1.0 +version: 2.0.0 repository: https://github.com/mateusfccp/update_available/tree/master/update_available publish_to: none environment: - sdk: ">=2.16.0 <3.0.0" - flutter: ">=2.10.0" + sdk: ">=3.0.0 <4.0.0" + flutter: ">=3.10.0" dependencies: flutter: @@ -15,7 +15,7 @@ dependencies: path: .. dev_dependencies: - flutter_lints: ^2.0.0 + flutter_lints: ^2.0.2 dependency_overrides: update_available_android: diff --git a/update_available/lib/update_available.dart b/update_available/lib/update_available.dart index 1609730..16f5ea9 100644 --- a/update_available/lib/update_available.dart +++ b/update_available/lib/update_available.dart @@ -13,13 +13,11 @@ export 'package:update_available_platform_interface/update_available_platform_in /// void main() async { /// final updateAvailability = await getUpdateAvailability(); /// -/// final text = updateAvailability.fold( -/// available: () => "There's an update to you app! Please, update it " -/// "so you have access to the latest features!", -/// notAvailable: () => 'No update is available for your app.', -/// unknown: () => "It was not possible to determine if there is or not " -/// "an update for your app.", -/// ); +/// text = switch (availability) { +/// UpdateAvailable() => "There's an update available!", +/// NoUpdateAvailable() => "There's no update available!", +/// UnknownAvailability() => "Sorry, couldn't determine if there is or not an available update!", +/// }; /// /// print(text); /// } diff --git a/update_available/pubspec.yaml b/update_available/pubspec.yaml index c121dfb..989bb0a 100644 --- a/update_available/pubspec.yaml +++ b/update_available/pubspec.yaml @@ -1,21 +1,21 @@ name: update_available description: Know if there's any update for your Flutter app, based on published versions. -version: 2.3.0 +version: 3.0.0 repository: https://github.com/mateusfccp/update_available/tree/master/update_available environment: - sdk: ">=2.16.0 <3.0.0" - flutter: ">=2.10.0" + sdk: ">=3.0.0 <4.0.0" + flutter: ">=3.10.0" dependencies: flutter: sdk: flutter - update_available_android: ^2.3.0 - update_available_ios: ^2.3.0 - update_available_platform_interface: ^3.1.0 + update_available_android: ^3.0.0 + update_available_ios: ^3.0.0 + update_available_platform_interface: ^4.0.0 dev_dependencies: - flutter_lints: ^2.0.0 + flutter_lints: ^2.0.2 flutter: plugin: diff --git a/update_available_android/CHANGELOG.md b/update_available_android/CHANGELOG.md index 63c65b3..9df82ae 100644 --- a/update_available_android/CHANGELOG.md +++ b/update_available_android/CHANGELOG.md @@ -1,3 +1,8 @@ +## 3.0.0 + +- Requires Dart 3.0 or later +- `UpdateAvailableAndroidPlugin` can't be implemented, extended or mixed anymore + ## 2.3.0 - Minimum Dart SDK versions is now 2.16 diff --git a/update_available_android/lib/update_available_android.dart b/update_available_android/lib/update_available_android.dart index 8eb8672..1833d99 100644 --- a/update_available_android/lib/update_available_android.dart +++ b/update_available_android/lib/update_available_android.dart @@ -3,7 +3,7 @@ import 'dart:async'; import 'package:flutter/services.dart'; import 'package:update_available_platform_interface/update_available_platform_interface.dart'; -class UpdateAvailableAndroidPlugin extends UpdateAvailablePlatform { +final class UpdateAvailableAndroidPlugin extends UpdateAvailablePlatform { static const platform = MethodChannel('me.mateusfccp/update_available'); static void registerWith() { @@ -13,10 +13,15 @@ class UpdateAvailableAndroidPlugin extends UpdateAvailablePlatform { @override Future getUpdateAvailability({String? iosAppStoreRegion}) async { try { - final available = await platform.invokeMethod('getUpdateAvailability'); - return available ? UpdateAvailable : NoUpdateAvailable; + final available = await platform.invokeMethod('getUpdateAvailability'); + + return switch (available) { + true => const UpdateAvailable(), + false => const NoUpdateAvailable(), + null => const UnknownAvailability(), + }; } on PlatformException { - return UnknownAvailability; + return const UnknownAvailability(); } } } diff --git a/update_available_android/pubspec.yaml b/update_available_android/pubspec.yaml index 3eab1ed..ae8ba53 100644 --- a/update_available_android/pubspec.yaml +++ b/update_available_android/pubspec.yaml @@ -1,19 +1,19 @@ name: update_available_android description: Android platform implementation of update_available -version: 2.3.0 +version: 3.0.0 repository: https://github.com/mateusfccp/update_available/tree/master/update_available_android environment: - sdk: ">=2.16.0 <3.0.0" - flutter: ">=2.10.0" + sdk: ">=3.0.0 <4.0.0" + flutter: ">=3.10.0" dependencies: flutter: sdk: flutter - update_available_platform_interface: ^3.1.0 + update_available_platform_interface: ^4.0.0 dev_dependencies: - flutter_lints: ^2.0.0 + flutter_lints: ^2.0.2 flutter: plugin: diff --git a/update_available_ios/CHANGELOG.md b/update_available_ios/CHANGELOG.md index cc31a62..6da643f 100644 --- a/update_available_ios/CHANGELOG.md +++ b/update_available_ios/CHANGELOG.md @@ -1,3 +1,10 @@ +## 3.0.0 + +- Requires Dart 3.0 or later +- `UpdateAvailableIosPlugin` can't be implemented, extended or mixed anymore +- `http` removed from the dependencies +- Provide some additional tests + ## 2.3.0 - Minimum Dart SDK versions is now 2.16 diff --git a/update_available_ios/lib/adapters/get_ios_package_version_impl.dart b/update_available_ios/lib/adapters/get_ios_package_version_impl.dart index 0b71e9a..299bcba 100644 --- a/update_available_ios/lib/adapters/get_ios_package_version_impl.dart +++ b/update_available_ios/lib/adapters/get_ios_package_version_impl.dart @@ -1,4 +1,6 @@ -import 'package:http/http.dart'; +import 'dart:convert'; +import 'dart:io'; + import 'package:pub_semver/pub_semver.dart'; import '../domain/get_ios_package_version.dart'; @@ -16,8 +18,12 @@ GetIOSPackageVersion httpGetIOSPackageVersion() { uri = Uri.parse('$_itunesURL/$iosAppStoreRegion/lookup?bundleId=$bundleId'); } - final response = await get(uri); - final versionString = getStringByKey(response.body)('version'); + final client = HttpClient(); + final request = await client.getUrl(uri); + final response = await request.close(); + final responseBody = await response.transform(utf8.decoder).join(); + + final versionString = getStringByKey(responseBody)('version'); if (versionString == null) { return null; diff --git a/update_available_ios/lib/update_available_ios.dart b/update_available_ios/lib/update_available_ios.dart index fb418ec..9bf8846 100644 --- a/update_available_ios/lib/update_available_ios.dart +++ b/update_available_ios/lib/update_available_ios.dart @@ -11,7 +11,7 @@ export 'adapters/get_ios_bundle_id_impl.dart'; export 'adapters/get_ios_package_version_impl.dart'; export 'adapters/get_ios_version_impl.dart'; -class UpdateAvailableIosPlugin extends UpdateAvailablePlatform { +final class UpdateAvailableIosPlugin extends UpdateAvailablePlatform { final GetIOSBundleId getIOSBundleId; final GetIOSVersion getIOSVersion; final GetIOSPackageVersion getIOSPackageVersion; @@ -38,12 +38,12 @@ class UpdateAvailableIosPlugin extends UpdateAvailablePlatform { final version = await getIOSVersion(); if (version == null || packageVersion == null) { - return UnknownAvailability; + return const UnknownAvailability(); } else { - return packageVersion > version ? UpdateAvailable : NoUpdateAvailable; + return packageVersion > version ? const UpdateAvailable() : const NoUpdateAvailable(); } } catch (error) { - return UnknownAvailability; + return const UnknownAvailability(); } } } diff --git a/update_available_ios/pubspec.yaml b/update_available_ios/pubspec.yaml index 9c1ffd2..ae1f156 100644 --- a/update_available_ios/pubspec.yaml +++ b/update_available_ios/pubspec.yaml @@ -1,25 +1,25 @@ name: update_available_ios description: iOS platform implementation of update_available -version: 2.3.0 +version: 3.0.0 repository: https://github.com/mateusfccp/update_available/tree/master/update_available_ios environment: - sdk: ">=2.16.0 <3.0.0" - flutter: ">=2.10.0" + sdk: ">=3.0.0 <4.0.0" + flutter: ">=3.10.0" dependencies: flutter: sdk: flutter - http: ^0.13.4 - meta: ^1.8.0 + meta: ^1.9.1 package_info_plus: ^4.0.2 pub_semver: ^2.1.4 - update_available_platform_interface: ^3.1.0 + update_available_platform_interface: ^4.0.0 dev_dependencies: flutter_test: sdk: flutter - flutter_lints: ^2.0.0 + flutter_lints: ^2.0.2 + test: ^1.24.0 flutter: plugin: diff --git a/update_available_ios/test/adapters/get_ios_package_version_impl_test.dart b/update_available_ios/test/adapters/get_ios_package_version_impl_test.dart new file mode 100644 index 0000000..efefdc9 --- /dev/null +++ b/update_available_ios/test/adapters/get_ios_package_version_impl_test.dart @@ -0,0 +1,26 @@ +import 'package:test/test.dart'; +import 'package:pub_semver/pub_semver.dart'; +import 'package:update_available_ios/adapters/get_ios_package_version_impl.dart'; + +void main() { + final getVersion = httpGetIOSPackageVersion(); + + group('httpGetIOSPackageVersion', () { + test('should return null if the given bundle ID does not exist', () async { + final version = await getVersion('lorem.ipsum.dolor'); + expect(version, isNull); + }); + + test('should get the latest version of getVersion given bundle ID', () async { + final version = await getVersion('org.adventistas.armsa'); + expect(version, isNotNull); + version as Version; + expect( + version.compareTo( + VersionRange(min: Version(1, 3, 0)), + ), + 1, + ); + }); + }); +} diff --git a/update_available_ios/test/adapters/json_test.dart b/update_available_ios/test/adapters/json_test.dart index 29d8e8d..186b929 100644 --- a/update_available_ios/test/adapters/json_test.dart +++ b/update_available_ios/test/adapters/json_test.dart @@ -1,37 +1,49 @@ -import 'package:flutter_test/flutter_test.dart'; +import 'package:test/test.dart'; import 'package:update_available_ios/adapters/json.dart'; -const json = '{"artistId": 456036234,' - '"artistName": "CONFEDERACAO DAS UNIOES BRASILEIRAS DA IGREJA ADVENTISTA DO SETIMO DIA",' - '"price": 0.00,' - '"bundleId": "org.adventistas.armsa",' - '"version": "1.3.0",' - '"wrapperType": "software",' - '"userRatingCount": 0}'; +const json = ''' +{ + "artistId": 456036234, + "artistName": "CONFEDERACAO DAS UNIOES BRASILEIRAS DA IGREJA ADVENTISTA DO SETIMO DIA",' + "price": 0.00,' + "bundleId": "org.adventistas.armsa",' + "version": "1.3.0",' + "wrapperType": "software",' + "userRatingCount": 0 +}' +'''; void main() { final extract = getStringByKey(json); - test( - 'should return the value when given a valid key and value is string', - () { - expect( - extract('artistName'), - 'CONFEDERACAO DAS UNIOES BRASILEIRAS DA IGREJA ADVENTISTA DO SETIMO DIA', - ); - expect(extract('bundleId'), 'org.adventistas.armsa'); - expect(extract('version'), '1.3.0'); - expect(extract('wrapperType'), 'software'); - }, - ); + group('getStringByKey', () { + test( + 'should return the value of a key when the key exists in the object and it is a string', + () { + expect( + extract('artistName'), + 'CONFEDERACAO DAS UNIOES BRASILEIRAS DA IGREJA ADVENTISTA DO SETIMO DIA', + ); + expect(extract('bundleId'), 'org.adventistas.armsa'); + expect(extract('version'), '1.3.0'); + expect(extract('wrapperType'), 'software'); + }, + ); - test( - 'should return the null when given an invalid key or value is not', - () { - expect(extract('artistId'), null); - expect(extract('price'), null); - expect(extract('userRatingCount'), null); - expect(extract('unexistentKey'), null); - }, - ); + test( + 'should return null when a key that does not exist in the object is given', + () { + expect(extract('nonexistentKey'), isNull); + }, + ); + + test( + 'should return null when the key given, although exists in the object, has a non-string value', + () { + expect(extract('artistId'), isNull); + expect(extract('price'), isNull); + expect(extract('userRatingCount'), isNull); + }, + ); + }); } diff --git a/update_available_ios/test/update_available_ios_test.dart b/update_available_ios/test/update_available_ios_test.dart index 12f6934..f0ba92d 100644 --- a/update_available_ios/test/update_available_ios_test.dart +++ b/update_available_ios/test/update_available_ios_test.dart @@ -4,78 +4,80 @@ import 'package:update_available_ios/update_available_ios.dart'; import 'package:update_available_platform_interface/update_available_platform_interface.dart'; void main() { - test( - "should return UnknownAvailability when can't determine the package version", - () async { - // Arrange - final plugin = UpdateAvailableIosPlugin( - getIOSBundleId: () async => 'fakeId', - getIOSPackageVersion: (_, {iosAppStoreRegion}) async => null, - getIOSVersion: () async => Version(1, 0, 0), - ); + group('getUpdateAvailability', () { + test( + "should return UnknownAvailability when can't determine the package version", + () async { + // Arrange + final plugin = UpdateAvailableIosPlugin( + getIOSBundleId: () async => 'fakeId', + getIOSPackageVersion: (_, {iosAppStoreRegion}) async => null, + getIOSVersion: () async => Version(1, 0, 0), + ); - // Assert - expect(await plugin.getUpdateAvailability(), UnknownAvailability); - }, - ); + // Assert + expect(await plugin.getUpdateAvailability(), const UnknownAvailability()); + }, + ); - test( - "should return UnknownAvailability when can't determine the current version", - () async { - // Arrange - final plugin = UpdateAvailableIosPlugin( - getIOSBundleId: () async => 'fakeId', - getIOSPackageVersion: (_, {iosAppStoreRegion}) async => Version(1, 0, 0), - getIOSVersion: () async => null, - ); + test( + "should return UnknownAvailability when can't determine the current version", + () async { + // Arrange + final plugin = UpdateAvailableIosPlugin( + getIOSBundleId: () async => 'fakeId', + getIOSPackageVersion: (_, {iosAppStoreRegion}) async => Version(1, 0, 0), + getIOSVersion: () async => null, + ); - // Assert - expect(await plugin.getUpdateAvailability(), UnknownAvailability); - }, - ); + // Assert + expect(await plugin.getUpdateAvailability(), const UnknownAvailability()); + }, + ); - test( - 'should return UpdateAvailable when current version is lower than published', - () async { - // Arrange - final plugin = UpdateAvailableIosPlugin( - getIOSBundleId: () async => 'fakeId', - getIOSPackageVersion: (_, {iosAppStoreRegion}) async => Version(1, 1, 0), - getIOSVersion: () async => Version(1, 0, 0), - ); + test( + 'should return UpdateAvailable when current version is lower than published', + () async { + // Arrange + final plugin = UpdateAvailableIosPlugin( + getIOSBundleId: () async => 'fakeId', + getIOSPackageVersion: (_, {iosAppStoreRegion}) async => Version(1, 1, 0), + getIOSVersion: () async => Version(1, 0, 0), + ); - // Assert - expect(await plugin.getUpdateAvailability(), UpdateAvailable); - }, - ); + // Assert + expect(await plugin.getUpdateAvailability(), const UpdateAvailable()); + }, + ); - test( - 'should return NoUpdateAvailable when current version is equal to published', - () async { - // Arrange - final plugin = UpdateAvailableIosPlugin( - getIOSBundleId: () async => 'fakeId', - getIOSPackageVersion: (_, {iosAppStoreRegion}) async => Version(1, 0, 0), - getIOSVersion: () async => Version(1, 0, 0), - ); + test( + 'should return NoUpdateAvailable when current version is equal to published', + () async { + // Arrange + final plugin = UpdateAvailableIosPlugin( + getIOSBundleId: () async => 'fakeId', + getIOSPackageVersion: (_, {iosAppStoreRegion}) async => Version(1, 0, 0), + getIOSVersion: () async => Version(1, 0, 0), + ); - // Assert - expect(await plugin.getUpdateAvailability(), NoUpdateAvailable); - }, - ); + // Assert + expect(await plugin.getUpdateAvailability(), const NoUpdateAvailable()); + }, + ); - test( - 'should return NoUpdateAvailable when current version is bigger than published', - () async { - // Arrange - final plugin = UpdateAvailableIosPlugin( - getIOSBundleId: () async => 'fakeId', - getIOSPackageVersion: (_, {iosAppStoreRegion}) async => Version(1, 0, 0), - getIOSVersion: () async => Version(1, 1, 0), - ); + test( + 'should return NoUpdateAvailable when current version is bigger than published', + () async { + // Arrange + final plugin = UpdateAvailableIosPlugin( + getIOSBundleId: () async => 'fakeId', + getIOSPackageVersion: (_, {iosAppStoreRegion}) async => Version(1, 0, 0), + getIOSVersion: () async => Version(1, 1, 0), + ); - // Assert - expect(await plugin.getUpdateAvailability(), NoUpdateAvailable); - }, - ); + // Assert + expect(await plugin.getUpdateAvailability(), const NoUpdateAvailable()); + }, + ); + }); } diff --git a/update_available_platform_interface/CHANGELOG.md b/update_available_platform_interface/CHANGELOG.md index eb06b26..88fc3d2 100644 --- a/update_available_platform_interface/CHANGELOG.md +++ b/update_available_platform_interface/CHANGELOG.md @@ -1,3 +1,10 @@ +## 4.0.0 + +- Requires Dart 3.0 or later +- `UpdateAvailablePlatform` can't be implemented anymore (just extended) +- `Availability` is now a `sealed` class +- Removed `when` and `whenOrElse` from `Availability` + ## 3.1.0 - Minimum Dart SDK versions is now 2.16 diff --git a/update_available_platform_interface/lib/src/availability.dart b/update_available_platform_interface/lib/src/availability.dart index f3eaa3a..e24a2be 100644 --- a/update_available_platform_interface/lib/src/availability.dart +++ b/update_available_platform_interface/lib/src/availability.dart @@ -1,118 +1,29 @@ -// ignore_for_file: constant_identifier_names - import 'package:meta/meta.dart'; /// The availability of the update. /// /// An update may be available or not, which will be represented with -/// [UpdateAvailable] and [NoUpdateAvailable], respectively. Finally, if -/// the process couldn't determine if a update is available or not, an -/// [UnknownAvailability] will be yielded. +/// [UpdateAvailable] and [NoUpdateAvailable], respectively. If the process +/// couldn't determine if an update is available or not, an +/// [UnknownAvailability] will be returned. /// -/// To check against the status, the recommended way is to use [fold] or -/// [foldElse], as they are safest than comparing with `if`, because it forces -/// you to provide every possible case. - +/// To check against the status, the recommended way is using `switch`, as +/// the class is sealed and Dart will guarantee exhaustiveness. @immutable -class Availability { - final _Availability _availability; - - const Availability._(this._availability); - - /// Returns a value based on the [Availability]. - /// - /// All parameters are required and must be not `null`. - /// - /// Example: - /// ```dart - /// void main() async { - /// final updateAvailability = await getUpdateAvailability(); - /// - /// final text = updateAvailability.fold( - /// available: () => "There's an update to you app! Please, update it " - /// "so you have access to the latest features!", - /// notAvailable: () => 'No update is available for your app.', - /// unknown: () => "It was not possible to determine if there is or not " - /// "an update for your app.", - /// ); - /// - /// print(text); - /// } - /// ``` - /// - /// If you don't want to exhaustively check for each case, refer to [foldElse]. - T fold({ - required T Function() available, - required T Function() notAvailable, - required T Function() unknown, - }) { - if (_availability == _Availability.UpdateAvailable) { - return available(); - } else if (_availability == _Availability.NoUpdateAvailable) { - return notAvailable(); - } else { - return unknown(); - } - } - - /// Returns a value based on the [Availability], non-exhaustively. - /// - /// Instead of passing all the cases exhaustively, only [orElse] is mandatory, - /// while all others are optional. - /// - /// Example: - /// ```dart - /// void main() async { - /// final updateAvailability = await getUpdateAvailability(); - /// - /// final text = updateAvailability.foldElse( - /// available: () => "There's an update to you app! Please, update it " - /// "so you have access to the latest features!", - /// orElse: () => 'No update is available for your app.', - /// ); - /// - /// print(text); - /// } - /// ``` - T foldElse({ - T Function()? available, - T Function()? notAvailable, - T Function()? unknown, - required T Function() orElse, - }) { - if (available != null && _availability == _Availability.UpdateAvailable) { - return available(); - } else if (notAvailable != null && _availability == _Availability.NoUpdateAvailable) { - return notAvailable(); - } else if (unknown != null && _availability == _Availability.UnknownAvailability) { - return unknown(); - } else { - return orElse(); - } - } - - @override - String toString() { - return fold( - available: () => 'Update available', - notAvailable: () => 'No update available', - unknown: () => 'Unknown availability', - ); - } -} - -enum _Availability { - UpdateAvailable, - NoUpdateAvailable, - UnknownAvailability, -} +sealed class Availability {} /// Represents that an update is available. -const UpdateAvailable = Availability._(_Availability.UpdateAvailable); +final class UpdateAvailable implements Availability { + const UpdateAvailable(); +} /// Represents that no update is available. -const NoUpdateAvailable = Availability._(_Availability.NoUpdateAvailable); +final class NoUpdateAvailable implements Availability { + const NoUpdateAvailable(); +} /// Represents that it was not possible to determine if an update is available /// or not. -const UnknownAvailability = Availability._(_Availability.UnknownAvailability); +final class UnknownAvailability implements Availability { + const UnknownAvailability(); +} diff --git a/update_available_platform_interface/lib/src/interface.dart b/update_available_platform_interface/lib/src/interface.dart index cccb094..654b1fc 100644 --- a/update_available_platform_interface/lib/src/interface.dart +++ b/update_available_platform_interface/lib/src/interface.dart @@ -3,7 +3,7 @@ import 'package:plugin_platform_interface/plugin_platform_interface.dart'; import 'availability.dart'; /// The platform interface for update_available. -abstract class UpdateAvailablePlatform extends PlatformInterface { +abstract base class UpdateAvailablePlatform extends PlatformInterface { UpdateAvailablePlatform() : super(token: _token); static final Object _token = Object(); @@ -32,4 +32,4 @@ abstract class UpdateAvailablePlatform extends PlatformInterface { } /// The unimplemented platform for [UpdateAvailablePlatform]. -class UnimplementedUpdateAvailable extends UpdateAvailablePlatform {} +final class UnimplementedUpdateAvailable extends UpdateAvailablePlatform {} diff --git a/update_available_platform_interface/lib/update_available_platform_interface.dart b/update_available_platform_interface/lib/update_available_platform_interface.dart index 16eac52..8204edc 100644 --- a/update_available_platform_interface/lib/update_available_platform_interface.dart +++ b/update_available_platform_interface/lib/update_available_platform_interface.dart @@ -1,4 +1,2 @@ -library update_available_platform_interface; - export 'src/availability.dart'; export 'src/interface.dart'; diff --git a/update_available_platform_interface/pubspec.yaml b/update_available_platform_interface/pubspec.yaml index 57d4bea..1d6e307 100644 --- a/update_available_platform_interface/pubspec.yaml +++ b/update_available_platform_interface/pubspec.yaml @@ -1,14 +1,14 @@ name: update_available_platform_interface description: A common platform interface for the update_available plugin. -version: 3.1.0 +version: 4.0.0 repository: https://github.com/mateusfccp/update_available/tree/master/update_available_platform_interface environment: - sdk: ">=2.16.0 <3.0.0" + sdk: ">=3.0.0 <4.0.0" dependencies: - meta: ^1.8.0 + meta: ^1.9.1 plugin_platform_interface: ^2.1.4 dev_dependencies: - flutter_lints: ^2.0.0 + flutter_lints: ^2.0.2