rasitayaz / flutter-conditional-wrap

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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 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(),
),

Null Safe Wrap

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.'),
),

About

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

License:MIT License


Languages

Language:Dart 100.0%