binding_attach_root_widget_test.dart 1008 Bytes
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/scheduler.dart';
6
import 'package:flutter/services.dart';
7
import 'package:flutter/widgets.dart';
8
import 'package:flutter_test/flutter_test.dart';
9 10 11

void main() {
  test('attachRootWidget will schedule a frame', () async {
12
    final WidgetsFlutterBinding binding = WidgetsFlutterBinding.ensureInitialized() as WidgetsFlutterBinding;
13
    expect(SchedulerBinding.instance.hasScheduledFrame, isFalse);
14
    // Framework starts with detached statue. Sends resumed signal to enable frame.
15
    final ByteData message = const StringCodec().encodeMessage('AppLifecycleState.resumed')!;
16
    await ServicesBinding.instance.defaultBinaryMessenger.handlePlatformMessage('flutter/lifecycle', message, (_) { });
17 18

    binding.attachRootWidget(const Placeholder());
19
    expect(SchedulerBinding.instance.hasScheduledFrame, isTrue);
20 21
  });
}