Live Cells
A simple yet powerful reactive programming library
Reactive Programming
- A reactive programming library for Dart and Flutter
- Define
cells
for your data - Declare
observers
on cells - Observers are called automatically when cell values change
// Define a cell
final count = MutableCell(0);
// Define an observer
ValueCell.watch(() {
print('${count()}');
});
// Increment cell value
// Automatically calls observer
count.value++;
Benefits over ValueNotifier
final a = MutableCell(0);
final b = MutableCell(1);
final sum = a + b;
- Cells can be defined as an expression of other cells
- No need to add and remove listeners
- Simpler resource management
- Disposed automatically
Two-way data flow
final n = MutableCell(0);
final strN = n.mutableString();
n.value = 5;
print(strN.value); // '5'
strN.value = '10';
print(n.value); // 10
- Data can flow in both directions
- Most other libraries (if not all) are limited to unidirectional data flow
Simple and Unobtrusive
- You only need to learn one basic building block — the cell
- Cells are designed to be indistinguishable from the values they hold
// A list cell
ValueCell<List> list;
// A cell for the index
ValueCell<int> index
// A cell which access a list item
final e = list[index]; - No need to implement complicated notifier or state classes.
Bind Data to Widgets
- Integrated with a widget library
- Allows widget properties to be bound directly to cells
- Reduces the need for controller objects and event handlers
- Only rebuild the widgets that have actually changed
final content = MutableCell('');
...
Column(
children: [
// Cell content bound to TextField content
LiveTextField(
content: content
),
CellWidget.builder((_) =>
Text('You wrote: ${content()}')
)
]
)