image_map.dart 692 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

part of sprites;

class ImageMap {
  ImageMap(AssetBundle bundle) : _bundle = bundle;

  final AssetBundle _bundle;
  final Map<String, Image> _images = new Map<String, Image>();

  Future<List<Image>> load(List<String> urls) {
    return Future.wait(urls.map(_loadImage));
  }

  Future<Image> _loadImage(String url) async {
18
    Image image = await _bundle.loadImage(url).first;
19 20 21 22 23 24 25
    _images[url] = image;
    return image;
  }

  Image getImage(String url) => _images[url];
  Image operator [](String url) => _images[url];
}