non_render_object_root_test.dart 1.31 KB
Newer Older
1 2 3 4 5
// Copyright 2015 The Chromium 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 'package:flutter/material.dart';
6
import 'package:flutter/foundation.dart';
7 8 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 42 43 44 45 46
import 'package:flutter/rendering.dart';
import 'package:test/test.dart';

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() {
    child?.layout(new BoxConstraints.tight(const Size(500.0, 500.0)));
  }
}

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

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

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