@@ -288,12 +288,13 @@ class _ContentInput extends StatefulWidget {
288
288
State <_ContentInput > createState () => _ContentInputState ();
289
289
}
290
290
291
- class _ContentInputState extends State <_ContentInput > {
291
+ class _ContentInputState extends State <_ContentInput > with WidgetsBindingObserver {
292
292
@override
293
293
void initState () {
294
294
super .initState ();
295
295
widget.controller.addListener (_contentChanged);
296
296
widget.focusNode.addListener (_focusChanged);
297
+ WidgetsBinding .instance.addObserver (this );
297
298
}
298
299
299
300
@override
@@ -313,6 +314,7 @@ class _ContentInputState extends State<_ContentInput> {
313
314
void dispose () {
314
315
widget.controller.removeListener (_contentChanged);
315
316
widget.focusNode.removeListener (_focusChanged);
317
+ WidgetsBinding .instance.removeObserver (this );
316
318
super .dispose ();
317
319
}
318
320
@@ -333,6 +335,34 @@ class _ContentInputState extends State<_ContentInput> {
333
335
store.typingNotifier.stoppedComposing ();
334
336
}
335
337
338
+ @override
339
+ void didChangeAppLifecycleState (AppLifecycleState state) {
340
+ switch (state) {
341
+ case AppLifecycleState .hidden:
342
+ case AppLifecycleState .paused:
343
+ case AppLifecycleState .detached:
344
+ // Transition to either [hidden] or [paused] signals that
345
+ // > [the] application is not currently visible to the user, and not
346
+ // > responding to user input.
347
+ //
348
+ // When transitioning to [detached], the compose box can't exist:
349
+ // > The application defaults to this state before it initializes, and
350
+ // > can be in this state (applicable on Android, iOS, and web) after
351
+ // > all views have been detached.
352
+ //
353
+ // For all these states, we can conclude that the user is not
354
+ // composing a message.
355
+ final store = PerAccountStoreWidget .of (context);
356
+ store.typingNotifier.stoppedComposing ();
357
+ case AppLifecycleState .inactive:
358
+ // > At least one view of the application is visible, but none have
359
+ // > input focus. The application is otherwise running normally.
360
+ // For example, we expect this state when the user is selecting a file
361
+ // to upload.
362
+ case AppLifecycleState .resumed:
363
+ }
364
+ }
365
+
336
366
@override
337
367
Widget build (BuildContext context) {
338
368
ColorScheme colorScheme = Theme .of (context).colorScheme;
0 commit comments