conditional_wrap 1.0.0 copy "conditional_wrap: ^1.0.0" to clipboard
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 🌯 #

Pub

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.'),
),
8
likes
160
points
957
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter widget that allows you to conditionally wrap a child subtree with a parent widget

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on conditional_wrap