Masamune Model Firebase Remote Config
[GitHub](https://github.com/mathrunet) | [YouTube](https://www.youtube.com/c/mathrunetchannel) | [Packages](https://pub.dev/publishers/mathru.net/packages) | [X](https://x.com/mathru) | [LinkedIn](https://www.linkedin.com/in/mathrunet/) | [mathru.net](https://mathru.net)
Masamune Model Firebase Remote Config
Usage
Installation
- Add the package to your project.
flutter pub add masamune_model_firebase_remote_config
Run flutter pub get after editing pubspec.yaml manually.
Setup
- Register the adapter with your Masamune model configuration. Provide default values and fetch intervals.
// lib/main.dart
import 'package:masamune_model_firebase_remote_config/masamune_model_firebase_remote_config.dart';
final modelAdapter = FirebaseRemoteConfigModelAdapter(
options: DefaultFirebaseOptions.currentPlatform, // Firebase config
initialValue: {
"feature_enabled": false,
"api_endpoint": "https://api.example.com",
"max_items": 10,
},
minimumFetchInterval: Duration(minutes: 30), // Cache duration
);
void main() {
runMasamuneApp(
appRef: appRef,
modelAdapter: modelAdapter,
(appRef, _) => MasamuneApp(
appRef: appRef,
home: HomePage(),
),
);
}
Load Remote Config Values
- Load the remote config as a Masamune model. Fetching is handled automatically through
fetchAndActivate()each time the adapter loads.
class MyPage extends PageScopedWidget {
@override
Widget build(BuildContext context, PageRef ref) {
// Load remote config as a document
final config = ref.app.model(
FirebaseRemoteConfigModel.document(),
)..load();
return Scaffold(
body: Column(
children: [
// Access config values
Text("Feature: ${config.value.get<bool>("feature_enabled")}"),
Text("Endpoint: ${config.value.get<String>("api_endpoint")}"),
Text("Max Items: ${config.value.get<int>("max_items")}"),
],
),
);
}
}
Important Notes
Read-Only: Only read operations are supported. Saving or deleting documents with this adapter throws UnsupportedError. Use Firebase Console or the Remote Config REST API to update values.
Caching: The adapter respects minimumFetchInterval. Values are cached and won't be refetched until the interval expires.
Default Values: Provide initialValue to ensure your app works even when remote config is unavailable.
Firebase Console Setup
- Go to Firebase Console → Remote Config
- Add parameters matching your
initialValuekeys - Set values for different conditions (e.g., by platform, version, or user segment)
- Publish your changes
GitHub Sponsors
Sponsors are always welcome. Thank you for your support!
Libraries
- masamune_model_firebase_remote_config
- Package that allows remote configurations to be retrieved as a Masamune framework documentation model.