Yassal Ahmad
Yassal Ahmad

Reputation: 21

How to pick color from image in Flutter?

I am trying to get color from image in Flutter.

I'm trying this package but it's not working.

Upvotes: 1

Views: 2535

Answers (1)

CharlyKeleb
CharlyKeleb

Reputation: 754

You can do this with the paletter_generator package

 var paletteGenerator;
    var itemBackgroundColor;

    Future<PaletteGenerator> _updatePaletteGenerator() async {
      paletteGenerator = await PaletteGenerator.fromImageProvider(
        Image.asset(product.image).image,
      );
      return paletteGenerator;
    }

//Then return a Future Builder

 return FutureBuilder<PaletteGenerator>(
      future: _updatePaletteGenerator(), // async work
      builder:
          (BuildContext context, AsyncSnapshot<PaletteGenerator> snapshot) {
  itemBackgroundColor = snapshot.data.dominantColor.color;
   },
 );

Upvotes: 5

Related Questions