getInstanceKey method

String getInstanceKey(
  1. Type type,
  2. String? name
)

Generates the key based on type (and optionally a name) to register an Instance Builder in the hashmap.

A nullable type is normalized to its non-nullable form, so a registration whose generic argument was inferred as nullable (e.g. MyController? c = Get.put(MyController());) shares the same key as Get.put<MyController>(...) and Get.find<MyController>().

Implementation

String getInstanceKey(Type type, String? name) {
  final typeName = type.toString();
  final cleanType = typeName.endsWith('?')
      ? typeName.substring(0, typeName.length - 1)
      : typeName;
  return name == null ? cleanType : '$cleanType$name';
}