Flutter十六进制颜色转换成颜色对象
十六进制颜色值格式一般如:#ff0000,以#开头,后面跟着6个十六进制字符。
而flutter中不能直接使用此类形式的颜色值,所以必须要转换为flutter颜色对象。
ColorhexToColor(Strings){
//如果传入的十六进制颜色值不符合要求,返回默认值
if(s==null||s.length!=7||int.tryParse(s.substring(1,7),radix:16)==null){
s='#999999';
}
returnnewColor(int.parse(s.substring(1,7),radix:16)+0xFF000000);
}
参考地址:
- https://stackoverflow.com/questions/50381968/flutter-dart-convert-hex-color-string-to-color/50382196
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短