【问题标题】:Flutter - How to use an RGB or HEX value for a Widget Container ColorFlutter - 如何为小部件容器颜色使用 RGB 或 HEX 值
【发布时间】:2018-11-26 05:07:45
【问题描述】:

我的应用程序中有一个容器,我想为其使用特定的填充颜色,但我无法弄清楚。我专门使用Colors.grey[500] 没有问题,但我想使用材质颜色库中没有的颜色。我真的很想使用color: new Color.fromRGBO(200, 150, 150, 1.0),但这会引发错误。

谁能指出我正确的方向,以便能够将 RGB 或 HEX 值分配给小部件 color: 属性?

当我将鼠标悬停在 Android Studio 中的代码行上时收到的错误/警告:

The argument type 'Color(...color.dart)' can't be assigned to the parameter 'Color(...painting.dart)'

【问题讨论】:

  • 介意告诉我们实际的错误吗?
  • Rémi,你的评论真的帮了我!造成问题的总是小事。错误是The argument type 'Color(...color.dart) can't be assigned to the parameter 'Color(...painting.dart) - 所以,我意识到我已经包含了import 'package:color/color.dart'; - 一旦我删除它,它就起作用了
  • 不错。考虑用你的答案来回答你自己的问题。并编辑您的问题以包含例外情况。
  • 会做的,再次感谢!
  • 你为什么使用color 包?

标签: flutter flutter-layout


【解决方案1】:

看来是我自己犯了错误。我之前已经包含了如下所示的 color.dart 包:

import 'package:color/color.dart';

它导致了我收到的冲突/错误。当我将鼠标悬停在 Android Studio 编辑器中的错误上时,我会收到警告/错误:

The argument type 'Color(...color.dart)' can't be assigned to the parameter 'Color(...painting.dart)'

删除该导入后,我尝试使用的代码运行良好。

【讨论】:

    猜你喜欢
    • 2017-08-04
    • 2016-07-12
    • 2019-02-08
    • 2012-02-06
    • 1970-01-01
    • 2021-01-07
    • 1970-01-01
    • 1970-01-01
    • 2018-06-16
    相关资源
    最近更新 更多