$ifFor<TValue> method
Widget
$ifFor<TValue>(
- Object propertyKey, {
- required ValueWidgetBuilder<
TValue> builder, - Widget? child,
- bool valueHandle(
- TValue
- TValue? initialValue,
绑定到指定属性, 当 propertyKey
对应属性值发生变化时,
若值判定结果为 true
则使用 builder
构建 Widget, 否则不构建 Widget
当值类型不为 bool 时, 非 null
即被判定为 true
, 否则为 false
可通过指定 valueHandle
对值进行处理
child
用于向构建方法中传入 Widget
// example
@override
Widget build(BuildContext context) {
return $ifFor<String>(#account,
builder: (context, value, child) => Text("tom!"),
valueHandle: (value) => value == "tom");
}
Implementation
Widget $ifFor<TValue>(Object propertyKey,
{required ValueWidgetBuilder<TValue> builder,
Widget? child,
bool Function(TValue)? valueHandle,
TValue? initialValue}) =>
$if(ensureProperty<TValue>(propertyKey, initialValue: initialValue),
builder: builder, child: child, valueHandle: valueHandle);