Skip to content
pubscout

conditional_parent_widget

0.0.2, released 4 years ago by an unverified publisher

Conditionally wrap a widget with a parent widget.

WASM-ready
$ flutter pub add conditional_parent_widget
Source repository

What it does

Conditionally wraps a child widget with a parent widget based on a boolean condition. It provides a parentBuilder and an optional parentBuilderElse to avoid repetitive ternary statements in the widget tree.

AI-written summary of version 0.0.2, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You need to conditionally wrap a subtree with a parent widget inside a build method.
  • You want to avoid verbose ternary operators or if-else statements when returning widgets.

Skip it when

  • You require a package that is actively maintained.
  • Complex state management is needed instead of simple conditional tree wrapping.

Strengths

  • Keeps widget tree code clean and readable.
  • Supports an optional parentBuilderElse for handling the false condition.

Weaknesses

  • The package is stable but not actively maintained.

Setup

Kind
Flutter widgets
Effort
Low
Code generation
No
Direct dependencies
0
return ConditionalParentWidget(
  condition: shouldIncludeParent,
  parentBuilder: (Widget child) => SomeParentWidget(child: child),
  child: Widget1(
    child: Widget2(
      child: Widget3(),
    ),
  ),
);

Alternatives

Packages that do the same job and could replace conditional_parent_widget.