listenable 0.1.0 listenable: ^0.1.0 copied to clipboard
Make you models changes listenable by flutter widgets using ValueListenableBuilder.
#Listenable
Listenable help you to manage Flutter widgets and state synchronization by leveraging the [ValueListenable] class. You will annotate you models and it will generate the required code for your models to be listenable by a ListenableBuilder widget.
Usage #
A simple usage example:
import 'package:listenable/listenable.dart';
part 'counters.g.dart';
class Counter = _Counter with _Counter$Listenable;
@ListenableModel()
abstract class _Counter {
@ListenableProperty()
final String name;
@ListenableProperty(updatesModel: false)
int _count = 0;
_Counter(this.name);
void increment() {
_count++;
}
void decrement() {
_count--;
}
}
Listen changes in your widgets #
Rebuild you widgets using the flutter existing widgets, you don't need any additional library
import 'package:flutter/widgets.dart';
class CounterWidget extends StatelessWidget {
final Counter _counter = Counter('MyCounter');
@override
Widget build(BuildContext context) {
return ValueListenableBuilder<int>(
valueListenable: _counter.countListenable,
builder: (context, count, _) => Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'[$count]',
style: TextStyle(
fontSize: 35, fontWeight: FontWeight.bold),
),
Text('${_counter.name}'),
],
),
);
}
}
Features and bugs #
Please file feature requests and bugs at the issue tracker.