Skip to content

Commit

Permalink
Create FireBaseRemoteConfigManUpService and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wasinnimlaor committed Jan 11, 2024
1 parent 39c5e36 commit 84fde9d
Show file tree
Hide file tree
Showing 6 changed files with 712 additions and 17 deletions.
66 changes: 66 additions & 0 deletions lib/src/firebase_remote_config_man_up_service.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import 'dart:async';
import 'dart:convert';

import 'package:firebase_remote_config/firebase_remote_config.dart';
import 'package:flutter/foundation.dart';
import 'package:manup/manup.dart';

class FireBaseRemoteConfigManUpService extends ManUpService {
final FirebaseRemoteConfig remoteConfig;
late StreamSubscription remoteConfigSubscription;
final PackageInfoProvider packageInfoProvider;
final String? os;
final String paramName;

ManUpDelegate? delegate;

FireBaseRemoteConfigManUpService({
required this.remoteConfig,
required this.paramName,
this.os,
this.packageInfoProvider = const DefaultPackageInfoProvider(),
ConfigStorage storage = const ConfigStorage(),
this.delegate,
}) : super(
delegate: delegate,
os: os,
packageInfoProvider: packageInfoProvider,
storage: storage,
) {
// Listen for updates in real time
remoteConfigSubscription =
remoteConfig.onConfigUpdated.listen((RemoteConfigUpdate event) async {
await remoteConfig.activate();

// Use the new config values here.
final remoteConfigValue = remoteConfig.getValue(paramName);
final data = remoteConfigValue.asString();
Map<String, dynamic>? json = jsonDecode(data);
validate(Metadata(data: json));
});
}

Future<Metadata> getMetadata() async {
try {
await remoteConfig.fetchAndActivate();
final remoteConfigValue = remoteConfig.getValue(paramName);
final data = remoteConfigValue.asString();
Map<String, dynamic>? json = jsonDecode(data);
final Metadata metaData = Metadata(data: json);
return metaData;
} catch (exception) {
if (kIsWeb) throw exception;
try {
var metadata = await readManUpFile();
return metadata;
} catch (e) {
throw ManUpException(exception.toString());
}
}
}

void close() {
remoteConfigSubscription.cancel();
super.close();
}
}
122 changes: 105 additions & 17 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "61.0.0"
_flutterfire_internals:
dependency: transitive
description:
name: _flutterfire_internals
sha256: f5628cd9c92ed11083f425fd1f8f1bc60ecdda458c81d73b143aeda036c35fe7
url: "https://pub.dev"
source: hosted
version: "1.3.16"
analyzer:
dependency: transitive
description:
Expand Down Expand Up @@ -141,10 +149,10 @@ packages:
dependency: transitive
description:
name: collection
sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c"
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
url: "https://pub.dev"
source: hosted
version: "1.17.1"
version: "1.18.0"
convert:
dependency: transitive
description:
Expand Down Expand Up @@ -193,6 +201,78 @@ packages:
url: "https://pub.dev"
source: hosted
version: "6.1.4"
firebase_analytics:
dependency: "direct main"
description:
name: firebase_analytics
sha256: "0240076090d77045d757aecb090616066d23b343840d4c21074094d6fe40a184"
url: "https://pub.dev"
source: hosted
version: "10.8.0"
firebase_analytics_platform_interface:
dependency: transitive
description:
name: firebase_analytics_platform_interface
sha256: "6d9baa077d16b47ef5f19d982c4fc475597991aa53b0c601216faa3e1cdab45f"
url: "https://pub.dev"
source: hosted
version: "3.9.0"
firebase_analytics_web:
dependency: transitive
description:
name: firebase_analytics_web
sha256: "89a740249bce9d52a99db4e501be6087ca6749c73c47cff2b174802be10abd81"
url: "https://pub.dev"
source: hosted
version: "0.5.5+12"
firebase_core:
dependency: transitive
description:
name: firebase_core
sha256: "96607c0e829a581c2a483c658f04e8b159964c3bae2730f73297070bc85d40bb"
url: "https://pub.dev"
source: hosted
version: "2.24.2"
firebase_core_platform_interface:
dependency: transitive
description:
name: firebase_core_platform_interface
sha256: c437ae5d17e6b5cc7981cf6fd458a5db4d12979905f9aafd1fea930428a9fe63
url: "https://pub.dev"
source: hosted
version: "5.0.0"
firebase_core_web:
dependency: transitive
description:
name: firebase_core_web
sha256: d585bdf3c656c3f7821ba1bd44da5f13365d22fcecaf5eb75c4295246aaa83c0
url: "https://pub.dev"
source: hosted
version: "2.10.0"
firebase_remote_config:
dependency: "direct main"
description:
name: firebase_remote_config
sha256: "60fc92273d1db338a6fad1839c42dedc4ad64f812043acad0cbb200702f5c9ce"
url: "https://pub.dev"
source: hosted
version: "4.3.8"
firebase_remote_config_platform_interface:
dependency: transitive
description:
name: firebase_remote_config_platform_interface
sha256: "41813ef8dfbc40ef7a59a73f9e5acef2608dbcb2933241b6c03d52e90677040f"
url: "https://pub.dev"
source: hosted
version: "1.4.16"
firebase_remote_config_web:
dependency: transitive
description:
name: firebase_remote_config_web
sha256: "089e92f333c2fb2c05c640c80fecea9d1e06dada0ba85efe34a580987ef94a0a"
url: "https://pub.dev"
source: hosted
version: "1.4.16"
fixnum:
dependency: transitive
description:
Expand Down Expand Up @@ -300,26 +380,26 @@ packages:
dependency: transitive
description:
name: matcher
sha256: "6501fbd55da300384b768785b83e5ce66991266cec21af89ab9ae7f5ce1c4cbb"
sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e"
url: "https://pub.dev"
source: hosted
version: "0.12.15"
version: "0.12.16"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724
sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41"
url: "https://pub.dev"
source: hosted
version: "0.2.0"
version: "0.5.0"
meta:
dependency: "direct main"
description:
name: meta
sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3"
sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e
url: "https://pub.dev"
source: hosted
version: "1.9.1"
version: "1.10.0"
mime:
dependency: transitive
description:
Expand Down Expand Up @@ -497,26 +577,26 @@ packages:
dependency: transitive
description:
name: source_span
sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250
sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c"
url: "https://pub.dev"
source: hosted
version: "1.9.1"
version: "1.10.0"
stack_trace:
dependency: transitive
description:
name: stack_trace
sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5
sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b"
url: "https://pub.dev"
source: hosted
version: "1.11.0"
version: "1.11.1"
stream_channel:
dependency: transitive
description:
name: stream_channel
sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8"
sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7
url: "https://pub.dev"
source: hosted
version: "2.1.1"
version: "2.1.2"
stream_transform:
dependency: transitive
description:
Expand Down Expand Up @@ -545,10 +625,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: eb6ac1540b26de412b3403a163d919ba86f6a973fe6cc50ae3541b80092fdcfb
sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b"
url: "https://pub.dev"
source: hosted
version: "0.5.1"
version: "0.6.1"
timing:
dependency: transitive
description:
Expand Down Expand Up @@ -645,6 +725,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.1.0"
web:
dependency: transitive
description:
name: web
sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152
url: "https://pub.dev"
source: hosted
version: "0.3.0"
web_socket_channel:
dependency: transitive
description:
Expand Down Expand Up @@ -678,5 +766,5 @@ packages:
source: hosted
version: "3.1.2"
sdks:
dart: ">=3.0.0 <4.0.0"
dart: ">=3.2.0-194.0.dev <4.0.0"
flutter: ">=3.3.0"
2 changes: 2 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ dependencies:
meta: ^1.8.0
url_launcher: ^6.1.6
path_provider: ^2.0.11
firebase_remote_config: ^4.3.8
firebase_analytics: ^10.8.0

dev_dependencies:
flutter_test:
Expand Down
Loading

0 comments on commit 84fde9d

Please sign in to comment.