1// Copyright 2015 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5import 'package:flutter/rendering.dart'; 6import '../flutter_test_alternative.dart'; 7 8import 'rendering_tester.dart'; 9 10void main() { 11 test('RenderPositionedBox expands', () { 12 final RenderConstrainedBox sizer = RenderConstrainedBox( 13 additionalConstraints: BoxConstraints.tight(const Size(100.0, 100.0)), 14 child: RenderDecoratedBox(decoration: const BoxDecoration()), 15 ); 16 final RenderPositionedBox positioner = RenderPositionedBox(child: sizer); 17 layout(positioner, constraints: BoxConstraints.loose(const Size(200.0, 200.0))); 18 19 expect(positioner.size.width, equals(200.0), reason: 'positioner width'); 20 expect(positioner.size.height, equals(200.0), reason: 'positioner height'); 21 }); 22 23 test('RenderPositionedBox shrink wraps', () { 24 final RenderConstrainedBox sizer = RenderConstrainedBox( 25 additionalConstraints: BoxConstraints.tight(const Size(100.0, 100.0)), 26 child: RenderDecoratedBox(decoration: const BoxDecoration()), 27 ); 28 final RenderPositionedBox positioner = RenderPositionedBox(child: sizer, widthFactor: 1.0); 29 layout(positioner, constraints: BoxConstraints.loose(const Size(200.0, 200.0))); 30 31 expect(positioner.size.width, equals(100.0), reason: 'positioner width'); 32 expect(positioner.size.height, equals(200.0), reason: 'positioner height'); 33 34 positioner.widthFactor = null; 35 positioner.heightFactor = 1.0; 36 pumpFrame(); 37 38 expect(positioner.size.width, equals(200.0), reason: 'positioner width'); 39 expect(positioner.size.height, equals(100.0), reason: 'positioner height'); 40 41 positioner.widthFactor = 1.0; 42 pumpFrame(); 43 44 expect(positioner.size.width, equals(100.0), reason: 'positioner width'); 45 expect(positioner.size.height, equals(100.0), reason: 'positioner height'); 46 }); 47 48 test('RenderPositionedBox width and height factors', () { 49 final RenderConstrainedBox sizer = RenderConstrainedBox( 50 additionalConstraints: BoxConstraints.tight(const Size(100.0, 100.0)), 51 child: RenderDecoratedBox(decoration: const BoxDecoration()), 52 ); 53 final RenderPositionedBox positioner = RenderPositionedBox(child: sizer, widthFactor: 1.0, heightFactor: 0.0); 54 layout(positioner, constraints: BoxConstraints.loose(const Size(200.0, 200.0))); 55 56 expect(positioner.size.width, equals(100.0)); 57 expect(positioner.size.height, equals(0.0)); 58 59 positioner.widthFactor = 0.5; 60 positioner.heightFactor = 0.5; 61 pumpFrame(); 62 63 expect(positioner.size.width, equals(50.0)); 64 expect(positioner.size.height, equals(50.0)); 65 66 positioner.widthFactor = null; 67 positioner.heightFactor = null; 68 pumpFrame(); 69 70 expect(positioner.size.width, equals(200.0)); 71 expect(positioner.size.height, equals(200.0)); 72 }, skip: isBrowser); 73} 74