string - flutter/Dart : Convert HEX color string to Color?

标签 string colors dart flutter

我们的数据库将颜色保存为像“#AABBCC”这样的String,所以我基本上在寻找这样的函数:Color.parseColor("#AABBCC"); Flutter

Color 类需要这样的 Color(0xFF42A5F5) 所以我需要将 "#AABBCC" 转换为 0xFFAABBCC

最佳答案

/// Construct a color from a hex code string, of the format #RRGGBB.
Color hexToColor(String code) {
  return new Color(int.parse(code.substring(1, 7), radix: 16) + 0xFF000000);
}

关于string - flutter/Dart : Convert HEX color string to Color?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50381968/

相关文章:

android - 布局看起来不同?

java - 以 "?"作为 clown 的字符串搜索?

colors - Colorjack - 你如何使用它?

dart - 使函数返回自定义流

multithreading - 为什么在这段代码中,await 不会阻塞 ui

c++ - C++ 中的排序字符串不能正确比较?

java - 在 Java 中解析 JavaScript 代码以检索变量的名称

sorting - 按 HSV/HSB 对颜色列表进行排序

java - 样式中定义的 textColor 未应用于按钮文本

mysql - 如何将 mysql 数据库与 Dart 连接?