Skip to content

Simplify App Level State Change Notifications / Reduce App Level State Setup Burden - #25

Merged
jshep23 merged 15 commits into
mainfrom
SimplifyCurrentAppNotifications
Apr 30, 2026
Merged

jshep23 merged 15 commits into
mainfrom
SimplifyCurrentAppNotifications

Conversation

@jshep23

@jshep23 jshep23 commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

This pull request simplifies and modernizes the state management mechanism in the current package by removing the need for the onAppStateChanged callback and leveraging Flutter's built-in ChangeNotifier for 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 onAppStateChanged requirement: The Current widget no longer requires an onAppStateChanged callback or a unique string to trigger updates. Instead, it now extends StatelessWidget and uses a ListenableBuilder to automatically rebuild when the CurrentViewModel notifies 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]

  • CurrentViewModel now uses ChangeNotifier: The base view model class mixes in ChangeNotifier and calls notifyListeners() on state changes, enabling the new reactive update mechanism. (lib/src/current_view_model.dart) [1] [2] [3] [4]

Example and Test Code Updates

  • Removed UUID and random state update logic: All references to UUID generation and random state IDs for triggering updates have been removed from the example app and tests, reflecting the new, simpler update mechanism. (example/lib/main.dart, example/pubspec.yaml, test/current_widget_test.dart) [1] [2] [3] [4] [5]

Documentation and API Usability

  • Updated documentation and README: The README and API docs have been revised to remove references to onAppStateChanged, clarify usage, and improve formatting and branding. Also, new topics were added to pubspec.yaml for 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 initialValue or propertyName unless 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]

@jshep23
jshep23 merged commit 6f33e49 into main Apr 30, 2026
5 checks passed
@jshep23
jshep23 deleted the SimplifyCurrentAppNotifications branch April 30, 2026 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant