Added a code sample for replacing the image cache. (#47467)

This commit is contained in:
gaaclarke
2019-12-20 08:50:42 -08:00
committed by GitHub
parent 93f718b386
commit 72a3d914ee
3 changed files with 39 additions and 0 deletions

View File

@@ -1 +1,2 @@
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "ephemeral/Flutter-Generated.xcconfig"

View File

@@ -1 +1,2 @@
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "ephemeral/Flutter-Generated.xcconfig"

View File

@@ -28,6 +28,43 @@ const int _kDefaultSizeBytes = 100 << 20; // 100 MiB
///
/// A shared instance of this cache is retained by [PaintingBinding] and can be
/// obtained via the [imageCache] top-level property in the [painting] library.
///
/// {@tool sample}
///
/// This sample shows how to supply your own caching logic and replace the
/// global [imageCache] varible.
///
/// ```dart
/// /// This is the custom implementation of [ImageCache] where we can override
/// /// the logic.
/// class MyImageCache extends ImageCache {
/// @override
/// void clear() {
/// print("Clearing cache!");
/// super.clear();
/// }
/// }
///
/// class MyWidgetsBinding extends WidgetsFlutterBinding {
/// @override
/// ImageCache createImageCache() => MyImageCache();
/// }
///
/// void main() {
/// // The constructor sets global variables.
/// MyWidgetsBinding();
/// runApp(MyApp());
/// }
///
/// class MyApp extends StatelessWidget {
/// @override
/// Widget build(BuildContext context) {
/// return Container();
/// }
/// }
/// ```
/// {@end-tool}
class ImageCache {
final Map<Object, _PendingImage> _pendingImages = <Object, _PendingImage>{};
final Map<Object, _CachedImage> _cache = <Object, _CachedImage>{};