Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit eddb242

Browse files
committed
Update docs.
1 parent 12f273d commit eddb242

File tree

5 files changed

+76
-62
lines changed

5 files changed

+76
-62
lines changed

lib/ui/platform_dispatcher.dart

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,19 +1642,37 @@ class FrameTiming {
16421642

16431643
/// States that an application can be in once it is running.
16441644
///
1645+
/// States not supported on a platform will be synthesized by the framework when
1646+
/// transitioning between states which are supported, so that all
1647+
/// implementations share the same state machine.
1648+
///
16451649
/// The current application state can be obtained from
1646-
/// [SchedulerBinding.instance.lifecycleState], and changes in state can be
1650+
/// [SchedulerBinding.instance.lifecycleState], and changes to the state can be
16471651
/// observed by creating an [AppLifecycleListener], or by using a
16481652
/// [WidgetsBindingObserver] by overriding the
16491653
/// [WidgetsBindingObserver.didChangeAppLifecycleState] method.
16501654
///
1651-
/// Applications should not expect to always receive all possible notifications.
1655+
/// Applications should not rely on always receiving all possible notifications.
16521656
///
16531657
/// For example, if the application is killed with a task manager, a kill
16541658
/// signal, the user pulls the power from the device, or there is a rapid
16551659
/// unscheduled disassembly of the device, no notification will be sent before
16561660
/// the application is suddenly terminated, and some states may be skipped.
16571661
enum AppLifecycleState {
1662+
/// The application is still hosted by a Flutter engine but is detached from
1663+
/// any host views.
1664+
///
1665+
/// The application defaults to this state before it initializes, and can be
1666+
/// in this state (on Android and iOS only) after all views have been
1667+
/// detached.
1668+
///
1669+
/// When the application is in this state, the engine is running without a
1670+
/// view.
1671+
///
1672+
/// This state is only entered on iOS and Android, although on all platforms
1673+
/// it is the default state before the application begins running.
1674+
detached,
1675+
16581676
/// The application is in the default running mode for a running application
16591677
/// that has input focus and is visible.
16601678
resumed,
@@ -1705,20 +1723,6 @@ enum AppLifecycleState {
17051723
///
17061724
/// This state is only entered on iOS and Android.
17071725
paused,
1708-
1709-
/// The application is still hosted by a Flutter engine but is detached from
1710-
/// any host views.
1711-
///
1712-
/// The application defaults to this state before it initializes, and can be
1713-
/// in this state (on Android and iOS only) after all views have been
1714-
/// detached.
1715-
///
1716-
/// When the application is in this state, the engine is running without a
1717-
/// view.
1718-
///
1719-
/// This state is only entered on iOS and Android, although on all platforms
1720-
/// it is the default state before anything has been intitialized.
1721-
detached,
17221726
}
17231727

17241728
/// The possible responses to a request to exit the application.

lib/web_ui/lib/platform_dispatcher.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,11 +245,11 @@ class FrameTiming {
245245
}
246246

247247
enum AppLifecycleState {
248+
detached,
248249
resumed,
249250
inactive,
250251
hidden,
251252
paused,
252-
detached,
253253
}
254254

255255
enum AppExitResponse {

shell/platform/common/application_lifecycle.h

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,49 +11,48 @@ namespace flutter {
1111
/// must be kept up to date with changes in the framework's AppLifecycleState
1212
/// enum. It is passed to the embedder's |SetLifecycleState| function.
1313
///
14-
/// |SetLifecycleState| will validate that the state transition is a valid state
15-
/// transition, and will assert if it is not. States not supported on a platform
16-
/// will be emitted when transitioning between states which are supported, so
17-
/// that all implementations share the same allowed state machine. Here is the
18-
/// allowed state machine:
19-
///
20-
/// +-----------+ +-----------+
21-
/// | detached |------------------------------>| resumed |
22-
/// +-----------+ +-----------+
23-
/// ^ ^
24-
/// | |
25-
/// | v
26-
/// +-----------+ +--------------+ +-----------+
27-
/// | paused |<------>| hidden |<----->| inactive |
28-
/// +-----------+ +--------------+ +-----------+
29-
///
30-
/// The states and their meanings are as follows:
31-
///
32-
/// detached: The initial state of the state machine. On Android and iOS,
33-
/// also the final state of the state machine when all views are
34-
/// detached. Other platforms do not enter this state again after
35-
/// initially leaving it.
36-
///
37-
/// resumed: The nominal "running" state of the application. The
38-
/// application is visible, has input focus, and is running.
39-
///
40-
/// inactive: At least one view of the application is visible, but none
41-
/// have input focus. The application is otherwise running
42-
/// normally.
43-
///
44-
/// hidden: All views of an application are hidden, either because the
45-
/// application is being stopped (on iOS and Android), or because
46-
/// it is being minimized or on a desktop that is no longer visible
47-
/// (on desktop), or on a tab that is no longer visible (on web).
48-
///
49-
/// paused: The application is not running, and can be detached or started
50-
/// again at any time. This state is typically only entered into on
51-
/// iOS and Android.
14+
/// States not supported on a platform will be synthesized by the framework when
15+
/// transitioning between states which are supported, so that all
16+
/// implementations share the same state machine.
17+
///
18+
/// Here is the state machine:
19+
///
20+
/// +-----------+ +-----------+
21+
/// | detached |------------------------------>| resumed |
22+
/// +-----------+ +-----------+
23+
/// ^ ^
24+
/// | |
25+
/// | v
26+
/// +-----------+ +--------------+ +-----------+
27+
/// | paused |<------>| hidden |<----->| inactive |
28+
/// +-----------+ +--------------+ +-----------+
5229
typedef enum {
30+
/// Corresponds to AppLifecycleState.detached: The initial state of the state
31+
/// machine. On Android and iOS, also the final state of the state machine
32+
/// when all views are detached. Other platforms do not enter this state again
33+
/// after initially leaving it.
5334
kAppLifecycleStateDetached = 0x0,
35+
36+
/// Corresponds to AppLifecycleState.resumed: The nominal "running" state of
37+
/// the
38+
/// application. The application is visible, has input focus, and is running.
5439
kAppLifecycleStateResumed = 0x1,
40+
41+
/// Corresponds to AppLifecycleState.inactive: At least one view of the
42+
/// application is visible, but none have input focus. The application is
43+
/// otherwise running normally.
5544
kAppLifecycleStateInactive = 0x2,
45+
46+
/// Corresponds to AppLifecycleState.hidden: All views of an application are
47+
/// hidden, either because the application is being stopped (on iOS and
48+
/// Android), or because it is being minimized or on a desktop that is no
49+
/// longer visible (on desktop), or on a tab that is no longer visible (on
50+
/// web).
5651
kAppLifecycleStateHidden = 0x3,
52+
53+
/// Corresponds to AppLifecycleState.paused: The application is not running,
54+
/// and can be detached or started again at any time. This state is typically
55+
/// only entered into on iOS and Android.
5756
kAppLifecycleStatePaused = 0x4,
5857
} AppLifecycleState;
5958

shell/platform/darwin/macos/framework/Headers/FlutterAppLifecycleDelegate.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ NS_ASSUME_NONNULL_BEGIN
1515

1616
#pragma mark -
1717
/**
18-
* Protocol for listener of events from the NSApplication, typically a
18+
* Protocol for listener of lifecycle events from the NSApplication, typically a
1919
* FlutterPlugin.
2020
*/
2121
@protocol FlutterAppLifecycleDelegate <NSObject>
@@ -96,21 +96,28 @@ NS_ASSUME_NONNULL_BEGIN
9696
/**
9797
* Called when the |FlutterAppDelegate| gets the applicationWillTerminate
9898
* notification.
99+
*
100+
* Applications should not rely on always receiving all possible notifications.
101+
*
102+
* For example, if the application is killed with a task manager, a kill signal,
103+
* the user pulls the power from the device, or there is a rapid unscheduled
104+
* disassembly of the device, no notification will be sent before the
105+
* application is suddenly terminated, and this notification may be skipped.
99106
*/
100107
- (void)handleWillTerminate:(NSNotification*)notification;
101108
@end
102109

103110
#pragma mark -
104111

105112
/**
106-
* Propagates `NSAppDelegate` callbacks to registered plugins.
113+
* Propagates `NSAppDelegate` callbacks to registered delegates.
107114
*/
108115
FLUTTER_DARWIN_EXPORT
109116
@interface FlutterAppLifecycleRegistrar : NSObject <FlutterAppLifecycleDelegate>
110117

111118
/**
112-
* Registers `delegate` to receive life cycle callbacks via this FlutterAppLifecycleDelegate
113-
* as long as it is alive.
119+
* Registers `delegate` to receive lifecycle callbacks via this
120+
* FlutterAppLifecycleDelegate as long as it is alive.
114121
*
115122
* `delegate` will only be referenced weakly.
116123
*/
@@ -119,6 +126,8 @@ FLUTTER_DARWIN_EXPORT
119126
/**
120127
* Unregisters `delegate` so that it will no longer receive life cycle callbacks
121128
* via this FlutterAppLifecycleDelegate.
129+
*
130+
* `delegate` will only be referenced weakly.
122131
*/
123132
- (void)removeDelegate:(NSObject<FlutterAppLifecycleDelegate>*)delegate;
124133
@end

shell/platform/darwin/macos/framework/Source/FlutterAppLifecycleDelegate.mm

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@ - (instancetype)init {
4040
// selector.
4141
#ifdef OBSERVE_NOTIFICATION
4242
#error OBSERVE_NOTIFICATION ALREADY DEFINED!
43-
#endif
43+
#else
4444
#define OBSERVE_NOTIFICATION(SELECTOR) \
4545
[self addObserverFor:NSApplication##SELECTOR##Notification selector:@selector(handle##SELECTOR:)]
46+
#endif
4647

4748
OBSERVE_NOTIFICATION(WillFinishLaunching);
4849
OBSERVE_NOTIFICATION(DidFinishLaunching);
@@ -104,8 +105,9 @@ - (void)removeDelegate:(NSObject<FlutterAppLifecycleDelegate>*)delegate {
104105
}
105106
}
106107

107-
// This isn't done via performSelector because that can cause leaks due
108-
// to the selector not being known.
108+
// This isn't done via performSelector because that can cause leaks due to the
109+
// selector not being known. Using a macro to avoid mismatch errors between the
110+
// notification and the selector.
109111
#ifdef DISTRIBUTE_NOTIFICATION
110112
#error DISTRIBUTE_NOTIFICATION ALREADY DEFINED!
111113
#else

0 commit comments

Comments
 (0)