• Flutter错误:将shade应用于Flutter颜色变量


    问题描述:

            我已经定义了一个保存颜色值的变量,当我设置屏幕时,我总是改变这个颜色。我想在我的应用程序中将这种颜色用作普通颜色和 shade100。但是,我的代码在下面给出了错误。

    1. late Color objeColor;
    2. objeColor = Colors.orange;
    3. Container(
    4. decoration: BoxDecoration(
    5. shape: BoxShape.circle,
    6. color: objeColor, // there is no error *******
    7. ),),
    8. Container(
    9. decoration: BoxDecoration(
    10. shape: BoxShape.circle,
    11. color: objeColor.shade100, // there is error *******
    12. ),),

    错误:

    The getter 'shade100' isn't defined for the type 'Color'. Try importing the library that defines 'shade100', correcting the name to the name of an existing getter, or defining a getter or field named 'shade100'

    解决思路一:

    您不能在小部件树中再次更改颜色的阴影。虽然你有很多其他方法来操纵颜色。例如,objeColor.withAlpha(75)看起来完全一样Colors.orange.shade100,所以它完全符合您的需求。在其他用例中,您可以尝试使用其他方法,例如withOpacity().

    解决思路二:

    shade100是 MaterialColor. 你可以做

    1. late MaterialColor objeColor;
    2. ...
    3. color: objeColor.shade100

    如果您觉得有帮助,可以关注公众号——定期发布有用的资讯和资源​

  • 相关阅读:
    Java数据结构与算法(一)
    执行npm 命令出现等待 sill idealTree buildDeps 解决办法
    html css面试题
    Vue开发历程---音乐播放器
    模拟实现stl库中的list(支持const迭代器、移动语义)
    Unix 进程一日游
    3
    react 手写树形渲染组件
    Java字符串简介
    三大云厂商 ARM 架构服务器性能对比
  • 原文地址:https://blog.csdn.net/qq_38334677/article/details/126106509