2

次のような再帰的な SplayTreeMap (自動生成) を取得しました (疑似コード):

SplayTreeMap map = <SplayTreeMap>{
  Entry('path', 'cooltype'): <SplayTreeMap>{
    Entry('subpath', 'othercooltype'): <SplayTreeMap>{
      Entry('subsubpath', 'coolcooltype'): <SplayTreeMap>{},
    },
    Entry('othersubpath', 'othercooltype'): <SplayTreeMap>{},
  },
}

クラス エントリは次のようになります。

class Entry implements Comparable<Entry> {
  String path;
  String type = 'defaulttype';
  int songs = 0;

  Entry(this.path, this.type);

  @override
  int compareTo(Entry other) =>
      this.path.toLowerCase().compareTo(other.path.toLowerCase());

  @override
  String toString() => 'Entry( ${this.path} )';

  String get name => path.split('/').lastWhere((e) => e != '');
}

私がやりたいことは、 に 1 を追加することEntry('subpath', 'othercooltype').songsです。を試しmap.updateましたが、成功しませんでした ( [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: type '(dynamic) => dynamic' is not a subtype of type '(SplayTreeMap<dynamic, dynamic>) => SplayTreeMap<dynamic, dynamic>' of 'update')。また、その値を保存し、キーを削除して更新されたキーを追加しようとしましたが、バグがありました (機能する場合もあれば、機能しない場合もあります)。

私の現在のコード:

    Entry entry = Entry(relativeString, type);
    if (type == 'othercooltype') entry.songs++;
    if (!submap.containsKey(entry)) {
      submap[entry] = SplayTreeMap();
      setState(() => valueChanged(value++));
    } else {
      // update key with songs++
    }
4

1 に答える 1