data_notifier 0.2.0
data_notifier: ^0.2.0 copied to clipboard
Manage and observe data states with ValueNotifier/ValueListenable. Handle loading, loaded, and error states with enhanced debugging.
0.1.0 #
- Initial release.
0.1.3 #
- Readme and pubspec updates.
0.1.4 #
- Refactor notifier state management: rename NotifierState to NotifierState and update related classes and imports
0.1.5 #
- PrintColor enum added and cmd_color.dart removed; updated imports in data_notifier.dart and utils.dart
- Updated NotifierBuilder to be usable without a builder, allowing it to be used as just a listener.
0.1.6 #
- Refactor state management: rename DataState to NotifierState, update related classes and imports; remove unused DataState and DataNotifierBuilder files; enhance NotifierBuilder functionality.
0.2.0 #
Breaking changes:
NotifierStateis now asealedclass and its notifier type parameterThas been removed:NotifierState<T, D>is nowNotifierState<D>. You can now use Dart's native exhaustiveswitchpattern matching on states.DataNotifieris now generic over the data type instead of the state type:DataNotifier<NotifierState<T, D>>is nowDataNotifier<D>(always holding aNotifierState<D>).- The
errorcallback ofwhennow receives(Object? error, String message)instead of(String message), consistent withmaybeWhen/whenOrElse. maybeWhennow callsorElsewhen the callback for the current state is not provided (previouslyorElsewas unreachable andnullwas returned instead).- The
ListenerandValueWidgetBuildertypedefs no longer conflict with Flutter's own declarations:Listenerwas renamed toNotifierListener,ListenWhentoNotifierListenWhen, andNotifierBuilder.buildernow uses Flutter'sValueWidgetBuilder. - Removed the no-op
DataNotifier.cancel()method. NotifierStateError.erroris now typed asObject?instead ofdynamic.
New features:
NotifierStategainedisLoading,isLoaded,isError, anddataOrNullconvenience getters.NotifierStateErrorgained an optionalstackTracefield.- All states now implement
==andhashCode, so setting an equal state no longer triggers unnecessary notifications/rebuilds. DataNotifiergainedsetLoading(),setLoaded(data), andsetError(error, message, {stackTrace})convenience setters, aDataNotifier.loading()constructor, and an optionaldebugLabelfor console logs.NotifierBuildernow validatesbuilder/childwith a constructor assert (instead of throwing at build time) and skips rebuilds entirely when used as a pure listener without abuilder.DataNotifiergained an asyncload(fetch)helper that emits loading and then loaded/error automatically. It is race-safe (when calls overlap, the latest call wins) and dispose-safe (results arriving afterdispose()are discarded). AnisDisposedgetter was also added.- Stale data is now preserved during reloads:
setLoading(),setError(...), andload(...)carry the current data into the new state aspreviousData(opt out withpreserveData: false), andNotifierState.dataOrPreviousexposes it alongsidedataOrNull. NotifierBuildergained abuildWhencallback to filter rebuilds, symmetric tolistenWhen(which only filters thelistener).- Added a comprehensive test suite.