无法从用户界面中删除芯片

时间:2020-07-03 07:58:18

标签: flutter dart flutter-layout

无法删除筹码。

这是 chipDetails 中的Chip数据列表。

List<Map> chipDetails= new List<Map>();


以下是创建筹码的功能及其 onDeleted 功能。 数据已从 chipDetails 列表中删除,但位于用户界面上。

//For creating the input chip
  Widget selectPlayerAsChip(String playerId,String playerName, String playerImage){

    Map data = {"id":playerId,"name":playerName,"profile_pic":playerImage};
    chipDetails.add(data);

    return Chip(
      avatar: profileIconSelector(playerImage,playerName,10.0),
      label: Text('$playerName'),
      onDeleted: (){
        setState(() {
          chipDetails.removeWhere((Map info) {
            return playerName == info["name"];
          });
        });
      },
    );
  }

1 个答案:

答案 0 :(得分:0)

我最终使用包装在有状态对话框中列出了筹码。 这些YouTube视频帮助:https://youtu.be/PxcbT1wGkUo https://youtu.be/FGfhnS6skMQ https://youtu.be/Fd5ZlOxyZJ4

fn append_1_to_all(mut strings: Vec<String>) -> Vec<String> {
    for s in strings.iter_mut() {
        s.push_str("1")
    }
    strings
}

fn get_shared_references(strings: &Vec<String>) -> Vec<&String> {
    // Or even better, just use strings.iter() instead of this function
    strings.iter().collect()
}

#[test]
fn test() {
    let strings = vec!["one".to_string(), "two".to_string(), "three".to_string()];

    // .clone() here is necessarily only because strings is used in the assert below
    let strings_appended = append_1_to_all(strings.clone());

    let strings_shared = get_shared_references(&strings_appended);

    assert_ne!(strings[0], *strings_shared[0]);
}