configure method
Configures Amplify with the provided configuration string.
This method can only be called once, after all the plugins
have been added and no plugin shall be added after amplify
is configured. Customers are expected to call Amplify.isConfigured
to check if their app is configured before calling this method.
Throws AmplifyAlreadyConfiguredException if this method is called again (e.g. during hot reload).
Implementation
Future<void> configure(String configuration) async {
if (isConfigured) {
throw const AmplifyAlreadyConfiguredException(
'Amplify has already been configured and re-configuration is not supported.',
recoverySuggestion:
'Check if Amplify is already configured using Amplify.isConfigured.',
);
}
final AmplifyConfig amplifyConfig;
try {
final json = jsonDecode(configuration) as Map;
amplifyConfig = AmplifyConfig.fromJson(json.cast());
} on FormatException catch (e) {
throw AmplifyException(
'The provided configuration is not a valid json. Check underlyingException.',
recoverySuggestion:
'Inspect your amplifyconfiguration.dart and ensure that the string is proper json',
underlyingException: e.toString(),
);
}
await configurePlatform(configuration);
_configCompleter.complete(amplifyConfig);
}