raised_button.dart 1.59 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
import 'package:flutter/widgets.dart';
6

7
import 'colors.dart';
8 9
import 'material_button.dart';
import 'theme.dart';
10 11 12

class RaisedButton extends MaterialButton {
  RaisedButton({
13
    Key key,
14 15
    Widget child,
    bool enabled: true,
16
    GestureTapCallback onPressed
17 18 19
  }) : super(key: key,
             child: child,
             enabled: enabled,
20 21 22 23
             onPressed: onPressed) {
    assert(enabled != null);
  }

24
  _RaisedButtonState createState() => new _RaisedButtonState();
25
}
26

27
class _RaisedButtonState extends MaterialButtonState<RaisedButton> {
28 29 30

  int get level => config.enabled ? (highlight ? 2 : 1) : 0;

31 32 33
  Color getColor(BuildContext context) {
    if (config.enabled) {
      switch (Theme.of(context).brightness) {
34 35
        case ThemeBrightness.light:
          if (highlight)
36
            return Colors.grey[350];
37
          else
38
            return Colors.grey[300];
39 40
          break;
        case ThemeBrightness.dark:
41
          Map<int, Color> swatch = Theme.of(context).primarySwatch ?? Colors.blue;
42
          if (highlight)
43
            return swatch[700];
44
          else
45
            return swatch[600];
46 47 48
          break;
      }
    } else {
49 50 51 52 53 54
      switch (Theme.of(context).brightness) {
        case ThemeBrightness.light:
          return Colors.black12;
        case ThemeBrightness.dark:
          return Colors.white12;
      }
55 56 57
    }
  }

58 59 60 61
  ThemeBrightness getColorBrightness(BuildContext context) {
    return Theme.of(context).brightness;
  }

62
}