美文网首页
flutter 自定义渐变色按钮 16进制颜色转换

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

作者: A然后呢 | 来源:发表于2020-09-02 17:00 被阅读0次
 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"),

相关文章

网友评论

      本文标题:flutter 自定义渐变色按钮 16进制颜色转换

      本文链接:https://www.haomeiwen.com/subject/pxturktx.html