decode method Null safety

  1. @override
void decode(
  1. dynamic value
)
override

Ingests value into the properties of this type.

Override this method to provide decoding behavior other than the default behavior.

Implementation

@override
void decode(dynamic value) {
  if (value is Map) {
    super.decode(value);
    return;
  }

  if (value is! String) {
    throw ConfigurationException(
      this,
      "'${value.runtimeType}' is not assignable; must be a object or string",
    );
  }

  final uri = Uri.parse(value);
  host = uri.host;
  port = uri.port;
  if (uri.pathSegments.length == 1) {
    databaseName = uri.pathSegments.first;
  }

  if (uri.userInfo == '') {
    validate();
    return;
  }

  final authority = uri.userInfo.split(":");
  if (authority.isNotEmpty) {
    username = Uri.decodeComponent(authority.first);
  }
  if (authority.length > 1) {
    password = Uri.decodeComponent(authority.last);
  }

  validate();
}