floating_action_button.dart 2.12 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 7 8 9 10 11 12
import 'package:sky/src/widgets/basic.dart';
import 'package:sky/src/widgets/button_base.dart';
import 'package:sky/src/widgets/framework.dart';
import 'package:sky/src/widgets/gesture_detector.dart';
import 'package:sky/src/widgets/icon.dart';
import 'package:sky/src/widgets/ink_well.dart';
import 'package:sky/src/widgets/material.dart';
import 'package:sky/src/widgets/theme.dart';
13 14 15 16 17 18 19 20

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

class FloatingActionButton extends ButtonBase {

  FloatingActionButton({
21
    Key key,
22 23 24 25 26 27 28 29 30
    this.child,
    this.backgroundColor,
    this.onPressed
  }) : super(key: key);

  Widget child;
  Color backgroundColor;
  Function onPressed;

31 32
  void syncConstructorArguments(FloatingActionButton source) {
    super.syncConstructorArguments(source);
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
    child = source.child;
    backgroundColor = source.backgroundColor;
    onPressed = source.onPressed;
  }

  Widget buildContent() {
    IconThemeColor iconThemeColor = IconThemeColor.white;
    Color materialColor = backgroundColor;
    if (materialColor == null) {
      ThemeData themeData = Theme.of(this);
      materialColor = themeData.accentColor;
      iconThemeColor = themeData.accentColorBrightness == ThemeBrightness.dark ? IconThemeColor.white : IconThemeColor.black;
    }

    return new Material(
      color: materialColor,
      type: MaterialType.circle,
      level: highlight ? 3 : 2,
      child: new ClipOval(
52 53
        child: new GestureDetector(
          onTap: onPressed,
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
          child: new Container(
            width: _kSize,
            height: _kSize,
            child: new InkWell(
              child: new Center(
                child: new IconTheme(
                  data: new IconThemeData(color: iconThemeColor),
                  child: child
                )
              )
            )
          )
        )
      )
    );
  }

}