### Getting Type Instances Source: https://github.com/schultek/type_plus/blob/main/README.md Explains two ways to obtain a `Type` instance in Dart: as a generic type argument from a class or function, or as a type variable. ```dart class MyClass { String get name => T.name; } void myFunction() { String name = T.name; } void main() { Type a = int; Type b = List; // for dart < 2.15 instead do typeOf>() String aName = a.name; String bName = b.name; print((MyClass).name); } ``` -------------------------------- ### Type Decomposition Example Source: https://github.com/schultek/type_plus/blob/main/README.md Demonstrates how to decompose a generic type like `Map` into its base type (`Map`) and type arguments (`String`, `int`) using Type Plus. ```dart void main() { var type = Map; String name = type.name; // = "Map" Type base = type.base; // = Map List args = type.args; // = [String, int] } ``` -------------------------------- ### Type Inheritance Check Example Source: https://github.com/schultek/type_plus/blob/main/README.md Demonstrates how to use `typeA.implements(typeB)` and `typeB.implementedBy(typeA)` to check type inheritance in Dart. It shows the registration of supertypes using `TypePlus.add` and asserts the inheritance relationships. ```dart class MyClass extends List {} void main() { var listType = List; TypePlus.add(superTypes: [listType]); var myType = MyClass; assert(myType.implements(listType)); assert(listType.implementedBy(myType)); assert(!myType.implements(List)); // needs to be the full specified type } ``` -------------------------------- ### Registering Generic Types with Factories Source: https://github.com/schultek/type_plus/blob/main/README.md Shows how to register a generic type by providing a type factory function. The factory function must match the generic arity of the type being registered. ```dart class MyClass {} void main() { TypePlus.addFactory((f) => f>()); } ``` -------------------------------- ### Type ID Usage for Type Construction Source: https://github.com/schultek/type_plus/blob/main/README.md Illustrates how to use unique type IDs generated by Type Plus to construct generic types from strings, and how to register custom IDs. ```dart void main() { Type a = List; Type b = int; Type newType = TypePlus.fromId('${a.id}<${b.id}>'); assert(newType.base == a); assert(newType.args.first == b); TypePlus.add(id: 'CoolId'); Type myType = TypePlus.fromId('CoolId'); assert(myType == MyClass); } ``` -------------------------------- ### Accessing Type Properties Source: https://github.com/schultek/type_plus/blob/main/README.md Illustrates how to access properties like name, id, base type, and type arguments from a generic type variable `T` using Type Plus. ```dart void myGenericFunction() { String name = T.name; // the full name of the type String id = T.id; // a unique id of the type Type base = T.base; // the base type of a generic type List args = T.args; // the type arguments of a generic type } ``` -------------------------------- ### Registering Non-Generic Types Source: https://github.com/schultek/type_plus/blob/main/README.md Demonstrates how to register a custom non-generic type with the TypePlus utility. This is typically done early in the Dart program's main function. ```dart TypePlus.add(); ``` -------------------------------- ### Generic Method Invocation with Type Variables Source: https://github.com/schultek/type_plus/blob/main/README.md Shows how to invoke a generic method using a type variable provided by Type Plus, overcoming the static limitation of generic type arguments in Dart. ```dart void printType() { print(T.name); } void main() { var type = typeOf>(); // prints: "Map" printType.callWith(typeArguments: [type]); // prints: "String" printType.callWith(typeArguments: [type.args.first]); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.