Repository navigation
Add to app engine does not report correct life cycle state during warm up #39832
Copy link
Copy link
Closed
Labels
a: existing-appsIntegration with existing apps via the add-to-app flowIntegration with existing apps via the add-to-app flowengineflutter/engine related. See also e: labels.flutter/engine related. See also e: labels.
Description
Steps to Reproduce
- follow this document to setup add to app https://github.com/flutter/samples/tree/master/experimental/add_to_app/SimpleIOSExample
- update the main function in this file
experimental/add_to_app/example_module/lib/main.dart
// Copyright 2019 The Flutter team. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Module Title',
routes: {
'/': (context) => FullScreenView(),
'/mini': (context) => MiniView(),
},
);
}
}
class FullScreenView extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('A Full-screen Flutter View'),
),
body: const MiniView(showExit: true),
);
}
}
class MiniView extends StatefulWidget {
final bool showExit;
const MiniView({this.showExit = false});
@override
_MiniViewState createState() => _MiniViewState();
}
class _MiniViewState extends State<MiniView> with WidgetsBindingObserver {
int count = 0;
AppLifecycleState _lastLifecycleState;
@override
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
}
@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
setState(() {
_lastLifecycleState = state;
});
}
@override
Widget build(BuildContext context) {
final mediaInfo = MediaQuery.of(context);
print('current state $_lastLifecycleState');
return SizedBox.expand(
child: Stack(
children: [
Positioned.fill(
child: DecoratedBox(
decoration: BoxDecoration(
color: Theme.of(context).scaffoldBackgroundColor,
),
),
),
Positioned.fill(
child: Opacity(
opacity: .25,
child: FittedBox(
fit: BoxFit.cover,
child: FlutterLogo(),
),
),
),
Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Window is ${mediaInfo.size.width} x '
'${mediaInfo.size.height}.',
style: Theme.of(context).textTheme.headline,
),
SizedBox(height: 16),
Text(
'Taps: $count',
style: Theme.of(context).textTheme.headline,
),
SizedBox(height: 16),
RaisedButton(
onPressed: () => setState(() => count++),
child: Text('Tap me!'),
),
if (widget.showExit) ...[
SizedBox(height: 16),
RaisedButton(
onPressed: () => SystemNavigator.pop(),
child: Text('Exit this screen'),
),
],
],
),
),
],
),
);
}
}
- run the app, and the widget is first build during initialization with lifecyclestate = null which it should be pause.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
a: existing-appsIntegration with existing apps via the add-to-app flowIntegration with existing apps via the add-to-app flowengineflutter/engine related. See also e: labels.flutter/engine related. See also e: labels.
Activity
chunhtai commentedon Sep 4, 2019
@xster
xster commentedon Sep 4, 2019
I assume you specifically meant that _lastLifecycleState is null because WidgetsBindingObserver.didChangeAppLifecycleState is never called right?
chunhtai commentedon Sep 4, 2019
It is never called, but there is more to it.
When the binding first initialized, it will poll the state from window.initialLifecycleState which engine should attach its state to. The engine, however, doesn't seems to attach anything to it during the warm up. Otherwise, WidgetsBindingObserver.didChangeAppLifecycleState would have been called when widget is built
chunhtai commentedon Nov 22, 2019
Change reverted and is pending on #45270
chunhtai commentedon Jan 18, 2020
another internal test failed
github-actions commentedon Aug 23, 2021
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.