https://github.com/dzenanr/educ_memory_gameでツイン画像がちらつく問題があります。
view/board.dart の Board クラスでは、_imageBox メソッドの次のコードが画像を作成してロードします。
var imagePath = 'images/${cell.image}';
ImageElement image = new Element.tag('img');
image.src = imagePath;
image.onLoad.listen((event) {
context.drawImageToRect(image, new Rect(x, y, boxSize, boxSize));
});
ボードのセルをクリックすると、画像が 1 秒間表示されます。同じ 2 つの画像が検出されると、それらの双子の画像は表示されたままになりますが、1 秒ごとにちらつきます (タイマーの更新間隔)。
ちらつきの問題を解決するために、Board クラスのコンストラクターでこれらの画像を作成します。
for (var cell in memory.cells) {
ImageElement image = new Element.tag('img');
image.src = 'images/${cell.image}';
imageMap[cell.image] = image;
}
次に、マップから画像を取得します。ただし、次の 2 つの機能はどちらも機能しません。
ImageElement image = imageMap[cell.image];
image.onLoad.listen((event) {
context.drawImageToRect(image, new Rect(x, y, boxSize, boxSize));
});
また
ImageElement image = imageMap[cell.image];
context.drawImageToRect(image, new Rect(x, y, boxSize, boxSize));