title: Flutter / dart const Color
body: <p>Im trying to convert a hex color to a const Color to be used in MaterialColor.
  Im not sure how to setup the factory, so the class can return a const Color.
  My class:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>class HtmlColor extends Color {
  
    factory HtmlColor(String hexCode, int amt) {
      if (hexCode[0] == "#") {
        hexCode = hexCode.substring(1, 7);
      }
      var num = int.parse(hexCode, radix: 16);
      var r = (num &gt;&gt; 16) + amt;
      if (r &gt; 255) r = 255;
      else if  (r &lt; 0) r = 0;
      var b = ((num &gt;&gt; 8) &amp; 0x00FF) + amt;
      if (b &gt; 255) b = 255;
      else if  (b &lt; 0) b = 0;
      var g = (num &amp; 0x0000FF) + amt;
      if (g &gt; 255) g = 255;
      else if (g &lt; 0) g = 0;
      return new HtmlColor.fromValue((g | (b &lt;&lt; 8) | (r &lt;&lt; 16)) + 0xFF000000);
    }
  
    const HtmlColor.fromValue(int value) : super(value);
  
  }</code></pre>
  </div>
  </div>
  </p>