0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

enumで管理してみた話

Posted at

Motivation

元々以下のように管理してた。

class CharacterImage {
  CharacterImage({required this.name, required this.path});

  final String name;
  final String path;
}

final List<CharacterImage> imageData = [
   CharacterImage(name: '', path: 'path/to/file'),
   ...
];

各キャラクター毎に動画のリストを作りたくなった⇨どうしよう

Idea

別でCharacterKeyを作成⇨keyとimageDataや動画のリストをMapで紐付け

class CharacterImage {
  CharacterImage({required this.name, required this.path});

  final String name;
  final String path;
}

enum CharacterKey {a, b}

final Map<CharacterKey, CharacterImage> imageData = {
   CharacterKey.a: CharacterImage(name: '', path: 'path/to/file'),
   ...
};

final Map<CharacterKey, List<String>> MovieId = {
   CharacterKey.a: ['id1', 'id2'],
   ...
}

Merit

子WidgetへはCharacterKeyを渡すだけで、Widget内で必要なimageDataやMovieIdを取得できるようになった。

Question

Dartでenumって使われているんかな?今回初めて知った

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?