Skip to content

Commit

Permalink
v3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusfccp authored Aug 3, 2023
1 parent b51cc7d commit a57d99e
Show file tree
Hide file tree
Showing 22 changed files with 250 additions and 263 deletions.
9 changes: 9 additions & 0 deletions update_available/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
21 changes: 11 additions & 10 deletions update_available/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@

* 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

Add `update_available` as a dependency in your `pubspec.yaml`:

```yaml
dependencies:
update_available: ^2.0.0
update_available: ^3.0.0
```
Update your packages with `flutter pub get`.
Expand All @@ -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).

Expand All @@ -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);
}
Expand Down
10 changes: 5 additions & 5 deletions update_available/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ class _UpdateAvailableExampleState extends State<UpdateAvailableExample> {
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!",
};
});
}
}
2 changes: 1 addition & 1 deletion update_available/example/lib/shared/button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions update_available/example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -15,7 +15,7 @@ dependencies:
path: ..

dev_dependencies:
flutter_lints: ^2.0.0
flutter_lints: ^2.0.2

dependency_overrides:
update_available_android:
Expand Down
12 changes: 5 additions & 7 deletions update_available/lib/update_available.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
/// }
Expand Down
14 changes: 7 additions & 7 deletions update_available/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
5 changes: 5 additions & 0 deletions update_available_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
13 changes: 9 additions & 4 deletions update_available_android/lib/update_available_android.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -13,10 +13,15 @@ class UpdateAvailableAndroidPlugin extends UpdateAvailablePlatform {
@override
Future<Availability> getUpdateAvailability({String? iosAppStoreRegion}) async {
try {
final available = await platform.invokeMethod('getUpdateAvailability');
return available ? UpdateAvailable : NoUpdateAvailable;
final available = await platform.invokeMethod<bool>('getUpdateAvailability');

return switch (available) {
true => const UpdateAvailable(),
false => const NoUpdateAvailable(),
null => const UnknownAvailability(),
};
} on PlatformException {
return UnknownAvailability;
return const UnknownAvailability();
}
}
}
10 changes: 5 additions & 5 deletions update_available_android/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
7 changes: 7 additions & 0 deletions update_available_ios/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions update_available_ios/lib/update_available_ios.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}
}
}
14 changes: 7 additions & 7 deletions update_available_ios/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
);
});
});
}
Loading

0 comments on commit a57d99e

Please sign in to comment.