Skip to content

Instantly share code, notes, and snippets.

@GAM3RG33K
Created December 3, 2021 12:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GAM3RG33K/f13d4dd5a0ef096d7b52498feaee00e7 to your computer and use it in GitHub Desktop.
Save GAM3RG33K/f13d4dd5a0ef096d7b52498feaee00e7 to your computer and use it in GitHub Desktop.
Find Brightness from the image provider
import 'package:flutter/material.dart';
// Add this to pubspec.yaml of your flutter project
// palette_generator: ^0.3.2
// get packages to download the package
import 'package:palette_generator/palette_generator.dart';
/// This method will find & return the most dominant color from the image
///
/// i.e. the most effective color or an average color from the provided image
Future<Color?> getDominantColor(ImageProvider imageProvider) async {
final _pallet = await PaletteGenerator.fromImageProvider(imageProvider);
final _dominantColor = _pallet.dominantColor?.color;
return _dominantColor;
}
/// Get Brightness from color
Brightness brightnessFromColor(Color color) {
final luminance = color.computeLuminance();
return luminance > 0.5 ? Brightness.light : Brightness.dark;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment