Skip to content

Commit

Permalink
Merge 51c0b11 into 33dd279
Browse files Browse the repository at this point in the history
  • Loading branch information
it-sam committed Aug 6, 2020
2 parents 33dd279 + 51c0b11 commit 0eec136
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 11 deletions.
68 changes: 68 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
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

0 comments on commit 0eec136

Please sign in to comment.