watch_it
2.5.0, released 2 months ago by flutter-it.dev
State management powered by get_it to observe changes and rebuild widgets automatically.
What it does
Allows Flutter widgets to observe changes of objects inside the get_it service locator and automatically rebuild when data changes. It eliminates boilerplate builders like ValueListenableBuilder and StreamBuilder.
AI-written summary of version 2.5.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You are already using get_it for dependency injection and want reactive UI updates
- You want to avoid widget tree nesting and boilerplate builders
Skip it when
- You prefer built-in Flutter mechanisms like InheritedWidget or setState
- You cannot follow the strict watch ordering rules
Strengths
- Zero boilerplate with no builders or manual subscriptions
- Automatic disposal of subscriptions when widgets are destroyed
- Type safe with compile-time error checking via generics
Weaknesses
- Requires strict adherence to watch ordering rules (index-based retrieval)
- Tight coupling with get_it service locator
Setup
- Kind
- Flutter widgets
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 2
Requires adding watch_it and get_it to pubspec.yaml.
class CounterWidget extends WatchingWidget {
@override
Widget build(BuildContext context) {
final count = watchValue((CounterModel m) => m.count);
return Text('$count');
}
}Alternatives
Packages that do the same job and could replace watch_it.
- yx_state
A state management library for Dart and Flutter applications.
82Compare - bloc_tools
Command-line tools for generating and linting bloc and cubit components.
88Compare - riverpod
A reactive caching and data-binding framework. Riverpod makes working with asynchronous code a breeze.
99Compare - listen
A package to notify state changes to interested listeners in pure Dart.
88Compare
Works with
Packages commonly used together with watch_it: ones it builds on, ones built on it, and its own family.
- get_itwatch_it depends on itA fast, type-safe service locator for Dart and Flutter without BuildContext or code generation.
- listen_itwatch_it depends on itValueListenable operators and reactive collections for Flutter and Dart
- command_itSame familyWrap sync and async functions as callable Command objects with reactive state.
- flutter_itBuilt on watch_itRe-exports get_it, watch_it, command_it, and listen_it for a single import.