From d2e27d732c6e2359a85901196c45eab6d7345d42 Mon Sep 17 00:00:00 2001 From: Drawner Date: Wed, 24 Jan 2024 16:23:48 -0600 Subject: [PATCH] 4.10.0 --- CHANGELOG.md | 7 +++++++ lib/state_extended.dart | 24 ++++++++++++++++++++++-- pubspec.yaml | 2 +- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d84911..5fdcbd7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,11 @@ +## 4.10.0 +January 24, 2023 +- StateX({StateXController? controller, bool? runAsync, bool? useInherited}) { + A new optional parameter, runAsync, to run built-in FutureBuilder with every build +- abstract class StateF extends StateX + A State class to run built-in FutureBuilder with every build + ## 4.9.0 December 14, 2023 - getter buildOverridden & buildFOverridden set when 'build' functions are overwritten diff --git a/lib/state_extended.dart b/lib/state_extended.dart index 7be7bb3..4583eca 100644 --- a/lib/state_extended.dart +++ b/lib/state_extended.dart @@ -49,10 +49,12 @@ abstract class StateX extends State implements StateListener { // - /// With an optional StateXController parameter and built-in InheritedWidget use - StateX({StateXController? controller, bool? useInherited}) { + /// With an optional StateXController parameter and built-in FutureBuilder & InheritedWidget use + StateX({StateXController? controller, bool? runAsync, bool? useInherited}) { // Add to the list of StateX objects present in the app! _addToMapOfStates(this); + // A flag whether the built-in FutureBuilder runs with every setState() call. + _runAsync = runAsync ?? false; // A flag determining whether the built-in InheritedWidget is used or not. _useInherited = useInherited ?? false; // Associate the controller to this State object @@ -63,6 +65,9 @@ abstract class StateX extends State StateXController? _controller; + /// Run the built-in FutureBuilder with every setState() call + late bool _runAsync; + /// Use this function instead of build() to use the built-in InheritedWidget. @override @protected @@ -1169,6 +1174,11 @@ abstract class StateX extends State /// Refresh the interface by 'rebuilding' the Widget Tree /// Call the State object's setState() function. super.setState(fn); + + if (_ranAsync && _runAsync) { + // Run the FutureBuilder again and again + _ranAsync = false; + } } _setStateAllowed = true; } else { @@ -1190,6 +1200,16 @@ abstract class StateX extends State } } +/// A State object the runs its built-in FutureBuilder with every setState() +/// +/// dartdoc: +/// {@category StateX class} +abstract class StateF extends StateX { + /// + StateF({StateXController? controller}) + : super(controller: controller, runAsync: true); +} + /// A State object that explicitly implements a built-in InheritedWidget /// /// dartdoc: diff --git a/pubspec.yaml b/pubspec.yaml index a0911e7..ae7d93d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: state_extended description: This class extends the capabilities of Flutter's State class and includes a controller. -version: 4.9.0 +version: 4.10.0 homepage: https://www.andrioussolutions.com repository: https://github.com/AndriousSolutions/state_extended