diff --git a/CHANGELOG.md b/CHANGELOG.md index 50c069f..f2d6021 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index f27917a..c21fac0 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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: @@ -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 + 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 diff --git a/lib/src/manup_delegate.dart b/lib/src/manup_delegate.dart index c7f8718..05f8996 100644 --- a/lib/src/manup_delegate.dart +++ b/lib/src/manup_delegate.dart @@ -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(); diff --git a/lib/src/mixin/manup_delegate_mixin.dart b/lib/src/mixin/manup_delegate_mixin.dart index 2f92353..81a1bde 100644 --- a/lib/src/mixin/manup_delegate_mixin.dart +++ b/lib/src/mixin/manup_delegate_mixin.dart @@ -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() {} diff --git a/lib/src/ui/manup_widget.dart b/lib/src/ui/manup_widget.dart index d053683..8678080 100644 --- a/lib/src/ui/manup_widget.dart +++ b/lib/src/ui/manup_widget.dart @@ -36,18 +36,17 @@ class _ManUpWidgetState extends State 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) { diff --git a/pubspec.lock b/pubspec.lock index d27f08a..1c61442 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,27 +1,13 @@ # 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: @@ -29,6 +15,13 @@ packages: 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: @@ -36,27 +29,27 @@ packages: 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 @@ -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: @@ -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: @@ -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 @@ -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: @@ -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: @@ -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" diff --git a/pubspec.yaml b/pubspec.yaml index 7d305d3..09d6958 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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: