Forked from moritzmorgenroth/material_color_generator.dart
Created
August 5, 2021 13:35
-
-
Save moneer-muntazah/0e2dfc10af0da5aacbcdedb7c6f0d00a to your computer and use it in GitHub Desktop.
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 'dart:math'; | |
import 'package:flutter/material.dart'; | |
MaterialColor generateMaterialColor(Color color) { | |
return MaterialColor(color.value, { | |
50: tintColor(color, 0.5), | |
100: tintColor(color, 0.4), | |
200: tintColor(color, 0.3), | |
300: tintColor(color, 0.2), | |
400: tintColor(color, 0.1), | |
500: tintColor(color, 0), | |
600: tintColor(color, -0.1), | |
700: tintColor(color, -0.2), | |
800: tintColor(color, -0.3), | |
900: tintColor(color, -0.4), | |
}); | |
} | |
int tintValue(int value, double factor) => | |
max(0, min((value + ((255 - value) * factor)).round(), 255)); | |
Color tintColor(Color color, double factor) => Color.fromRGBO( | |
tintValue(color.red, factor), | |
tintValue(color.green, factor), | |
tintValue(color.blue, factor), | |
1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment