import 'package:flutter/material.dart'; extension ColorOpacityExtension on Color { Color withOpacitySafe(double opacity) { final int alpha = (opacity * 255).round().clamp(0, 255); return Color.fromARGB( alpha, // alpha value should be an int this.r.toInt(), // red channel this.g.toInt(), // green channel this.b.toInt(), // blue channel ); } }