63 lines
1.3 KiB
Dart
63 lines
1.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
extension ColorExtension on Color {
|
|
|
|
Color get toLight {
|
|
return withOpacity(0.8);
|
|
}
|
|
|
|
Color get toLighter {
|
|
return withOpacity(0.6);
|
|
}
|
|
|
|
Color get toSoft {
|
|
return withOpacity(0.12);
|
|
}
|
|
|
|
Color get toLittle {
|
|
return withOpacity(0.03);
|
|
}
|
|
|
|
Color darken([double amount = .1]) {
|
|
assert(amount >= 0 && amount <= 1);
|
|
final hsl = HSLColor.fromColor(this);
|
|
final hslDark = hsl.withLightness((hsl.lightness - amount).clamp(0.0, 1.0));
|
|
return hslDark.toColor();
|
|
}
|
|
|
|
Color blendDarken(
|
|
BuildContext context, {
|
|
double factor = 0.1,
|
|
}) {
|
|
final brightness = Theme.of(context).brightness;
|
|
return Color.lerp(
|
|
this,
|
|
brightness == Brightness.dark ? Colors.white : Colors.black,
|
|
factor,
|
|
)!;
|
|
}
|
|
|
|
Color blendLighten(
|
|
BuildContext context, {
|
|
double factor = 0.1,
|
|
}) {
|
|
final brightness = Theme.of(context).brightness;
|
|
return Color.lerp(
|
|
this,
|
|
brightness == Brightness.dark ? Colors.black : Colors.white,
|
|
factor,
|
|
)!;
|
|
}
|
|
}
|
|
|
|
extension ColorSchemeExtension on ColorScheme {
|
|
ColorScheme toPrueBlack(bool isPrueBlack) => isPrueBlack
|
|
? copyWith(
|
|
surface: Colors.black,
|
|
surfaceContainer: surfaceContainer.darken(
|
|
0.05,
|
|
),
|
|
)
|
|
: this;
|
|
}
|