stack_test.dart 1.3 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1 2 3 4
// 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.

5
import 'package:flutter/rendering.dart';
6 7
import 'package:test/test.dart';

8
import 'rendering_tester.dart';
9 10 11 12

void main() {
  test('Stack can layout with top, right, bottom, left 0.0', () {
    RenderBox size = new RenderConstrainedBox(
13 14
      additionalConstraints: new BoxConstraints.tight(const Size(100.0, 100.0))
    );
15 16 17 18 19

    RenderBox red = new RenderDecoratedBox(
      decoration: new BoxDecoration(
        backgroundColor: const Color(0xFFFF0000)
      ),
20 21
      child: size
    );
22 23 24 25

    RenderBox green = new RenderDecoratedBox(
      decoration: new BoxDecoration(
        backgroundColor: const Color(0xFFFF0000)
26 27
      )
    );
28

29
    RenderBox stack = new RenderStack(children: <RenderBox>[red, green]);
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
    (green.parentData as StackParentData)
      ..top = 0.0
      ..right = 0.0
      ..bottom = 0.0
      ..left = 0.0;

    layout(stack, constraints: const BoxConstraints());

    expect(stack.size.width, equals(100.0));
    expect(stack.size.height, equals(100.0));

    expect(red.size.width, equals(100.0));
    expect(red.size.height, equals(100.0));

    expect(green.size.width, equals(100.0));
    expect(green.size.height, equals(100.0));
  });
}