Skip to content

Commit

Permalink
5.2.1
Browse files Browse the repository at this point in the history
Took 52 minutes
  • Loading branch information
Drawner committed Sep 25, 2024
1 parent 782126a commit 6903e4f
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 16 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@

## 5.2.0

## 5.2.1
September 25, 2024
- Introduce getters, deactivated and disposed in part01_statex.dart
if (_deactivated) and if (_disposed || !_deactivated) in part01_statex.dart

## 5.2.0+1
September 23, 2024
- Parameter, 'showBinding', renamed 'printEvents'
- catchAsyncError() with try..catch in FutureBuilderStateMixin
- con.onAsyncError() with try..catch in part18_async_ops_mixin.dart
- appState.builder() with try..catch in part10_builder_statefulwidget.dart
- Call a group of tests: group('Test state_extended', testStateExtended);

## 5.1.0
September 20, 2024
Expand Down
2 changes: 1 addition & 1 deletion example/lib/src/controller/app/app_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ExampleAppController extends StateXController with EventsControllerMixin {
@override
void onAsyncError(FlutterErrorDetails details) {}

/// Error right at the start
/// Error in builder()
bool errorInBuilder = false;

/// Allow for a Splash screen or not
Expand Down
9 changes: 6 additions & 3 deletions example/test/widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ import 'package:integration_test/integration_test.dart'

import '../test/_test_imports.dart';

void main() => group('Test state_extended', testApp);
void main() => testExampleApp();

/// Call a group of tests.
void testExampleApp() => group('Test state_extended', testStateExtended);

late IntegrationTestsBinder _integrationTest;

/// Also called in package's own testing file, test/widget_test.dart
void testApp() {
void testStateExtended() {
//
/// Set up anything necessary before testing begins.
/// Runs once before ALL tests or groups
Expand All @@ -39,7 +42,7 @@ void testApp() {
/// Runs after EACH test or group
tearDown(() async {
// Code that clears caches can go here
// exit(0);
// exit(0); // Closes the whole thing!
});

// Call this function instead of using the 'default' TestWidgetsFlutterBinding
Expand Down
23 changes: 18 additions & 5 deletions lib/part01_statex.dart
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ abstract class StateX<T extends StatefulWidget> extends State<StatefulWidget>
/// the tree to another due to the use of a [GlobalKey]).
// Likely was deactivated.
deactivated = false;
_deactivated = false;

// Add to the list of StateX objects present in the app!
_addToMapOfStates(this);
Expand Down Expand Up @@ -444,8 +444,13 @@ abstract class StateX<T extends StatefulWidget> extends State<StatefulWidget>
/// from the tree. Subclasses should override this method to clean up any links between
/// this object and other elements in the tree.
/// Users may have explicitly call this.
if (_deactivated) {
return;
}

// Indicate this State object is deactivated.
deactivated = true;
_deactivated = true;

/// Ignore Route changes
RouteObserverStates.unsubscribeRoutes(this);
Expand Down Expand Up @@ -487,7 +492,8 @@ abstract class StateX<T extends StatefulWidget> extends State<StatefulWidget>
}

/// State object's deactivated() was called.
bool deactivated = false;
bool get deactivated => _deactivated;
bool _deactivated = false;

/// The framework calls this method when this [StateX] object will never
/// build again and will be disposed of with garbage collection.
Expand All @@ -500,12 +506,18 @@ abstract class StateX<T extends StatefulWidget> extends State<StatefulWidget>
/// Subclasses should override deactivate() method instead
/// to release any resources (e.g., stop any active animations).
/// Users may have explicitly call this.
if (_disposed || !_deactivated) {
return;
}

/// Indicate this State object is terminated.
disposed = true;
_disposed = true;

// No 'setState()' functions are allowed to fully function at this point.
_setStateAllowed = false;

/// Call its controllers' dispose() functions
for (final con in controllerList) {
con.dispose();
}
Expand Down Expand Up @@ -533,7 +545,8 @@ abstract class StateX<T extends StatefulWidget> extends State<StatefulWidget>
/// Flag indicating this State object is disposed.
/// Will be garbage collected.
/// property, mounted, is then set to false.
bool disposed = false;
bool get disposed => _disposed;
bool _disposed = false;

/// Override this method to respond when its [StatefulWidget] is re-created.
/// The framework always calls [build] after calling [didUpdateWidget], which
Expand Down
4 changes: 2 additions & 2 deletions lib/part08_app_statex.dart
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ abstract class AppStateX<T extends StatefulWidget> extends StateX<T>
}

try {
if (!state.disposed) {
if (!state._disposed) {
state.dispose();
}
} catch (e, stack) {
Expand All @@ -230,7 +230,7 @@ abstract class AppStateX<T extends StatefulWidget> extends StateX<T>
//
try {
//
if (state.mounted && !state.deactivated) {
if (state.mounted && !state._deactivated) {
//
final response = await state.didRequestAppExit();

Expand Down
4 changes: 2 additions & 2 deletions lib/part11_map_of_states.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ mixin _MapOfStates on State {
StateX? nextState;
final list = statesList(reversed: reversed);
for (final StateX state in list) {
if (state.mounted && !state.deactivated) {
if (state.mounted && !state._deactivated) {
nextState = state;
break;
}
Expand All @@ -105,7 +105,7 @@ mixin _MapOfStates on State {
final list = statesList(reversed: reversed, remove: remove);
for (final StateX state in list) {
try {
if (state.mounted && !state.deactivated) {
if (state.mounted && !state._deactivated) {
func(state);
}
} catch (e, stack) {
Expand Down
2 changes: 1 addition & 1 deletion lib/part14_set_state_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ mixin SetStateMixin {
}
for (final StateX state in it) {
try {
if (state.mounted && !state.deactivated) {
if (state.mounted && !state._deactivated) {
func(state);
}
} catch (e, stack) {
Expand Down
2 changes: 1 addition & 1 deletion test/state_extended_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
// Calls the example app's very own test
import '../example/test/widget_test.dart';

void main() => testApp();
void main() => testExampleApp();

0 comments on commit 6903e4f

Please sign in to comment.