从颤动中的父色生成自定义颜色阴影 [英] Generate custom color shades from parent color in flutter

查看:57
本文介绍了从颤动中的父色生成自定义颜色阴影的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要找到一种更好的方法来根据主题自定义颜色生成阴影颜色.到目前为止,我找到了一种方法,可以通过以下方法减少给定颜色的不透明度来做到这一点.因此我可以在此功能中强调给定颜色的颜色和褪色.

I needs to find a better approach to generate shade colors from a given custom color for theming purposes. So far I found a way to do this by reducing opacity of the given color as below. so I can accent Color color and faded color of given color to this function.

import 'package:flutter/material.dart';

class AppColors {
  Color accentColor;
  Color fadedColor;

  AppColors(this.accentColor, this.fadedColor);
}

AppColors getAppColors(String color) {
  int budgetAccentcolor = int.parse('0xff' + color);
  int budgetFadedColor = int.parse('0x26' + color);

  return AppColors(Color(budgetAccentcolor), Color(budgetFadedColor));
}

但是由于我减少了颜色的不透明度,它显示了小部件下面的情况,例如使用 SliverAppBar 时.

But because of I'm reducing opacity of the color It shows what's going under the widgets like when using SliverAppBar.

反正有没有得到十六进制颜色的褪色值?

Is there anyway to get the faded value of a Hex color?

推荐答案

最后从我这样称呼这种功能.

backgroundColor: lighten(hexToColor("f98b5")),

这篇关于从颤动中的父色生成自定义颜色阴影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆