proviso 1.0.5 copy "proviso: ^1.0.5" to clipboard
proviso: ^1.0.5 copied to clipboard

Complete set of tools for widgets conditional rendering and wrapping. Conditional widgets and builders.

proviso #

stability-stable License

A complete set of tools for conditional rendering (if-else and switch conditions), subtree wrapping with a parent widget, and some handy shortcuts (like DebugWidget, WebOnlyWidget, SafeBuilder, and many more). 👍

Install #

In flutter project add the dependency:

dependencies:
  ...
  proviso: ^1.0.5

Why #

To make a more readable and simpler conditional statement code.

All variants of conditional rendering you will ever need in a single package #

in the form of widgets:

Row(
  children: [
    ConditionWidget(
      condition: starred,
      widget: Icon(
        Icons.favorite
      ),
      fallback: fallbackWidget
    ),
    ConditionWidget(
      condition: archived,
      widget: Icon(
        Icons.archive
      )
    )  
  ]
)
ConditionBuilder(
  condition: (_) => someCondition,
  trueBuilder: (_) => trueWidget,
  fallbackBuilder: (_) => fallbackWidget
);

builders:

ConditionalBuilder.widget(
  context: context,
  condition: (_) => _evaluateSomething(),
  trueBuilder: (_) => trueWidget,
  fallbackBuilder: (_) => fallbackWidget,
);

Switch case widgets and builders:

final Widget targetConditionWidget = Container();
final Widget fallbackWidget = Container();

SwitchCaseBuilder.widget<String>(
  context: context,
  condition: (_) => '1',
  caseBuilders: {'1': (_) => targetConditionWidget, '2': (_) => Container()},
  fallbackBuilder: (_) => fallbackWidget,
);  

Conditional parent widget

ConditionalWrap(
  shouldWrap: shouldWrapChildInParent,
  child: Container(),
  parentBuilder: (child) => Container(
    child: child,
  ),
)

try/catch builders

SafeBuilder(
  widgetBuilder: (_) => validWidget,
  fallbackBuilder: (e, _) => fallbackWidget, // called if widgetBuilder fails with error
)

Conditionally render a single widget or a list of widgets

ConditionalBuilder.widgets(
  context: context,
  condition: (_) => true,
  trueBuilder: (_) => [Container(), Container()],
  fallbackBuilder: (_) => [],
)

Some more helpers like:

DebugOnlyWidget, WebOnlyWidget etc

Contributions #

Feel free to report bugs, request new features or to contribute to this project!

5
likes
160
pub points
54%
popularity

Publisher

verified publishermos-dev.com

Complete set of tools for widgets conditional rendering and wrapping. Conditional widgets and builders.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter

More

Packages that depend on proviso