value_layout_builder
0.5.0, released 2 years ago by romainrastel.com
A LayoutBuilder that passes a custom value to its builder during layout.
What it does
It extends LayoutBuilder to expose an arbitrary value to the builder via custom constraints. The value is set by a custom RenderObject and can be used to build widgets that depend on layout information.
AI-written summary of version 0.5.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need to access a value computed during layout in a child widget
- You are creating a custom RenderObject that must communicate data to a builder
- You want a lightweight way to pass data from a parent RenderObject to its child widget
Skip it when
- You only need the standard constraints from LayoutBuilder
- You are not using a custom RenderObject to supply the value
Strengths
- Simple API, no code generation
- Null-safety compliant
- Works with both RenderBox and RenderSliver
Weaknesses
- Requires a custom RenderObject to supply the value
- Not a general-purpose state management tool
- Limited to layout-time data
Setup
- Kind
- Flutter widgets
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 0
Add dependency in pubspec, import package:value_layout_builder/value_layout_builder.dart
class _Tester<T> extends SingleChildRenderObjectWidget {
const _Tester({Key? key, required this.value, required Widget child})
: super(key: key, child: child);
final T value;
@override
_RenderTester<T> createRenderObject(BuildContext context) => _RenderTester<T>(value: value);
@override
void updateRenderObject(BuildContext context, _RenderTester<T> renderObject) {
renderObject.value = value;
}
}
_Tester<String>(
value: 'test',
child: ValueLayoutBuilder<String>(
builder: (context, constraints) {
final String value = constraints.value;
return Text(value);
},
),
)Alternatives
Packages that do the same job and could replace value_layout_builder.
- scaled_app
Scale the entire UI design proportionally based on device size.
79Compare - custom_adaptive_scaffold
Drop-in adaptive Material 3 scaffolding and responsive layout widgets for Flutter apps.
76Compare
Works with
Packages commonly used together with value_layout_builder: ones it builds on, ones built on it, and its own family.