From f7aa762b7afc1b47412df4718d0c242f27875af1 Mon Sep 17 00:00:00 2001 From: Drawner Date: Mon, 14 Oct 2024 10:57:21 -0500 Subject: [PATCH] 5.5.0 Took 9 minutes --- CHANGELOG.md | 7 +++++++ lib/part05_futurebuilder_state_mixin.dart | 7 ++++++- lib/part08_app_statex.dart | 11 +++++++++-- pubspec.lock | 10 +++++----- pubspec.yaml | 2 +- 5 files changed, 28 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ed6945b..dd2d0ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/part05_futurebuilder_state_mixin.dart b/lib/part05_futurebuilder_state_mixin.dart index c16f218..1986b4a 100644 --- a/lib/part05_futurebuilder_state_mixin.dart +++ b/lib/part05_futurebuilder_state_mixin.dart @@ -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) { @@ -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 diff --git a/lib/part08_app_statex.dart b/lib/part08_app_statex.dart index f73fd34..9977951 100644 --- a/lib/part08_app_statex.dart +++ b/lib/part08_app_statex.dart @@ -20,9 +20,11 @@ abstract class AppStateX extends StateX super.controller, List? 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; @@ -37,6 +39,9 @@ abstract class AppStateX extends StateX // The 'data object' available to the framework. Object? _dataObj; + // Call the built-in InheritedWidget during rebuilds + final bool _notifyClientsInBuild; + @override @mustCallSuper void initState() { @@ -73,7 +78,9 @@ abstract class AppStateX extends StateX 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(); } diff --git a/pubspec.lock b/pubspec.lock index 7d90750..805c1a5 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -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 @@ -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: @@ -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" diff --git a/pubspec.yaml b/pubspec.yaml index 287ddf8..5756aa5 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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: