material_button.dart 1.62 KB
Newer Older
1 2 3 4 5 6
// 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.

import 'package:sky/widgets/basic.dart';
import 'package:sky/widgets/button_base.dart';
7
import 'package:sky/widgets/framework.dart';
8
import 'package:sky/widgets/gesture_detector.dart';
9 10 11 12 13 14 15
import 'package:sky/widgets/ink_well.dart';
import 'package:sky/widgets/material.dart';

// Rather than using this class directly, please use FlatButton or RaisedButton.
abstract class MaterialButton extends ButtonBase {

  MaterialButton({
16
    Key key,
17 18 19 20 21 22 23 24 25
    this.child,
    this.enabled: true,
    this.onPressed
  }) : super(key: key);

  Widget child;
  bool enabled;
  Function onPressed;

26
  void syncConstructorArguments(MaterialButton source) {
27 28 29
    child = source.child;
    enabled = source.enabled;
    onPressed = source.onPressed;
30
    super.syncConstructorArguments(source);
31 32 33 34 35 36 37 38 39 40
  }

  Color get color;
  int get level;

  Widget buildContent() {
    Widget contents = new Container(
      padding: new EdgeDims.symmetric(horizontal: 8.0),
      child: new Center(child: child) // TODO(ianh): figure out a way to compell the child to have gray text when disabled...
    );
41 42
    return new GestureDetector(
      onTap: enabled ? onPressed : null,
43 44 45 46 47 48 49 50 51 52
      child: new Container(
        height: 36.0,
        constraints: new BoxConstraints(minWidth: 88.0),
        margin: new EdgeDims.all(8.0),
        child: new Material(
          type: MaterialType.button,
          child: enabled ? new InkWell(child: contents) : contents,
          level: level,
          color: color
        )
53
      )
54 55 56 57
    );
  }

}