-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #160 from pawan2806/master
Integrate Remote Config #48
- Loading branch information
Showing
3 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
int get getIntValue=>_remoteConfig.getInt(_INT_VALUE); | ||
String get getStringValue=>_remoteConfig.getString(_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(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters