optimized_cached_image 1.0.0-rc1 optimized_cached_image: ^1.0.0-rc1 copied to clipboard
A library for loading images from network, resizing as per container size and caching while being memory sensitive.
import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:optimized_cached_image/image_cache_manager.dart';
import 'package:optimized_cached_image/widgets.dart';
import 'package:path_provider/path_provider.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
final urlPrefix = "https://i.picsum.photos/id/";
final urlSuffix = "/1000/1000.jpg";
@override
void initState() {
super.initState();
/// Just a demo of the param(s) in ImageCacheManager,
/// you don't need to do this unless you wish to customize stuff
ImageCacheManager.init(
ImageCacheConfig(storagePath: path(), enableLog: !kReleaseMode));
}
/// A debug path to inspect our cache files on android.
/// Note this is purely for debugging and wouldn't work on ios since such a directory doesn't exist.
/// You're better of not passing this value to [ImageCacheManager.init]
Future<Directory> path() async => (await getExternalCacheDirectories())[0];
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Optimized Cached Image Example'),
),
body: Container(
child: GridView.builder(
padding: const EdgeInsets.all(20),
itemCount: 30,
gridDelegate:
SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3),
itemBuilder: (BuildContext context, int index) {
return OptimizedCacheImage(
imageUrl: "https://picsum.photos/id/${(index + 100)}/600/600",
);
},
),
),
),
);
}
}