Repository navigation
Simplify App Level State Change Notifications / Reduce App Level State Setup Burden - #25
Merged
Merged
Conversation
Co-authored-by: Copilot <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request simplifies and modernizes the state management mechanism in the
currentpackage by removing the need for theonAppStateChangedcallback and leveraging Flutter's built-inChangeNotifierfor efficient widget updates. It also improves documentation and cleans up the example and test code to reflect these changes. The most important updates are outlined below.Core State Management Refactor
Removed
onAppStateChangedrequirement: TheCurrentwidget no longer requires anonAppStateChangedcallback or a unique string to trigger updates. Instead, it now extendsStatelessWidgetand uses aListenableBuilderto automatically rebuild when theCurrentViewModelnotifies listeners. This greatly simplifies usage and reduces boilerplate. (lib/src/current.dart,lib/src/current_view_model.dart,example/lib/main.dart,test/current_widget_test.dart) [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14]CurrentViewModelnow usesChangeNotifier: The base view model class mixes inChangeNotifierand callsnotifyListeners()on state changes, enabling the new reactive update mechanism. (lib/src/current_view_model.dart) [1] [2] [3] [4]Example and Test Code Updates
example/lib/main.dart,example/pubspec.yaml,test/current_widget_test.dart) [1] [2] [3] [4] [5]Documentation and API Usability
onAppStateChanged, clarify usage, and improve formatting and branding. Also, new topics were added topubspec.yamlfor better discoverability. (README.md,lib/src/current.dart,pubspec.yaml) [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13]API and Usability Improvements
Simplified property initialization: Examples now use streamlined property initialization without explicit
initialValueorpropertyNameunless necessary, making code cleaner and easier to follow. (README.md) [1] [2] [3]Improved validation example patterns: Validation logic in the README is now encapsulated in dedicated methods for clarity and testability, showing best practices for structuring validation in view models. (
README.md) [1] [2]