rgba method

Color rgba(
  1. dynamic r,
  2. [dynamic g,
  3. dynamic b,
  4. dynamic a]
)

Creates a transparent color object from decimal red, green, blue and alpha (RGBA) values.

Parameters: red: An integer 0-255 or percentage 0-100%. green: An integer 0-255 or percentage 0-100%. blue: An integer 0-255 or percentage 0-100%. alpha: A number 0-1 or percentage 0-100%. Returns: color Example: rgba(90, 129, 32, 0.5) Output: rgba(90, 129, 32, 0.5)

Implementation

// r, g, b, a are (Dimension | num). r could be Color.
Color rgba(dynamic r, [dynamic g, dynamic b, dynamic a]) {
  try {
    if (r is Color) {
      final alpha = g != null ? number(g) : r.alpha;
      return Color.fromList(r.rgb, alpha, 'rgba');
    }

    final rgb =
        <dynamic>[r, g, b].map((dynamic c) => scaled(c, 255)).toList();
    return Color.fromList(rgb, number(a), 'rgba');
  } catch (e) {
    return null;
  }

// 3.8.0 20180729
//  rgba: function (r, g, b, a) {
//      try {
//          if (r instanceof Color) {
//              if (g) {
//                  a = number(g);
//              } else {
//                  a = r.alpha;
//              }
//              return new Color(r.rgb, a, 'rgba');
//          }
//          var rgb = [r, g, b].map(function (c) { return scaled(c, 255); });
//          a = number(a);
//          return new Color(rgb, a, 'rgba');
//      }
//      catch (e) {}
//  },
}