justify_content.dart 1.61 KB
Newer Older
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 'lib/solid_color_box.dart';
8 9 10 11 12 13 14 15 16

const TextStyle style = const TextStyle(color: const Color(0xFF000000));

// Attempts to draw
// http://www.w3.org/TR/2015/WD-css-flexbox-1-20150514/images/flex-pack.svg
void main() {
  var table = new RenderFlex(direction: FlexDirection.vertical);

  void addRow(FlexJustifyContent justify) {
Eric Seidel's avatar
Eric Seidel committed
17
    RenderParagraph paragraph = new RenderParagraph(new StyledTextSpan(style, [new PlainTextSpan("${justify}")]));
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
    table.add(new RenderPadding(child: paragraph, padding: new EdgeDims.only(top: 20.0)));
    var row = new RenderFlex(direction: FlexDirection.horizontal);
    row.add(new RenderSolidColorBox(const Color(0xFFFFCCCC), desiredSize: new Size(80.0, 60.0)));
    row.add(new RenderSolidColorBox(const Color(0xFFCCFFCC), desiredSize: new Size(64.0, 60.0)));
    row.add(new RenderSolidColorBox(const Color(0xFFCCCCFF), desiredSize: new Size(160.0, 60.0)));
    row.justifyContent = justify;
    table.add(row);
    row.parentData.flex = 1;
  }

  addRow(FlexJustifyContent.start);
  addRow(FlexJustifyContent.end);
  addRow(FlexJustifyContent.center);
  addRow(FlexJustifyContent.spaceBetween);
  addRow(FlexJustifyContent.spaceAround);

  RenderDecoratedBox root = new RenderDecoratedBox(
    decoration: new BoxDecoration(backgroundColor: const Color(0xFFFFFFFF)),
    child: new RenderPadding(child: table, padding: new EdgeDims.symmetric(vertical: 50.0))
  );

39
  new FlutterBinding(root: root);
40
}