createVariable<U> method
Create a ProviderModelVariable belonging to this ProviderModel that can be used in batches and automatically detect changes to notify listeners when it's value changes.
initial is the initial value that this variable will be set to.
Use this function as the value of a late final variable in your class.
class MyClass extends ProviderModel<MyClass> {
late final myVariable = createVariable<int>(0);
}
Implementation
@nonVirtual
@protected
ProviderModelVariable<U> createVariable<U>(U initial) {
assert(
_debugValidType ??= T != const _DebugDynamicType<dynamic>().type,
'ProviderModel\'s T type parameter must be the same as the class that extends it. Currrently it is dynamic or unset.',
);
final tContainer = ProviderModelVariable<U>._internalCreate(
this,
initial,
true,
);
_variables.add(tContainer);
return tContainer;
}