solid_color_box.dart 1.62 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
import 'package:flutter/gestures.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

class RenderSolidColorBox extends RenderDecoratedBox {
  final Size desiredSize;
  final Color backgroundColor;

  RenderSolidColorBox(Color backgroundColor, { this.desiredSize: Size.infinite })
      : backgroundColor = backgroundColor,
        super(decoration: new BoxDecoration(backgroundColor: backgroundColor));

  double getMinIntrinsicWidth(BoxConstraints constraints) {
    return constraints.constrainHeight(
      this.desiredSize == Size.infinite ? 0.0 : desiredSize.width
    );
  }

  double getMaxIntrinsicWidth(BoxConstraints constraints) {
    return constraints.constrainWidth(
      this.desiredSize == Size.infinite ? 0.0 : desiredSize.width
    );
  }

  double getMinIntrinsicHeight(BoxConstraints constraints) {
    return constraints.constrainHeight(
      this.desiredSize == Size.infinite ? 0.0 : desiredSize.height
    );
  }

  double getMaxIntrinsicHeight(BoxConstraints constraints) {
    return constraints.constrainHeight(
      this.desiredSize == Size.infinite ? 0.0 : desiredSize.height
    );
  }

  void performLayout() {
    size = constraints.constrain(desiredSize);
  }

44
  void handleEvent(InputEvent event, BoxHitTestEntry entry) {
Adam Barth's avatar
Adam Barth committed
45
    if (event.type == 'pointerdown')
46
      decoration = new BoxDecoration(backgroundColor: const Color(0xFFFF0000));
Adam Barth's avatar
Adam Barth committed
47
    else if (event.type == 'pointerup')
48 49 50
      decoration = new BoxDecoration(backgroundColor: backgroundColor);
  }
}