ColorsUtils.dart 409 B

12345678910111213141516
  1. import 'dart:ui';
  2. class ColorsUtil {
  3. /// 十六进制颜色,
  4. /// hex, 十六进制值,例如:0xffffff,
  5. /// alpha, 透明度 [0.0,1.0]
  6. static Color hexColor(int hex, {double alpha = 1}) {
  7. if (alpha < 0) {
  8. alpha = 0;
  9. } else if (alpha > 1) {
  10. alpha = 1;
  11. }
  12. return Color.fromRGBO((hex & 0xFF0000) >> 16, (hex & 0x00FF00) >> 8,
  13. (hex & 0x0000FF) >> 0, alpha);
  14. }
  15. }