'is there any alternative for Hex code error in flutter?
import 'package:flutter/material.dart'; import 'package:hexcolor/hexcolor.dart'; i have imported "Hexcolor" package and i got an error Target of URI doesn't exist: 'package:hexcolor/hexcolor.dart'.
and this is the output :enter image description here
can someone help me
Solution 1:[1]
You can write this much code and get rid of the hex color package.
Add this code to utils or a similar directory.
class HexColor extends Color {
static int _getColorFromHex(String hexColor) {
hexColor = hexColor.toUpperCase().replaceAll('#', '');
if (hexColor.length == 6) {
hexColor = 'FF' + hexColor;
}
return int.parse(hexColor, radix: 16);
}
HexColor(final String hexColor) : super(_getColorFromHex(hexColor));
}
Usage
Container(
height: 100,
width: 100,
color: HexColor('#00FF00')
)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | nitishk72 |
