non_render_object_root_test.dart 1.29 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

import 'rendering_tester.dart';

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

  final RenderObject child;

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

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

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

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

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

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

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

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