diff --git a/packages/flutter/lib/src/widgets/binding.dart b/packages/flutter/lib/src/widgets/binding.dart index f73504d208..885b18149f 100644 --- a/packages/flutter/lib/src/widgets/binding.dart +++ b/packages/flutter/lib/src/widgets/binding.dart @@ -877,6 +877,9 @@ mixin WidgetsBinding on BindingBase, ServicesBinding, SchedulerBinding, GestureB } _needToReportFirstFrame = false; if (firstFrameCallback != null && !sendFramesToEngine) { + // This frame is deferred and not the first frame sent to the engine that + // should be reported. + _needToReportFirstFrame = true; SchedulerBinding.instance.removeTimingsCallback(firstFrameCallback); } } diff --git a/packages/flutter/test/widgets/binding_first_frame_rasterized_test.dart b/packages/flutter/test/widgets/binding_first_frame_rasterized_test.dart new file mode 100644 index 0000000000..80113cc57d --- /dev/null +++ b/packages/flutter/test/widgets/binding_first_frame_rasterized_test.dart @@ -0,0 +1,33 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:ui'; + +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:quiver/testing/async.dart'; + +void main() { + test('Deferred frames will trigger the first frame callback', () { + FakeAsync().run((FakeAsync fakeAsync) { + final WidgetsBinding binding = WidgetsFlutterBinding.ensureInitialized(); + binding.deferFirstFrame(); + + runApp(const Placeholder()); + fakeAsync.flushTimers(); + + // Simulates the engine completing a frame render to trigger the + // appropriate callback setting [WidgetBinding.firstFrameRasterized]. + binding.window.onReportTimings([]); + expect(binding.firstFrameRasterized, isFalse); + + binding.allowFirstFrame(); + fakeAsync.flushTimers(); + + // Simulates the engine again. + binding.window.onReportTimings([]); + expect(binding.firstFrameRasterized, isTrue); + }); + }); +}