Support first frame notification in trivial apps (#3618)
Apps that didn't use [WidgetsApp] were not sending the `'Widgets completed first useful frame'` notification. This fixes that by making the code cleaner.
This commit is contained in:
@@ -161,12 +161,11 @@ class WidgetsAppState<T extends WidgetsApp> extends State<T> implements WidgetsB
|
||||
// If the app expects a locale but we don't yet know the locale, then
|
||||
// don't build the widgets now.
|
||||
// TODO(ianh): Make this unnecessary. See https://github.com/flutter/flutter/issues/1865
|
||||
// TODO(ianh): The following line should not be included in release mode, only in profile and debug modes.
|
||||
WidgetsBinding.instance.preventThisFrameFromBeingReportedAsFirstFrame();
|
||||
return new Container();
|
||||
}
|
||||
|
||||
// TODO(ianh): The following line should not be included in release mode, only in profile and debug modes.
|
||||
WidgetsBinding.instance.didFirstFrame();
|
||||
|
||||
Widget result = new MediaQuery(
|
||||
data: new MediaQueryData.fromWindow(ui.window),
|
||||
child: new LocaleQuery(
|
||||
|
||||
@@ -172,15 +172,17 @@ abstract class WidgetsBinding extends BindingBase implements GestureBinding, Ren
|
||||
observer.didChangeAppLifecycleState(state);
|
||||
}
|
||||
|
||||
bool _didFirstFrame = false;
|
||||
bool _reportFirstFrame = true;
|
||||
bool _needToReportFirstFrame = true;
|
||||
bool _thisFrameWasUseful = true;
|
||||
|
||||
/// Tell the framework that the first useful frame has been completed.
|
||||
/// Tell the framework that the frame we are currently building
|
||||
/// should not be considered to be a useful first frame.
|
||||
///
|
||||
/// This is used by [WidgetsApp] to report the first frame.
|
||||
// remove this once we've fixed https://github.com/flutter/flutter/issues/1865
|
||||
void didFirstFrame() {
|
||||
_didFirstFrame = true;
|
||||
//
|
||||
// TODO(ianh): This method should only be available in debug and profile modes.
|
||||
void preventThisFrameFromBeingReportedAsFirstFrame() {
|
||||
_thisFrameWasUseful = false;
|
||||
}
|
||||
|
||||
void _handleBuildScheduled() {
|
||||
@@ -202,10 +204,14 @@ abstract class WidgetsBinding extends BindingBase implements GestureBinding, Ren
|
||||
_buildingDirtyElements = false;
|
||||
super.beginFrame();
|
||||
buildOwner.finalizeTree();
|
||||
// TODO(ianh): Following code should not be included in release mode, only profile and debug mode
|
||||
if (_reportFirstFrame && _didFirstFrame) {
|
||||
developer.Timeline.instantSync('Widgets completed first useful frame');
|
||||
_reportFirstFrame = false;
|
||||
// TODO(ianh): Following code should not be included in release mode, only profile and debug modes.
|
||||
if (_needToReportFirstFrame) {
|
||||
if (_thisFrameWasUseful) {
|
||||
_thisFrameWasUseful = true;
|
||||
} else {
|
||||
developer.Timeline.instantSync('Widgets completed first useful frame');
|
||||
_needToReportFirstFrame = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user