floating_action_button.dart 1.5 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 6
import 'dart:sky' as sky;

7
import '../painting/shadows.dart';
8
import '../theme2/colors.dart';
9 10
import 'ink_well.dart';
import 'material.dart';
11
import 'wrappers.dart';
12

13 14
// TODO(eseidel): This needs to change based on device size?
// http://www.google.com/design/spec/layout/metrics-keylines.html#metrics-keylines-keylines-spacing
15
const double _kSize = 56.0;
16

17
class FloatingActionButton extends Component {
18 19 20 21

  FloatingActionButton({ Object key, this.content, this.level: 0 })
      : super(key: key);

22 23
  final UINode content;
  final int level;
H
Hixie 已提交
24

25 26 27 28 29 30 31
  UINode build() {
    List<UINode> children = [];

    if (content != null)
      children.add(content);

    return new Material(
32
      content: new CustomPaint(
33
        callback: (sky.Canvas canvas, Size size) {
34
          const double radius = _kSize / 2.0;
35 36 37 38 39 40 41
          sky.Paint paint = new sky.Paint()..color = Red[500];
          var builder = new ShadowDrawLooperBuilder()
            ..addShadow(const sky.Size(0.0, 5.0),
                        const sky.Color(0x77000000),
                        5.0);
          paint.setDrawLooper(builder.build());
          canvas.drawCircle(radius, radius, radius, paint);
42
        },
43 44 45 46 47 48 49 50
        child: new ClipOval(
          child: new Container(
            width: _kSize,
            height: _kSize,
            child: new InkWell(children: children)
          )
        )
      ),
51 52
      level: level);
  }
H
Hixie 已提交
53

54
}