【问题标题】:How do I show the color preview next to color name?如何在颜色名称旁边显示颜色预览?
【发布时间】:2019-12-11 14:22:05
【问题描述】:

我目前正在使用 Flutter 开发一个移动应用程序。我想在下拉列表中显示颜色预览和颜色,如下所示:

我该怎么做?有什么可以导入的包吗?

*它们都是土耳其语单词。 (Kırmızı=red、mavi=blue、sarı=yellow 等)

【问题讨论】:

  • 我给你一个提示,你可以使用这些小部件来做到这一点:ListViewListTile,颜色名称为titleIcon,颜色名称为tailing。您还可以展示您的代码以获得更多帮助。
  • 你试过什么?堆栈溢出希望您在提问之前有一个可重复的最小示例。

标签: flutter visual-studio-code colors preview


【解决方案1】:
class PaintColors{
  String colorName;
  var preview;

PaintColors(this.colorName, this.preview);

paintTheIcon(String name) {
switch (name) {
  case 'Kırmızı':
    preview = Icon(
      Icons.brightness_1,
      color: Colors.red,
    );
    break;

case 'Beyaz':
    preview = Icon(
      Icons.brightness_1,
      color: Colors.white,
    );
    break;
}
return preview;
}
}

我创建了这个类并尝试将它们放入列表中:

static List<PaintColors> colorList = [('Beyaz', paintTheIcon('Beyaz'))];

... 但它没有用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-09-10
    • 2014-09-01
    • 1970-01-01
    • 2016-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-05
    相关资源
    最近更新 更多