Skip to content

Commit

Permalink
Feature/update delegates (#10)
Browse files Browse the repository at this point in the history
* Update change log

* Remove shouldShowManupAlert methods

* Fix mixin delegate typo

* Update readME

* Upgrading version to 1.0.0 with changelog

Co-authored-by: sparmar <[email protected]>
  • Loading branch information
it-sam and sparmar authored Aug 6, 2020
1 parent 33dd279 commit b7fe5f0
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 71 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
## [1.0.0]
### First major release
Added Delegate support with `ManupDelegate`
Added Helper Widget with `ManUpWidget`
Check `README` file for full details.
## [0.0.3]
First manup release
70 changes: 69 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Mandatory Update
# Manup

[![Build Status](https://travis-ci.org/NextFaze/flutter_manup.svg?branch=master)](https://travis-ci.org/NextFaze/flutter_manup) [![Coverage Status](https://coveralls.io/repos/github/NextFaze/flutter_manup/badge.svg?branch=master)](https://coveralls.io/github/NextFaze/flutter_manup?branch=master)

Expand Down Expand Up @@ -39,6 +39,7 @@ You can use `ManUpService` directly in your code. As part of your app startup lo
```dart
ManUpService service = ManUpService('https://example.com/manup.json');
ManUpStatus result = await service.validate();
service.close();
```

`ManUpStatus` will let you know how the version of the app running compares to the metadata:
Expand All @@ -48,6 +49,73 @@ ManUpStatus result = await service.validate();
- `unsupported`: The app is an unsupported version and should not run
- `disabled`: The app has been marked as disabled and should not run

### Using the Service with Delegate

Implement `ManupDelegate` or use `ManupDelegateMixin` mixin which has default implementation.

- `manUpConfigUpdateStarting()` : will be called before starting to validate
- `manupStatusChanged(ManUpStatus status)` : will be called every time status changes
- `manUpUpdateAvailable()` : will be called when ManUpStatus changes to supported
- `manUpUpdateRequired()` : will be called when ManUpStatus changes to unsupported
- `manUpMaintenanceMode()`: will be called when ManUpStatus changes to disabled

## Example

```dart
class ManUpExample extends StatefulWidget {
ManUpExample({Key key}) : super(key: key);
@override
_ManUpExampleState createState() => _ManUpExampleState();
}
class _ManUpExampleState extends State<ManUpExample>
with ManupDelegate, ManupDelegateMixin, DialogMixin {
ManUpService service;
@override
void initState() {
super.initState();
service = ManUpService("https://example.com/manup.json",
http: http.Client(), os: Platform.operatingSystem);
service.delegate = this;
service.validate();
}
@override
Widget build(BuildContext context) {
return Container();
}
@override
void manUpStatusChanged(ManUpStatus status) {
// handle status or show default dialog
showManupDialog(status, service.getMessage(forStatus: status),
service.configData.updateUrl);
}
@override
void dispose() {
service?.close();
super.dispose();
}
}
```

### Using the Service with Helper Widget
Wrap your widget with `ManUpWidget` to automaticaly handle every thing.
```dart
@override
Widget build(BuildContext context) {
return Scaffold(
body: ManUpWidget(
service: manUpService,
shouldShowAlert: () => true,
onComplete: (bool isComplete) => print(isComplete),
onError: (dynamic e) => print(e.toString()),
child: Container()),
);
}
```
### Exception Handling

`validate` will throw a `ManUpException` if the lookup failed for any reason. Most likely, this will be caused
Expand Down
2 changes: 0 additions & 2 deletions lib/src/manup_delegate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ part of manup;
/// `ManupDelegate` class has required methods.
/// Default implemetation is in `ManupDelegateMixin` file.
abstract class ManupDelegate {
bool get shouldShowManupAlert;
// informative
void manUpStatusChanged(ManUpStatus status);
void manUpConfigUpdateStarting();
void manUpUpdateRequired();
Expand Down
4 changes: 1 addition & 3 deletions lib/src/mixin/manup_delegate_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ part of manup;

/// Default implemetation of [ManupDelegate]
mixin ManupDelegateMixin on ManupDelegate {
bool get shouldShowManupAlert => true;
// informative
void manupStatusChanged(ManUpStatus status) {}
void manUpStatusChanged(ManUpStatus status) {}
void manUpConfigUpdateStarting() {}
void manUpUpdateRequired() {}
void manUpUpdateAvailable() {}
Expand Down
11 changes: 5 additions & 6 deletions lib/src/ui/manup_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,17 @@ class _ManUpWidgetState extends State<ManUpWidget>
WidgetsBinding.instance?.addObserver(this);
}

@override
Widget build(BuildContext context) => widget?.child;

validateManup() {
widget.service.validate().catchError((e) => widget?.onError(e));
}

@override
Widget build(BuildContext context) => widget?.child;

// man up delegate
@override
// Man up
bool get shouldShowManupAlert =>
this?.widget?.shouldShowAlert?.call() ?? true;

// man up delegate
@override
void manUpStatusChanged(ManUpStatus status) {
if (status == ManUpStatus.latest) {
Expand Down
81 changes: 23 additions & 58 deletions pubspec.lock
Original file line number Diff line number Diff line change
@@ -1,62 +1,55 @@
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
archive:
dependency: transitive
description:
name: archive
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.13"
args:
dependency: transitive
description:
name: args
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.0"
async:
dependency: transitive
description:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.1"
version: "2.4.2"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
characters:
dependency: transitive
description:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.3"
collection:
clock:
dependency: transitive
description:
name: collection
name: clock
url: "https://pub.dartlang.org"
source: hosted
version: "1.14.12"
convert:
version: "1.0.1"
collection:
dependency: transitive
description:
name: convert
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.1"
crypto:
version: "1.14.13"
fake_async:
dependency: transitive
description:
name: crypto
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.4"
version: "1.1.0"
flutter:
dependency: "direct main"
description: flutter
Expand Down Expand Up @@ -86,20 +79,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.3"
image:
dependency: transitive
description:
name: image
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.12"
matcher:
dependency: transitive
description:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.6"
version: "0.12.8"
meta:
dependency: "direct main"
description:
Expand Down Expand Up @@ -127,14 +113,7 @@ packages:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.4"
petitparser:
dependency: transitive
description:
name: petitparser
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.0"
version: "1.7.0"
platform_detect:
dependency: transitive
description:
Expand All @@ -156,13 +135,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.4.2"
quiver:
dependency: transitive
description:
name: quiver
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.3"
sky_engine:
dependency: transitive
description: flutter
Expand All @@ -181,7 +153,7 @@ packages:
name: stack_trace
url: "https://pub.dartlang.org"
source: hosted
version: "1.9.3"
version: "1.9.5"
stream_channel:
dependency: transitive
description:
Expand Down Expand Up @@ -209,14 +181,14 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.15"
version: "0.2.17"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.6"
version: "1.2.0"
url_launcher:
dependency: "direct main"
description:
Expand Down Expand Up @@ -259,13 +231,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.8"
xml:
dependency: transitive
description:
name: xml
url: "https://pub.dartlang.org"
source: hosted
version: "3.6.1"
sdks:
dart: ">=2.6.0 <3.0.0"
dart: ">=2.9.0-14.0.dev <3.0.0"
flutter: ">=1.12.13+hotfix.5 <2.0.0"
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: manup
description: Mandatory update for Flutter Apps.
version: 0.0.3
version: 1.0.0
homepage: https://github.com/NextFaze/flutter_manup

environment:
Expand Down

0 comments on commit b7fe5f0

Please sign in to comment.