conditional_wrap 1.0.0
conditional_wrap: ^1.0.0 copied to clipboard
A Flutter widget that allows you to conditionally wrap a child subtree with a parent widget
Flutter Conditional Wrap 🌯 #
A widget that allows you to conditionally wrap a child subtree with a parent widget

Usage #
Conditional Wrap #
ConditionalWrap widget takes a boolean condition parameter and wraps the child subtree with builder if the condition is true.
ConditionalWrap(
condition: shouldIncludeParent,
builder: (child) => ParentWidget(child: child),
child: ChildSubtree(),
),
You can also provide a fallback builder to use when the condition is false.
ConditionalWrap(
condition: _shouldUseBuilder,
builder: (child) => ParentWidget(child: child),
fallback: (child) => FallbackParent(child: child),
child: ChildSubtree(),
),
Null Safe Wrap #
NullSafeWrap<T> widget takes a generic T? value parameter and wraps the child subtree with builder if the value is not null. This builder 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,
builder: (color, child) => ColoredBox(
color: color,
child: child,
),
child: Text('hello, friend.'),
),