A widget that allows you to conditionally wrap a child subtree with a parent widget
ConditionalWrap
widget takes a boolean condition
parameter and wraps the child subtree with wrapper
if the condition is true.
ConditionalWrap(
condition: _shouldIncludeParent,
wrapper: (child) => ParentWidget(child: child),
child: ChildSubtree(),
),
You can also provide a fallback
wrapper to use when the condition
is false.
ConditionalWrap(
condition: _shouldUseWrapper,
wrapper: (child) => ParentWidget(child: child),
fallback: (child) => FallbackParent(child: child),
child: ChildSubtree(),
),
NullSafeWrap<T>
widget takes a generic T? value
parameter and wraps the child subtree with wrapper
if the value is not null. This null-safe wrapper provides T value
argument that can be used safely.
Similarly to conditional wrap, you can provide a fallback
to use when the value is null.
NullSafeWrap<Color>(
value: _color,
wrapper: (color, child) => ColoredBox(
color: color,
child: child,
),
child: Text('hello, friend.'),
),