Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Mus2413 committed Mar 27, 2021
2 parents 68a9e7f + 2062487 commit bae953a
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -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<void> main() async {

//firebase Initialization
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
//AdMob Initialization
final Future<InitializationStatus> initFuture =
MobileAds.instance.initialize();

//Initialize remote config
_remoteConfigService= await RemoteConfigService.getInstance();
await _remoteConfigService.initialize();

final AdState adState = AdState(initFuture);

runApp(
Expand Down
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);
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();
}

}
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 bae953a

Please sign in to comment.