Created
December 3, 2021 12:18
-
-
Save GAM3RG33K/f13d4dd5a0ef096d7b52498feaee00e7 to your computer and use it in GitHub Desktop.
Find Brightness from the image provider
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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