Files
MWClash/lib/common/color.dart

63 lines
1.3 KiB
Dart
Raw Normal View History

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