'Setting Up Firebase Remote Config in Test in Flutter
I'm trying to add firebase remote config mock to test my Flutter app. I have this file as a mock https://github.com/pusp/flutterfire/blob/c3b13af41e2fadc22a44ebbcd14a8ac4736d9e75/packages/firebase_remote_config/firebase_remote_config/test/mock.dart
typedef Callback(MethodCall call);
setupFirebaseRemoteConfigMocks([Callback customHandlers]) {
TestWidgetsFlutterBinding.ensureInitialized();
MethodChannelFirebase.channel.setMockMethodCallHandler((call) async {
if (call.method == 'Firebase#initializeCore') {
return [
{
'name': defaultFirebaseAppName,
'options': {
'apiKey': '123',
'appId': '123',
'messagingSenderId': '123',
'projectId': '123',
},
'pluginConstants': {},
}
];
}
if (call.method == 'Firebase#initializeApp') {
return {
'name': call.arguments['appName'],
'options': call.arguments['options'],
'pluginConstants': {},
};
}
if (customHandlers != null) {
customHandlers(call);
}
return null;
});
}
and added following in setUpAll function in my Flutter test file
setUpAll(() async {
setupFirebaseRemoteConfigMocks();
await Firebase.initializeApp();
});
Here is how I'm loading Firebase remote config in the source file
RemoteConfig remoteConfig = RemoteConfig.instance;
await remoteConfig.setConfigSettings(RemoteConfigSettings(
fetchTimeout: const Duration(seconds: 10),
minimumFetchInterval: const Duration(hours: 1),
));
await remoteConfig.fetchAndActivate();
But when I try running the test, I'm getting the following error. What could have gone wrong?
══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
The following _TypeError was thrown running a test:
type 'Null' is not a subtype of type 'int'
When the exception was thrown, this was the stack:
#0 MethodChannelFirebaseRemoteConfig.setInitialValues (package:firebase_remote_config_platform_interface/src/method_channel/method_channel_firebase_remote_config.dart:63:62)
#1 new FirebaseRemoteConfigPlatform.instanceFor (package:firebase_remote_config_platform_interface/src/platform_interface/platform_interface_firebase_remote_config.dart:32:10)
#2 RemoteConfig._delegate (package:firebase_remote_config/src/remote_config.dart:24:55)
#3 RemoteConfig._delegate (package:firebase_remote_config/src/remote_config.dart)
#4 RemoteConfig.setConfigSettings (package:firebase_remote_config/src/remote_config.dart:131:12)
Solution 1:[1]
your pluginConstants is not quite right. Try this:
'pluginConstants': {
'plugins.flutter.io/firebase_remote_config': {
'minimumFetchInterval': 0,
'fetchTimeout': 0,
'lastFetchTime': 0,
'lastFetchStatus': 'success',
'parameters': {}
}
},
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | ROBERT DAWKINS |
