Skip to content

Commit

Permalink
4.20.0
Browse files Browse the repository at this point in the history
Took 8 hours 59 minutes
  • Loading branch information
Drawner committed Jul 14, 2024
1 parent ef04fa7 commit e6477ac
Show file tree
Hide file tree
Showing 9 changed files with 924 additions and 637 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@

## 4.20.0
July 14, 2024
- AppState class loops through all the app's StateX objects when an event occurs.
Each StateX class will otherwise register as its own binding observer:
WidgetsBinding.instance.addObserver(this);
- The getter, didCallChangeEvent, serves as a flag for event handling
// Already called by another State object currently running.
if (didCallChangeEvent) {
- didPushRoute(String route) is now deprecated after v3.8.0-14.0.pre

## 4.19.0
July 10, 2024
- AppState.detachedAppLifecycleState() 'attempts' to call State object's deactivate() and dispose()
Expand Down
68 changes: 35 additions & 33 deletions example/lib/src/controller/app/common/events_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:ui' show Locale;
import 'dart:ui' show AppExitResponse, Locale;

import 'package:flutter/foundation.dart';

Expand Down Expand Up @@ -50,14 +50,12 @@ mixin EventsControllerMixin on StateXController {
}
return true;
}());
super.deactivate();
}

/// Called when this object is reinserted into the tree after having been
/// removed via [deactivate].
@override
void activate() {
super.activate();
assert(() {
if (kDebugMode) {
print('=========== activate() in $className\n');
Expand All @@ -71,13 +69,13 @@ mixin EventsControllerMixin on StateXController {
/// Note: YOU WILL HAVE NO IDEA WHEN THIS WILL RUN in the Framework.
@override
void dispose() {
super.dispose();
assert(() {
if (kDebugMode) {
print('=========== dispose() in $className\n');
}
return true;
}());
super.dispose();
}

/// Called when this State is *first* added to as a Route observer?!
Expand Down Expand Up @@ -149,7 +147,6 @@ mixin EventsControllerMixin on StateXController {
/// when a phone is rotated.
@override
void didChangeMetrics() {
super.didChangeMetrics();
assert(() {
if (kDebugMode) {
print('=========== didChangeMetrics() in $className\n');
Expand All @@ -161,7 +158,6 @@ mixin EventsControllerMixin on StateXController {
/// Called when the platform's text scale factor changes.
@override
void didChangeTextScaleFactor() {
super.didChangeTextScaleFactor();
assert(() {
if (kDebugMode) {
print('=========== didChangeTextScaleFactor() in $className\n');
Expand All @@ -173,7 +169,6 @@ mixin EventsControllerMixin on StateXController {
/// Brightness changed.
@override
void didChangePlatformBrightness() {
super.didChangePlatformBrightness();
assert(() {
if (kDebugMode) {
print('=========== didChangePlatformBrightness() in $className\n');
Expand All @@ -185,7 +180,6 @@ mixin EventsControllerMixin on StateXController {
/// Called when the system tells the app that the user's locale has changed.
@override
void didChangeLocales(List<Locale>? locales) {
super.didChangeLocales(locales);
assert(() {
if (kDebugMode) {
print('=========== didChangeLocales() in $className\n');
Expand All @@ -194,73 +188,70 @@ mixin EventsControllerMixin on StateXController {
}());
}

/// Either be in the progress of attaching when the engine is first initializing
/// or after the view being destroyed due to a Navigator pop.
/// The application is in an inactive state and is not receiving user input.
/// Apps in this state should assume that they may be [pausedAppLifecycleState] at any time.
@override
void detachedAppLifecycleState() {
void inactiveAppLifecycleState() {
assert(() {
if (kDebugMode) {
print('=========== detachedAppLifecycleState() in $className\n');
print('=========== inactiveAppLifecycleState() in $className\n');
}
return true;
}());
super.detachedAppLifecycleState();
}

/// The application is visible and responding to user input.
/// All views of an application are hidden, either because the application is
/// about to be paused (on iOS and Android), or because it has been minimized
/// or placed on a desktop that is no longer visible (on non-web desktop), or
/// is running in a window or tab that is no longer visible (on the web).
@override
void resumedAppLifecycleState() {
void hiddenAppLifecycleState() {
assert(() {
if (kDebugMode) {
print('=========== resumedAppLifecycleState() in $className\n');
print('=========== hiddenAppLifecycleState() in $className\n');
}
return true;
}());
}

/// The application is in an inactive state and is not receiving user input.
/// Apps in this state should assume that they may be [pausedAppLifecycleState] at any time.
/// The application is not currently visible to the user, not responding to
/// user input, and running in the background.
@override
void inactiveAppLifecycleState() {
void pausedAppLifecycleState() {
assert(() {
if (kDebugMode) {
print('=========== inactiveAppLifecycleState() in $className\n');
print('=========== pausedAppLifecycleState() in $className\n');
}
return true;
}());
}

/// All views of an application are hidden, either because the application is
/// about to be paused (on iOS and Android), or because it has been minimized
/// or placed on a desktop that is no longer visible (on non-web desktop), or
/// is running in a window or tab that is no longer visible (on the web).
/// Either be in the progress of attaching when the engine is first initializing
/// or after the view being destroyed due to a Navigator pop.
@override
void hiddenAppLifecycleState() {
void detachedAppLifecycleState() {
assert(() {
if (kDebugMode) {
print('=========== hiddenAppLifecycleState() in $className\n');
print('=========== detachedAppLifecycleState() in $className\n');
}
return true;
}());
}

/// The application is not currently visible to the user, not responding to
/// user input, and running in the background.
/// The application is visible and responding to user input.
@override
void pausedAppLifecycleState() {
void resumedAppLifecycleState() {
assert(() {
if (kDebugMode) {
print('=========== pausedAppLifecycleState() in $className\n');
print('=========== resumedAppLifecycleState() in $className\n');
}
return true;
}());
super.pausedAppLifecycleState();
}

/// Called when there's a memory constraint.
@override
void didHaveMemoryPressure() {
super.didHaveMemoryPressure();
assert(() {
if (kDebugMode) {
print('=========== didHaveMemoryPressure() in $className\n');
Expand All @@ -272,12 +263,23 @@ mixin EventsControllerMixin on StateXController {
/// Called when the system changes the set of active accessibility features.
@override
void didChangeAccessibilityFeatures() {
super.didChangeAccessibilityFeatures();
assert(() {
if (kDebugMode) {
print('=========== didChangeAccessibilityFeatures() in $className\n');
}
return true;
}());
}

/// Called when a request is received from the system to exit the application.
@override
Future<AppExitResponse> didRequestAppExit() {
assert(() {
if (kDebugMode) {
print('=========== didRequestAppExit() in $className\n');
}
return true;
}());
return super.didRequestAppExit();
}
}
4 changes: 4 additions & 0 deletions example/lib/src/controller/home/another_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ class AnotherController extends StateXController
/// when a phone is rotated.
@override
void didChangeMetrics() {
// Already called by another State object currently running.
if (didCallChangeEvent) {
return;
}
super.didChangeMetrics();
// call setState() function to test State object
rootState?.setState(() {});
Expand Down
2 changes: 2 additions & 0 deletions example/lib/src/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export 'package:flutter/material.dart' hide StateSetter;

export 'package:state_extended/state_extended.dart';

export '/src/view/app/common/class_name_mixin.dart';

export '/src/view/app/common/events_state.dart';

export '/src/view/app/my_app.dart';
Expand Down
23 changes: 23 additions & 0 deletions example/lib/src/view/app/common/class_name_mixin.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
///
mixin ClassNameMixin on Object {
///
String get className {
if (_className == null) {
final name = '$this';
final hash = name.indexOf('#');
if (hash > 0) {
_className = name.substring(0, hash);
} else {
final parts = name.split(' ');
_className = parts.last;
}
}
return _className!;
}

set className(String? name) =>
_className ??= name?.isEmpty ?? true ? null : name;

String? _className;
}
5 changes: 2 additions & 3 deletions example/lib/src/view/app/common/events_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ mixin EventsStateMixin<T extends StatefulWidget> on StateX<T> {
/// Whenever it removes
@override
void deactivate() {
super.deactivate();
assert(() {
if (kDebugMode) {
print('########### deactivate() in $className\n');
}
return true;
}());
super.deactivate();
}

/// Called when this object is reinserted into the tree after having been
Expand All @@ -69,13 +69,13 @@ mixin EventsStateMixin<T extends StatefulWidget> on StateX<T> {
/// Note: YOU WILL HAVE NO IDEA WHEN THIS WILL RUN in the Framework.
@override
void dispose() {
super.dispose();
assert(() {
if (kDebugMode) {
print('########### dispose() in $className\n');
}
return true;
}());
super.dispose();
}

/// Called when this State is *first* added to as a Route observer?!
Expand Down Expand Up @@ -252,7 +252,6 @@ mixin EventsStateMixin<T extends StatefulWidget> on StateX<T> {
}
return true;
}());
super.pausedAppLifecycleState();
}

/// Called when there's a memory constraint.
Expand Down
2 changes: 1 addition & 1 deletion example/lib/src/view/app/my_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class MyApp extends StatefulWidget {
}

///
class _MyAppState extends AppStateX<MyApp> with EventsStateMixin<MyApp> {
class _MyAppState extends AppStateX<MyApp> with ClassNameMixin {
//
_MyAppState()
: super(
Expand Down
Loading

0 comments on commit e6477ac

Please sign in to comment.