Skip to content

Commit

Permalink
Firebase Remote Config
Browse files Browse the repository at this point in the history
  • Loading branch information
pawan2806 committed Mar 26, 2021
1 parent 9c28ee5 commit dec3c6e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
47 changes: 47 additions & 0 deletions lib/services/remote_config.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_remote_config/firebase_remote_config.dart';
import 'package:flutter/material.dart';

const String _BOOLEAN_VALUE="sample_bool_value";
const String _INT_VALUE="sample_int_value";
const String _STRING_VALUE="sample_string_value";
class RemoteConfigService {
final RemoteConfig _remoteConfig;
RemoteConfigService({RemoteConfig remoteConfig }) :_remoteConfig=remoteConfig;
final defaults=<String, dynamic>{
_BOOLEAN_VALUE:false,
_INT_VALUE:01,
_STRING_VALUE:"Remote Config Sample",
};

static RemoteConfigService _instance;
static Future<RemoteConfigService> getInstance() async {
if(_instance==null){
_instance=RemoteConfigService(
remoteConfig: await RemoteConfig.instance,
);
}
return _instance;
}

bool get getBoolValue=>_remoteConfig.getBool(_BOOLEAN_VALUE);
bool get getIntValue=>_remoteConfig.getBool(_INT_VALUE);
bool get getStringValue=>_remoteConfig.getBool(_STRING_VALUE);

Future initialize() async {
try {
await _remoteConfig.setDefaults(defaults);
await _fetchAndActivate();
} on FetchThrottledException catch (e) {
print("Remote config fetch throttled : $e");
} catch (e){
print("Unable to fecth");
}
}

Future _fetchAndActivate() async {
await _remoteConfig.fetch(expiration: Duration(hours: 4));
await _remoteConfig.activateFetched();
}

}
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ dependencies:
sdk: flutter

fluttertoast: ^7.1.8
firebase_remote_config: ^0.6.0
firebase_core: 0.7.0
google_fonts: ^1.1.0
razorpay_flutter: 1.1.0
Expand Down

0 comments on commit dec3c6e

Please sign in to comment.