flutter/packages/flutter_sprites/lib/image_map.dart
Adam Barth 490b22874a SkySprites should import the public libraries
Importing the public libraries caused a name conflict with dart:sky because we
assume people will import dart:sky into a namespace, so I've also changed
skysprites to import dart:sky into a namespace.
2015-09-18 11:19:39 -07:00

26 lines
723 B
Dart

// 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 skysprites;
class ImageMap {
ImageMap(AssetBundle bundle) : _bundle = bundle;
final AssetBundle _bundle;
final Map<String, sky.Image> _images = new Map<String, sky.Image>();
Future<List<sky.Image>> load(List<String> urls) {
return Future.wait(urls.map(_loadImage));
}
Future<sky.Image> _loadImage(String url) async {
sky.Image image = await _bundle.loadImage(url).first;
_images[url] = image;
return image;
}
sky.Image getImage(String url) => _images[url];
sky.Image operator [](String url) => _images[url];
}