Skip to content

Your app looks AI-generated. Vincent Van Gogh noticed. An agent skill that finds and fixes AI-looking UI and UX in mobile apps, web apps, and websites.

fix(detect): read Flutter Color.fromARGB and Color.fromRGBO stops in slop-gradient (#161) (#168)

Pranav Arya746eadbca811
diff --git a/skills/unslop-anything/scripts/detect.js b/skills/unslop-anything/scripts/detect.js
index cc2c6ba..4d810d9 100644
--- a/skills/unslop-anything/scripts/detect.js
+++ b/skills/unslop-anything/scripts/detect.js
@@ -118,6 +118,37 @@ function cssFunctionColors(snippet) {
return out;
}
+// Flutter's Color.fromARGB(a, r, g, b) and Color.fromRGBO(r, g, b, opacity) in a
+// snippet, as uppercase hex, so they go through the same checks as
+// Color(0xFFRRGGBB). Alpha and opacity are dropped, as they are for hex, and
+// may be any expression. A channel that is not a literal (a variable, an
+// expression) skips the color. Flutter keeps the low eight bits of a channel.
+function flutterColors(snippet) {
+ const out = [];
+ const re = /\bColor\.from(ARGB|RGBO)\(/g;
+ let m;
+ while ((m = re.exec(snippet))) {
+ const open = m.index + m[0].length - 1;
+ const close = closeOf(snippet, open) - 1;
+ // Split on top-level commas only: the opacity may be a call of its own.
+ const args = [];
+ let depth = 0;
+ let start = open + 1;
+ for (let i = start; i <= close; i++) {
+ const c = snippet[i];
+ if ("([{".includes(c)) depth++;
+ else if (i === close || (c === "," && depth === 0)) {
+ args.push(snippet.slice(start, i).trim());
+ start = i + 1;
+ } else if (")]}".includes(c)) depth--;
+ }
+ const rgb = m[1] === "ARGB" ? args.slice(1, 4) : args.slice(0, 3);
+ if (args.length < 4 || !rgb.every((c) => /^(?:0x[0-9a-fA-F]+|\d+)$/.test(c))) continue;
+ out.push(rgb.map((c) => (Number(c) & 0xff).toString(16).padStart(2, "0")).join("").toUpperCase());
+ }
+ return out;
+}
+
// The purple, indigo, violet and hot-pink band that default AI palettes live in.
function isSlopHue(hex) {
const { h, s, l } = hexToHsl(hex);
@@ -610,7 +641,7 @@ const rules = [
if (/^\s*(?:import|export\s+\{|from)\b/.test(code.slice(lineStart, m.index))) continue;
// Only the gradient's own stops count, not whatever follows it.
const stops = gradientScope(code, m.index, m[0]);
- if ([...hexColors(stops, stack), ...cssFunctionColors(stops)].some(isSlopHue) || SLOP_COLOR_NAME.test(stops)) hits.push(m.index);
+ if ([...hexColors(stops, stack), ...cssFunctionColors(stops), ...flutterColors(stops)].some(isSlopHue) || SLOP_COLOR_NAME.test(stops)) hits.push(m.index);
}
// Tailwind: bg-gradient-to-r from-violet-600 to-fuchsia-500
for (const m of matches(/["'`][^"'`\n]*\bbg-(?:gradient|linear|radial|conic)-[^"'`\n]*["'`]/, code)) {
diff --git a/test/detect.test.js b/test/detect.test.js
index 8e1e6b9..c26b951 100644
--- a/test/detect.test.js
+++ b/test/detect.test.js
@@ -1585,3 +1585,32 @@ test("slop-gradient reads rgb() and hsl() stops", () => {
];
for (const src of quiet) assert.deepStrictEqual(rulesFor(src), [], src);
});
+
+test("slop-gradient reads Flutter Color.fromARGB and Color.fromRGBO stops (issue #161)", () => {
+ const rulesFor = (src) => scanSource(src, "hero.dart").map((f) => f.rule).filter((r) => r === "slop-gradient");
+ const gradient = (stops) => `Container(decoration: BoxDecoration(gradient: LinearGradient(colors: [${stops}])))\n`;
+ const flagged = [
+ "Color.fromARGB(255, 124, 58, 237), Color.fromARGB(255, 219, 39, 119)",
+ "Color.fromRGBO(124, 58, 237, 1), Color.fromRGBO(219, 39, 119, 1)",
+ "const Color.fromRGBO(124, 58, 237, 0.8), Colors.white",
+ // Hex literals for the channels, and a trailing comma.
+ "Color.fromARGB(0xFF, 0x7C, 0x3A, 0xED,), Colors.white",
+ "Color.fromARGB(\n 255,\n 124,\n 58,\n 237,\n ), Colors.white",
+ // The alpha or opacity can be any expression; only the channels are read.
+ "Color.fromRGBO(124, 58, 237, animation.value.clamp(0.0, 1.0)), Colors.white",
+ "Color.fromARGB((255 * t).round(), 124, 58, 237), Colors.white",
+ ];
+ for (const stops of flagged) assert.deepStrictEqual(rulesFor(gradient(stops)), ["slop-gradient"], stops);
+ const quiet = [
+ "Color.fromARGB(255, 14, 165, 233), Color.fromARGB(255, 34, 197, 94)",
+ "Color.fromRGBO(14, 165, 233, 1), Color.fromRGBO(34, 197, 94, 1)",
+ // 255 here is the alpha, not a channel: (0, 0, 0) is black.
+ "Color.fromARGB(255, 0, 0, 0), Color.fromARGB(255, 255, 255, 255)",
+ // A channel that is not a literal cannot be read.
+ "Color.fromARGB(255, r, g, b), Color.fromRGBO(red, 58, 237, 1)",
+ "Color.fromRGBO(shade(124), 58, 237, 1), Colors.white",
+ // Flutter keeps the low eight bits of a channel: 256 is 0, so this is (0, 58, 237), a blue.
+ "Color.fromARGB(255, 256, 58, 237), Colors.white",
+ ];
+ for (const stops of quiet) assert.deepStrictEqual(rulesFor(gradient(stops)), [], stops);
+});