Skip to content

Commit

Permalink
5.5.0
Browse files Browse the repository at this point in the history
Took 9 minutes
  • Loading branch information
Drawner committed Oct 14, 2024
1 parent 655ddbb commit f7aa762
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 9 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@

## 5.5.0
Octobter 14, 2024
- AppStateX class now has the notifyClientsInBuild parameter. Defaults to true.
Notify any dependencies when calling for a rebuild
- The runInitAsync() function in every StateX object
now allows their initAsync() functions to be conditionally called wit every rebuild.

## 5.4.0
October 07, 2024
- Built-in InheritedWidget is now called with AppState's setState() function
Expand Down
7 changes: 6 additions & 1 deletion lib/part05_futurebuilder_state_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ mixin FutureBuilderStateMixin on State {
// A little trick to determine if the user has overridden this function.
_buildOverridden = false;
// Generate the Future evey time or just once
if (_runAsync || _future == null) {
if ((_runAsync && runInitAsync()) || _future == null) {
_future = initAsync();
_future?.catchError(
(Object e) {
Expand Down Expand Up @@ -66,6 +66,11 @@ mixin FutureBuilderStateMixin on State {
// Call initAsync() all the time if set true.
bool _runAsync = false;

/// Call initAsync() all the time if return true.
/// Conditional calls initAsync() creating a Future with every rebuild
@protected
bool runInitAsync() => true;

/// IMPORTANT
/// The _future must be created first. If the _future is created at the same
/// time as the FutureBuilder, then every time the FutureBuilder's parent is
Expand Down
11 changes: 9 additions & 2 deletions lib/part08_app_statex.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ abstract class AppStateX<T extends StatefulWidget> extends StateX<T>
super.controller,
List<StateXController>? controllers,
Object? object,
bool? notifyClientsInBuild,
super.printEvents,
// Save the current error handler
}) : _prevErrorFunc = FlutterError.onError {
}) : _prevErrorFunc = FlutterError.onError,
_notifyClientsInBuild = notifyClientsInBuild ?? true {
// Introduce its own error handler
FlutterError.onError = _errorHandler;

Expand All @@ -37,6 +39,9 @@ abstract class AppStateX<T extends StatefulWidget> extends StateX<T>
// The 'data object' available to the framework.
Object? _dataObj;

// Call the built-in InheritedWidget during rebuilds
final bool _notifyClientsInBuild;

@override
@mustCallSuper
void initState() {
Expand Down Expand Up @@ -73,7 +78,9 @@ abstract class AppStateX<T extends StatefulWidget> extends StateX<T>
Widget buildF(BuildContext context) {
_buildFOverridden = false;
_builderState?.setState(() {}); // calls builder()
_inheritedState?.setState(() {}); // calls the InheritedWidget
if (_notifyClientsInBuild) {
_inheritedState?.setState(() {}); // calls the InheritedWidget
}
return const _InheritedWidgetStatefulWidget();
}

Expand Down
10 changes: 5 additions & 5 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ packages:
dependency: "direct dev"
description:
name: flutter_lints
sha256: "3f41d009ba7172d5ff9be5f6e6e6abb4300e263aab8866d2a0842ed2a70f8f0c"
sha256: "5398f14efa795ffb7a33e9b6a08798b26a180edac4ad7db3f231e40f82ce11e1"
url: "https://pub.dev"
source: hosted
version: "4.0.0"
version: "5.0.0"
flutter_localizations:
dependency: "direct main"
description: flutter
Expand Down Expand Up @@ -162,10 +162,10 @@ packages:
dependency: transitive
description:
name: lints
sha256: "976c774dd944a42e83e2467f4cc670daef7eed6295b10b36ae8c85bcbf828235"
sha256: "3315600f3fb3b135be672bf4a178c55f274bebe368325ae18462c89ac1e3b413"
url: "https://pub.dev"
source: hosted
version: "4.0.0"
version: "5.0.0"
matcher:
dependency: transitive
description:
Expand Down Expand Up @@ -316,5 +316,5 @@ packages:
source: hosted
version: "3.0.3"
sdks:
dart: ">=3.3.0 <4.0.0"
dart: ">=3.5.0 <4.0.0"
flutter: ">=3.18.0-18.0.pre.54"
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ dev_dependencies:
# activated in the `analysis_options.yaml` file located at the root of your
# package. See that file for information about deactivating specific lint
# rules and activating additional ones.
flutter_lints: ^4.0.0
flutter_lints: ^5.0.0

# Needed here as well for testing
flutter_test:
Expand Down

0 comments on commit f7aa762

Please sign in to comment.