2024-04-30 23:38:49 +08:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
|
|
extension ColorExtension on Color {
|
2024-12-09 01:40:39 +08:00
|
|
|
|
|
|
|
|
Color get toLight {
|
|
|
|
|
return withOpacity(0.8);
|
2024-04-30 23:38:49 +08:00
|
|
|
}
|
|
|
|
|
|
2024-12-09 01:40:39 +08:00
|
|
|
Color get toLighter {
|
|
|
|
|
return withOpacity(0.6);
|
2024-04-30 23:38:49 +08:00
|
|
|
}
|
|
|
|
|
|
2024-12-09 01:40:39 +08:00
|
|
|
Color get toSoft {
|
2025-02-09 18:39:38 +08:00
|
|
|
return withOpacity(0.15);
|
2024-04-30 23:38:49 +08:00
|
|
|
}
|
|
|
|
|
|
2024-12-09 01:40:39 +08:00
|
|
|
Color get toLittle {
|
2024-04-30 23:38:49 +08:00
|
|
|
return withOpacity(0.03);
|
|
|
|
|
}
|
2024-08-04 08:21:14 +08:00
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
2024-12-09 01:40:39 +08:00
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
)!;
|
|
|
|
|
}
|
2024-08-01 23:51:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extension ColorSchemeExtension on ColorScheme {
|
|
|
|
|
ColorScheme toPrueBlack(bool isPrueBlack) => isPrueBlack
|
|
|
|
|
? copyWith(
|
|
|
|
|
surface: Colors.black,
|
2024-12-09 01:40:39 +08:00
|
|
|
surfaceContainer: surfaceContainer.darken(
|
|
|
|
|
0.05,
|
|
|
|
|
),
|
2024-08-01 23:51:00 +08:00
|
|
|
)
|
|
|
|
|
: this;
|
|
|
|
|
}
|