trex 1.0.1 trex: ^1.0.1 copied to clipboard
Hooks, Statable Widgets, Trackable Variables, Extensions - The most efficient State Management solution...
T-Rex #
Hooks, Statable Widgets, and Datatype extensions to make development easier and efficient. T-Rex is a compact, simple State Management solution for your Flutter Applications, implemented without using Streams or any complicated abstractions.
Most State Management solutions use Streams to notify changes to data. This becomes highly unintuitive and inefficient when you have a lot of state variables and data changes to watch out for. T-Rex doesn't use Streams, and use basic features of Dart to provide a wide-variety of State Management solutions.
Hook
The code below demonstrates the usage of hooks using a Hookable widget. Your widget will automatically update UI when the value stored in the Hook changes.
class MyCounter extends Hookable {
late final Hook<int> count;
void hooks() {
count = Hook(0, this);
}
Widget build(_) {
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: crossAxisAlignment.center,
children: [
Text(count.value.toString()),
IconButton(
onPressed: () {
/// The widget automatically rebuilds when value of the Hook changes.
count.value++;
}
icon: Icon(Icons.add),
),
]
),
),
);
}
}
Tx<T>
Trackable Variables #
Tx<int> count = Tx(
0,
afterChange: (_) {
this.setState(() {});
}
);
The simplest way to manage state, for very simple widgets and screens.