- Create a new Firebase project using flutterfire configure command
flutterfire configure
-
Create new parameter in Firebase Remote Config
-
Configure Flutter_Local_Notifications for Android and IOS
BACKEND_URL = https://test.backend.com
- Add firebase_remote_config to your pubspec.yaml
dependencies:
firebase_core: ^2.11.0
firebase_remote_config: ^4.1.0
- Add Following to your
main.dart
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'config/remote_config_setup.dart';
import 'firebase_options.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
// Firebase Core setup
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
// Remote Config Setup
await remoteConfig();
// Run your app after this
}
remoteConfig()
setup
import 'package:firebase_remote_config/firebase_remote_config.dart';
import 'package:firebase_remote_config_as_env/constants/urls.dart';
Future<void> remoteConfig() async {
final remoteConfig = FirebaseRemoteConfig.instance;
await remoteConfig.setConfigSettings(RemoteConfigSettings(
fetchTimeout: const Duration(minutes: 1),
minimumFetchInterval: const Duration(hours: 1),
));
await remoteConfig.fetchAndActivate();
// GET CONFIGS HERE
AppUrls.backendBaseUrl = remoteConfig.getString('BACKEND_URL');
print(AppUrls.backendBaseUrl);
// BACKEND_URL is the parameter we have used in Firebase Remote Config
return;
}
Medium Article: https://medium.com/@rohan.doshi02/using-firebase-remote-config-as-production-environment-config-in-flutter-app-e6cf60714278