Flutter:从另一个类导入带有链接ID的正确颜色值

问题描述 投票:0回答:1

我想访问另一个类(类RubricItem)中的列表中的数据。颜色必须是具有相应ID的颜色。

然后,我想将我从RubricItem类调用的列表中的数据插入到Colors类中的列表中。在Colors类中,参数id是:。根据我输入的ID,我的“ rubricColor:”应该知道其值是什么。

示例:

我写下了Colors类'BlueAccent'中列表的id值,然后他还必须知道必须用rubricColor:编写哪种颜色。他在Colors类的id:处看到“ BlueAccent”,并将其与RubricItem类的列表中的id:进行比较,并在RubricItem类的同一列表中看到颜色值,并在Colors列表中看到我的rubricColor:值类,从RubricItem类的列表中获取color的值。

希望您能理解我的意思。我很难解释。

RubricItem类:

class _RubricItemState extends State<RubricItem> {
  final List<Rubric> rubrics = [
    Rubric(
      id: 'BlueAccent',
      title: "BLUEACCENT",
      color: Colors.blueAccent,
      icon: 'assets/icons/blueAC.png',
    ),
    Rubric(
      id: "Pink",
      title: "PINK",
      color: Colors.pinkAccent,
      icon: 'assets/icons/PINK.png',
    ),
    Rubric(
      id: 'GreenAccent',
      title: "GREENACCENT",
      color: Colors.greenAccent,
      icon: 'assets/icons/GreenAccent.png',
    ),
  ];
...

颜色类别列表:

final List<Colorr> colors = [
  Colorr(
    id: 'BlueAccent',  // with this id he should be find the id in the List of the RubricItem() class 
    title: 'Blabla',
    rubric: '',
    rubricColor: , //(RubricItemColor)
  ),
];
list flutter dart provider
1个回答
0
投票
map<String, Rubric> map<String, Colorr>

并且字符串是id。然后只需使用ID

© www.soinside.com 2019 - 2024. All rights reserved.