Making.School.Asignment.app/lib/common/config/colorUtils.dart

54 lines
1.6 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* @Author: wangyang 1147192855@qq.com
* @Date: 2022-07-06 14:52:21
* @LastEditors: wangyang 1147192855@qq.com
* @LastEditTime: 2022-07-06 14:57:33
* @FilePath: \marking_app\lib\utils\colorUtils.dart
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
import 'dart:ui';
import 'dart:ui';
import 'package:flutter/material.dart';
//调用的时候需要把hex改一下比如#223344 needs change to 0xFF223344
//即把#换成0xFF即可
MaterialColor createMaterialColor(Color color) {
List strengths = <double>[.05];
Map<int, Color> swatch = {};
final int r = color.red, g = color.green, b = color.blue;
for (int i = 1; i < 10; i++) {
strengths.add(0.1 * i);
}
for (var strength in strengths) {
final double ds = 0.5 - strength;
swatch[(strength * 1000).round()] = Color.fromRGBO(
r + ((ds < 0 ? r : (255 - r)) * ds).round(),
g + ((ds < 0 ? g : (255 - g)) * ds).round(),
b + ((ds < 0 ? b : (255 - b)) * ds).round(),
1,
);
}
return MaterialColor(color.value, swatch);
}
class CommonColors {
static const Color defaultColor = Color.fromRGBO(45, 56, 76, 1);
static Map<String, ColorItem> map = Map.from({
'text_black': ColorItem(
title: 'text_black', color: const Color.fromRGBO(45, 56, 76, 1)),
});
ColorItem getColorItem(String key, {Color color = defaultColor}) {
return map[key] ?? ColorItem(color: color,title: 'default_color');
}
}
class ColorItem {
String title;
Color color;
ColorItem({required this.color, required this.title});
}