override<T, SubType extends T> static method
Inheritable<T>
override<T, SubType extends T>({
- required SubType value,
- Key? key,
- Set<
AspectOverride< ? overrides,Object?, T> > - ValueChanged<
T> ? onMutate, - Widget? child,
- bool strict = true,
Create an Inheritable that overrides T
with given value
for the widget sub-tree.
Providing onChange
will create Inheritable.mutable instead.
Specify strict
to catch unnecessary uses of this method.
When specified, an assertion error is thrown if the overriding value type and the base type are same.
However strict
is only used in debug mode, it has no effect in release mode.
Example:
Inheritable.override<T, SubType>(
value: SubType(),
chid: MyWidget(),
)
This is just a convenience method, there is nothing special about subtyping. The same effect can be achieved by
Inheritable<T>( // Specify base type explicitly
value: SubType(), // Provide a subtype instance
child: MyWidget(),
)
Implementation
/// ```
static Inheritable<T> override<T, SubType extends T>({
required SubType value,
Key? key,
Set<AspectOverride<Object?, T>>? overrides,
ValueChanged<T>? onMutate,
Widget? child,
bool strict = true,
}) {
assert(
T != Object && T != dynamic,
'Underspecified types are most likely a mistake. This can happen when forgetting to pass type arguments to Inheritable constructors. '
'Try being more specific using Inheritable<T>() or Inheritable<T>.mutable or Inheritable.override<T, TT>.',
);
assert(
!strict ||
T != SubType ||
onMutate != null ||
overrides != null && overrides.isNotEmpty,
'Provided value is not allowed in strict mode',
);
if (onMutate != null) {
return _MutableInheritable<T>._(
onMutate: onMutate,
value: value,
key: key,
overrides: newOverridesSet(overrides),
child: child,
);
}
return Inheritable<T>._(
value: value,
key: key,
overrides: newOverridesSet(overrides),
child: child,
);
}