diff --git a/lib/main.dart b/lib/main.dart index 190f46f..0b1b6af 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,19 +1,28 @@ import 'package:firebase_core/firebase_core.dart'; +import 'package:firebase_remote_config/firebase_remote_config.dart'; import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:provider/provider.dart'; +import 'services/remote_config.dart'; import 'package:retro_shopping/helpers/ad_state.dart'; import 'package:retro_shopping/helpers/constants.dart'; import 'package:google_mobile_ads/google_mobile_ads.dart'; import 'package:retro_shopping/helpers/route_page.dart'; +RemoteConfigService _remoteConfigService; Future main() async { + //firebase Initialization WidgetsFlutterBinding.ensureInitialized(); await Firebase.initializeApp(); //AdMob Initialization final Future initFuture = MobileAds.instance.initialize(); + + //Initialize remote config + _remoteConfigService= await RemoteConfigService.getInstance(); + await _remoteConfigService.initialize(); + final AdState adState = AdState(initFuture); runApp( diff --git a/lib/services/remote_config.dart b/lib/services/remote_config.dart new file mode 100644 index 0000000..eaf44f6 --- /dev/null +++ b/lib/services/remote_config.dart @@ -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={ + _BOOLEAN_VALUE:false, + _INT_VALUE:01, + _STRING_VALUE:"Remote Config Sample", + }; + + static RemoteConfigService _instance; + static Future 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(); + } + +} \ No newline at end of file diff --git a/pubspec.yaml b/pubspec.yaml index fabe1a2..26ab927 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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