configureDataStore method

  1. @override
Future<void> configureDataStore({
  1. ModelProviderInterface? modelProvider,
  2. dynamic errorHandler(
    1. AmplifyException
    )?,
  3. DataStoreConflictHandler? conflictHandler,
  4. List<DataStoreSyncExpression>? syncExpressions,
  5. int? syncInterval,
  6. int? syncMaxRecords,
  7. int? syncPageSize,
  8. AuthModeStrategy authModeStrategy = AuthModeStrategy.defaultStrategy,
})
override

This method instantiates the native DataStore plugins with plugin configurations. This needs to happen before Amplify.configure() can be called.

Implementation

@override
Future<void> configureDataStore({
  ModelProviderInterface? modelProvider,
  Function(AmplifyException)? errorHandler,
  DataStoreConflictHandler? conflictHandler,
  List<DataStoreSyncExpression>? syncExpressions,
  int? syncInterval,
  int? syncMaxRecords,
  int? syncPageSize,
  AuthModeStrategy authModeStrategy = AuthModeStrategy.defaultStrategy,
}) async {
  _channel.setMethodCallHandler(_methodCallHandler);
  try {
    this.modelProvider = modelProvider;
    this.errorHandler = errorHandler;
    this.conflictHandler = conflictHandler;
    _syncExpressions = syncExpressions;

    return await _channel
        .invokeMethod('configureDataStore', <String, dynamic>{
      'modelSchemas': modelProvider?.modelSchemas
          .map((schema) => schema.toMap())
          .toList(),
      'customTypeSchemas': modelProvider?.customTypeSchemas
          .map((schema) => schema.toMap())
          .toList(),
      'hasErrorHandler': errorHandler != null,
      'hasConflictHandler': conflictHandler != null,
      'modelProviderVersion': modelProvider?.version,
      'syncExpressions': syncExpressions!
          .map((syncExpression) => syncExpression.toMap())
          .toList(),
      'syncInterval': syncInterval,
      'syncMaxRecords': syncMaxRecords,
      'syncPageSize': syncPageSize,
      'authModeStrategy': authModeStrategy.rawValue,
    });
  } on PlatformException catch (e) {
    if (e.code == "AmplifyAlreadyConfiguredException") {
      throw AmplifyAlreadyConfiguredException(
          AmplifyExceptionMessages.alreadyConfiguredDefaultMessage,
          recoverySuggestion:
              AmplifyExceptionMessages.alreadyConfiguredDefaultSuggestion);
    } else {
      throw _deserializeException(e);
    }
  }
}