Home > Software design >  is there any alternative for Hex code error in flutter?
is there any alternative for Hex code error in flutter?

Time:05-04

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

CodePudding user response:

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')
)
  • Related