TypeInfo<T>.fromType constructor

TypeInfo<T>.fromType(
  1. Type type, [
  2. Iterable<Object>? arguments,
  3. Object? object
])

Implementation

factory TypeInfo.fromType(Type type,
    [Iterable<Object>? arguments, Object? object]) {
  if (type == _TypeWrapper.tString || object is String) {
    return tString as TypeInfo<T>;
  }
  if (type == _TypeWrapper.tInt || object is int) return tInt as TypeInfo<T>;
  if (type == _TypeWrapper.tDouble || object is double) {
    return tDouble as TypeInfo<T>;
  }
  if (type == _TypeWrapper.tNum || object is num) return tNum as TypeInfo<T>;
  if (type == _TypeWrapper.tBool || object is bool) {
    return tBool as TypeInfo<T>;
  }
  if (type == _TypeWrapper.tBigInt || object is BigInt) {
    return tBigInt as TypeInfo<T>;
  }
  if (type == _TypeWrapper.tDateTime || object is DateTime) {
    return tDateTime as TypeInfo<T>;
  }
  if (type == _TypeWrapper.tDuration || object is Duration) {
    return tDuration as TypeInfo<T>;
  }
  if (type == _TypeWrapper.tUint8List || object is Uint8List) {
    return tUint8List as TypeInfo<T>;
  }

  if (type == _TypeWrapper.tObject) return tObject as TypeInfo<T>;

  var hasArguments = arguments != null && arguments.isNotEmpty;

  if (type == _TypeWrapper.tDynamic) {
    // A FutureOr is a `dynamic` with arguments:
    if (hasArguments) {
      return TypeInfo._(_TypeWrapper.tFutureOr, arguments, object,
          TypeInfo.tFutureOr._typeWrapper);
    } else {
      return tDynamic as TypeInfo<T>;
    }
  }

  if (type == _TypeWrapper.tFuture) {
    if (hasArguments) {
      return TypeInfo._(_TypeWrapper.tFuture, arguments, object,
          TypeInfo.tFuture._typeWrapper);
    } else {
      return TypeInfo.tFuture as TypeInfo<T>;
    }
  }

  if (type == _TypeWrapper.tVoid) return tVoid as TypeInfo<T>;

  if (arguments == null || arguments.isEmpty) {
    if (type == _TypeWrapper.tList || object is List) {
      return tList as TypeInfo<T>;
    }
    if (type == _TypeWrapper.tSet || object is Set) {
      return tSet as TypeInfo<T>;
    }
    if (type == _TypeWrapper.tMap || object is Map) {
      return tMap as TypeInfo<T>;
    }
    if (type == _TypeWrapper.tIterable || object is Iterable) {
      return tIterable as TypeInfo<T>;
    }

    if (type == _TypeWrapper.tFuture || object is Future) {
      return tFuture as TypeInfo<T>;
    }
  }

  return TypeInfo<T>._(type, arguments, object);
}