• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 'package:flutter/gestures.dart';
7
8class RenderSolidColorBox extends RenderDecoratedBox {
9  RenderSolidColorBox(this.backgroundColor, { this.desiredSize = Size.infinite })
10      : super(decoration: BoxDecoration(color: backgroundColor));
11
12  final Size desiredSize;
13  final Color backgroundColor;
14
15  @override
16  double computeMinIntrinsicWidth(double height) {
17    return desiredSize.width == double.infinity ? 0.0 : desiredSize.width;
18  }
19
20  @override
21  double computeMaxIntrinsicWidth(double height) {
22    return desiredSize.width == double.infinity ? 0.0 : desiredSize.width;
23  }
24
25  @override
26  double computeMinIntrinsicHeight(double width) {
27    return desiredSize.height == double.infinity ? 0.0 : desiredSize.height;
28  }
29
30  @override
31  double computeMaxIntrinsicHeight(double width) {
32    return desiredSize.height == double.infinity ? 0.0 : desiredSize.height;
33  }
34
35  @override
36  void performLayout() {
37    size = constraints.constrain(desiredSize);
38  }
39
40  @override
41  void handleEvent(PointerEvent event, BoxHitTestEntry entry) {
42    if (event is PointerDownEvent) {
43      decoration = const BoxDecoration(color: Color(0xFFFF0000));
44    } else if (event is PointerUpEvent) {
45      decoration = BoxDecoration(color: backgroundColor);
46    }
47  }
48}
49