non_render_object_root_test.dart 1.3 KB
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/material.dart';
6
import 'package:flutter/foundation.dart';
7
import 'package:flutter/rendering.dart';
8
import '../flutter_test_alternative.dart';
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41

import 'rendering_tester.dart';

class RealRoot extends AbstractNode {
  RealRoot(this.child) {
    if (child != null)
      adoptChild(child);
  }

  final RenderObject child;

  @override
  void redepthChildren() {
    if (child != null)
      redepthChild(child);
  }

  @override
  void attach(Object owner) {
    super.attach(owner);
    child?.attach(owner);
  }

  @override
  void detach() {
    super.detach();
    child?.detach();
  }

  @override
  PipelineOwner get owner => super.owner;

  void layout() {
42
    child?.layout(BoxConstraints.tight(const Size(500.0, 500.0)));
43 44 45 46
  }
}

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

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

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