flutter 自定义渐变色按钮 16进制颜色转换

2020-09-02  本文已影响0人  A然后呢
 Container(
           width: 300,
           height: 50,
           decoration: BoxDecoration(
             border: Border.all(color: Colors.blue, width: 1.0),  //边框线
             borderRadius: BorderRadius.circular(8.0),   //圆角
             gradient: LinearGradient(colors: <Color>[   //背景渐变
               Colors.blue[200],
               Colors.blue,
             ]),
           ),
            //用RaisedButton按钮的时候需要设置下面三个属性
            //   color: Colors.transparent, // 设为透明色
           ///elevation: 0, // 正常时阴影隐藏
           ///highlightElevation: 0, // 点击时阴影隐藏
           child:FlatButton(
             child: Text(
               "提交",
               style: TextStyle(fontSize: 20, color: Colors.white),
             ),
             onPressed: () {},
           ),
         ),

16进制字符串颜色

extension HexColor on Color {
  /// String is in the format "aabbcc" or "ffaabbcc" with an optional leading "#".
  static Color fromHex(String hexString) {
    final buffer = StringBuffer();
    if (hexString.length == 6 || hexString.length == 7) buffer.write('ff');
    buffer.write(hexString.replaceFirst('#', ''));
    return Color(int.parse(buffer.toString(), radix: 16));
  }

  /// Prefixes a hash sign if [leadingHashSign] is set to `true` (default is `true`).
  String toHex({bool leadingHashSign = true}) => '${leadingHashSign ? '#' : ''}'
      '${alpha.toRadixString(16).padLeft(2, '0')}'
      '${red.toRadixString(16).padLeft(2, '0')}'
      '${green.toRadixString(16).padLeft(2, '0')}'
      '${blue.toRadixString(16).padLeft(2, '0')}';
  


//使用
  HexColor.fromHex("#001122"),
上一篇下一篇

猜你喜欢

热点阅读