checkbox.dart 1.7 KB
Newer Older
1 2 3 4 5 6 7 8
part of widgets;

class Checkbox extends ButtonBase {

  bool checked;
  ValueChanged onChanged;

  static Style _style = new Style('''
9
    transform: translateX(0);
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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
    display: flex;
    justify-content: center;
    align-items: center;
    -webkit-user-select: none;
    cursor: pointer;
    width: 30px;
    height: 30px;'''
  );

  static Style _containerStyle = new Style('''
    border: solid 2px;
    border-color: rgba(90, 90, 90, 0.25);
    width: 10px;
    height: 10px;'''
  );

  static Style _containerHighlightStyle = new Style('''
    border: solid 2px;
    border-color: rgba(90, 90, 90, 0.25);
    width: 10px;
    height: 10px;
    border-radius: 10px;
    background-color: orange;
    border-color: orange;'''
  );

  static Style _uncheckedStyle = new Style('''
    top: 0px;
    left: 0px;'''
  );

  static Style _checkedStyle = new Style('''
    top: 0px;
    left: 0px;
    transform: translate(2px, -15px) rotate(45deg);
    width: 10px;
    height: 20px;
    border-style: solid;
    border-top: none;
    border-left: none;
    border-right-width: 2px;
    border-bottom-width: 2px;
    border-color: #0f9d58;'''
  );

  Checkbox({ Object key, this.onChanged, this.checked }) : super(key: key);

  Node render() {
    return new Container(
      style: _style,
      children: [
61
        super.render(),
62 63 64 65 66 67 68 69 70
        new Container(
          style: _highlight ? _containerHighlightStyle : _containerStyle,
          children: [
            new Container(
              style: checked ? _checkedStyle : _uncheckedStyle
            )
          ]
        )
      ]
71
    )..events.listen('click', _handleClick);
72 73 74 75 76 77
  }

  void _handleClick(sky.Event e) {
    onChanged(!checked);
  }
}