Reputation: 21
I am trying to get color from image in Flutter.
I'm trying this package but it's not working.
Upvotes: 1
Views: 2535
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