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

5
import 'package:flutter/foundation.dart';
6
import 'package:flutter/rendering.dart';
7
import 'package:flutter_test/flutter_test.dart';
8 9 10 11 12

import 'rendering_tester.dart';

class RealRoot extends AbstractNode {
  RealRoot(this.child) {
13
    adoptChild(child);
14 15 16 17 18 19
  }

  final RenderObject child;

  @override
  void redepthChildren() {
20
    redepthChild(child);
21 22 23 24 25
  }

  @override
  void attach(Object owner) {
    super.attach(owner);
26
    child.attach(owner as PipelineOwner);
27 28 29 30 31
  }

  @override
  void detach() {
    super.detach();
32
    child.detach();
33 34 35
  }

  @override
36
  PipelineOwner? get owner => super.owner as PipelineOwner?;
37 38

  void layout() {
39
    child.layout(BoxConstraints.tight(const Size(500.0, 500.0)));
40 41 42 43
  }
}

void main() {
Ian Hickson's avatar
Ian Hickson committed
44
  test('non-RenderObject roots', () {
45
    RenderPositionedBox child;
46 47
    final RealRoot root = RealRoot(
      child = RenderPositionedBox(
48
        alignment: Alignment.center,
49
        child: RenderSizedBox(const Size(100.0, 100.0)),
50
      ),
51
    );
52
    root.attach(PipelineOwner());
53 54 55 56 57 58 59 60

    child.scheduleInitialLayout();
    root.layout();

    child.markNeedsLayout();
    root.layout();
  });
}