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). 👍
In flutter project add the dependency:
dependencies:
...
proviso: ^1.0.5
To make a more readable and simpler conditional statement code.
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,
);
final Widget targetConditionWidget = Container();
final Widget fallbackWidget = Container();
SwitchCaseBuilder.widget<String>(
context: context,
condition: (_) => '1',
caseBuilders: {'1': (_) => targetConditionWidget, '2': (_) => Container()},
fallbackBuilder: (_) => fallbackWidget,
);
ConditionalWrap(
shouldWrap: shouldWrapChildInParent,
child: Container(),
parentBuilder: (child) => Container(
child: child,
),
)
SafeBuilder(
widgetBuilder: (_) => validWidget,
fallbackBuilder: (e, _) => fallbackWidget, // called if widgetBuilder fails with error
)
ConditionalBuilder.widgets(
context: context,
condition: (_) => true,
trueBuilder: (_) => [Container(), Container()],
fallbackBuilder: (_) => [],
)
DebugOnlyWidget, WebOnlyWidget etc
Feel free to report bugs, request new features or to contribute to this project!