Skip to content

Commit

Permalink
Add ChangeNotifier to ManUpService
Browse files Browse the repository at this point in the history
- `ManUpService` now implements `ChangeNotifier` and the most recent status can be retrieved from the `status` getter
- `onComplete`, `onError` and `shouldShowAlert` on `ManUpWidget` are now optional (`shouldShowAlert` defaults to `() => true`)
- `ManUpWidget` now exposes an optional `onStatusChanged`
- "Kill switch" (`disabled`) and required update alert dialogs are no longer barrier dismissable.
- Changes to status will now show updated dialogs
- Update examples
  • Loading branch information
zbarbuto committed Sep 19, 2024
1 parent 6b0feeb commit 3cf53ad
Show file tree
Hide file tree
Showing 21 changed files with 997 additions and 393 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ test/firebase_remote_config_man_up_service_test.mocks.dart
.pub-cache/
.pub/
/build/


example/ios
example/android
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# manUp

## [9.1.0]

- `ManUpService` now implements `ChangeNotifier` and the most recent status can be retrieved from the `status` getter
- `onComplete`, `onError` and `shouldShowAlert` on `ManUpWidget` are now optional (`shouldShowAlert` defaults to `() => true`)
- `ManUpWidget` now exposes an optional `onStatusChanged`
- "Kill switch" (`disabled`) and required update alert dialogs are no longer barrier dismissable.
- Changes to status will now show updated dialogs
- Update examples

## [9.0.1]

- Relax version requirements for firebase
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# Manup
# ManUp

*Man*datory *Up*dates for Flutter

[![pub package](https://img.shields.io/pub/v/manup.svg)](https://pub.dartlang.org/packages/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)

![image](./example.gif)

Sometimes you have an app which talks to services in the cloud. Sometimes,
those services change, and your app no longer works. Wouldn't it be great if
the app could let the user know there's an update? That's what this module
Expand Down
Binary file added example.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion example/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ macos/
windows/
web/
linux/
firebase_options.dart
firebase_options.dart
.metadata
45 changes: 0 additions & 45 deletions example/.metadata

This file was deleted.

84 changes: 16 additions & 68 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,83 +1,31 @@
import 'dart:async';

import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_remote_config/firebase_remote_config.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart';
import 'package:manup/manup.dart';

// See /examples for more examples
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
// You can get DefaultFirebaseOptions from the generated file(firebase_options.dart)
// from flutterfire_cli

// options: DefaultFirebaseOptions.currentPlatform,
);

runApp(const MyApp());
}

class MyApp extends StatefulWidget {
const MyApp({super.key});

@override
State<MyApp> createState() => _MyAppState();
runApp(const ExampleApp());
}

class _MyAppState extends State<MyApp> {
late FireBaseRemoteConfigManUpService manUpService;

String statusStr = 'unknown';
String latestVersion = '-';

@override
void initState() {
super.initState();
manUpService = FireBaseRemoteConfigManUpService(
remoteConfig: FirebaseRemoteConfig.instance,
// Parameter name (key) in remote config
paramName: 'configName',
);
}
class ExampleApp extends StatelessWidget {
const ExampleApp({super.key});

@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'App',
home: Scaffold(
body: ManUpWidget(
service: manUpService,
shouldShowAlert: () => true,
onComplete: (bool isComplete) => debugPrint('Validate complete'),
onError: (dynamic e) => debugPrint('Error: $e'),
child: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text('Status: $statusStr'),
Text('Latest version: $latestVersion'),
],
)),
),
floatingActionButton: FloatingActionButton(
child: const Text('Validate'),
onPressed: () {
manUpService.validate().then((status) {
setState(() {
statusStr = status.name;
latestVersion = manUpService
.setting(
key: 'latest',
orElse: '',
os: 'ios',
)
.toString();
});
}).catchError((error) {
debugPrint('error: $error');
});
},
),
home: ManUpWidget(
// Alternatively, use [FireBaseRemoteConfigManUpService] or implement
// your own [ManUpService]
service: HttpManUpService('https://example.com/my_config.json',
http: Client()),
child: const Text('My App'),
// Optionals
onComplete: (_) {},
onError: (_) {},
onStatusChanged: (status) {},
shouldShowAlert: () => true,
),
);
}
Expand Down
Loading

0 comments on commit 3cf53ad

Please sign in to comment.