Solid provides fine-grained reactivity inspired by SolidJS. Instead of rebuilding entire widget trees, Solid tracks which specific parts of the UI depend on which state variables. When a state variable changes, only the specific UI elements that depend on that state are updated.
For example, if you have a Text widget displaying a counter and another Text widget displaying the current time, updating the counter will not trigger a rebuild of the time widget. This happens automatically without manual state management or dependency injection work.
import 'package:flutter/material.dart';
import 'package:solid_annotations/solid_annotations.dart';
class Counter extends StatelessWidget {
Counter({super.key});
@SolidState()
int counter = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text('Date: ${DateTime.now()}'),
Text('Counter is $counter'),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: () => counter++,
child: const Icon(Icons.add),
),
);
}
}