Flutter/Dart: Convert HEX color string to Color?

前端 未结 5 833
醉酒成梦
醉酒成梦 2020-12-10 02:24

Our database has colors saved as a String like \"#AABBCC\" and so I\'m basically looking for a function like this: Color.parseColor(\"#AABBCC\"); f

5条回答
  •  無奈伤痛
    2020-12-10 03:27

    /// 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);
    }
    

提交回复
热议问题