Aus öffentlichen Paketdaten erstellte Orientierung.
ExtendedImage ist ein leistungsstarkes Flutter-Paket, das die Funktionalität standardmäßiger Bilder durch erweiterte Funktionen wie Ladeplätzen, Fehlerzustände, Netzwerk-Caching, Zoom- und Pan-Gesten, Fotoansicht, Slide-out-Seitenübergänge sowie Bildbearbeitungswerkzeuge wie Ausschneiden, Drehen und Spiegeln erweitert. Es unterstützt mehrere Plattformen wie Android, iOS, Web, macOS, Windows und Linux. Für reichhaltige Bildinteraktionen entwickelt, verbessert es die Benutzererfahrung in medienintensiven Anwendungen.
Anwendungsfälle
Foto-Galerien
Bildbearbeitungs-Apps
E-Commerce-Produktansichten
Sozialmedien-Feeds
Interaktive Bildbetrachter
Hauptmerkmale
Zoom- und Panorama-Unterstützung
Lade- und Fehlerplatzhalter
Netzwerk-Bild-Caching
Fotoansicht mit Wischgesten
Eingebaute Bildbearbeitungstools
Plattformübergreifende Kompatibilität
Geeignet für
Entwickler, die medienreiche Apps erstellen
Apps, die interaktive Bildmanipulation erfordern
Projekte, die eine robuste Bildladung und -caching benötigen
Hinweise
Höherer Speicherverbrauch bei komplexen Operationen
Möglicher Leistungseinfluss auf Geräten mit geringer Leistungsfähigkeit
Erfordert sorgfältige Behandlung großer Bilder während der Bearbeitung
Original-README
Originaler README-Schnappschuss aus dem verknüpften Quell-Repository. Aktuelle Inhalte finden Sie im Repository.
A powerful official extension library of images, which supports placeholder(loading)/ failed state, cache network, zoom pan image, photo view, slide-out page, editor (crop, rotate, flip), paint custom etc.
The scale to place in the [ImageInfo] object of the image.
1.0
headers
The HTTP headers that will be used with [HttpClient.get] to fetch image from network.
-
cache
whether cache image to local
false
retries
the time to retry to request
3
timeLimit
time limit to request image
-
timeRetry
the time duration to retry to request
milliseconds: 100
cancelToken
token to cancel network request
CancellationToken()
you can create new provider and extends it with ExtendedProvider, and override instantiateImageCodec method.
so that you can handle image raw data here (compress image).
Load State
Extended Image provide 3 states(loading,completed,failed), you can define your state widget with
loadStateChanged call back.
loadStateChanged is not only for network, if your image need long time to load,
you can set enableLoadState(default value is true for network and others are false) to true
Notice:
if you don't want to override any state, please return null in this case
if you want to override size or sourceRect, you can override it with ExtendedRawImage at completed state
if you want to add something (like animation) at completed state, you can override it with ExtendedImageState.completedWidget
ExtendedImageState.completedWidget is include gesture or editor, so that you would't miss them
/// custom load state widget if you wantfinalLoadStateChanged loadStateChanged;
enumLoadState {
//loading
loading,
//completed
completed,
//failed
failed
}
///whether has loading or failed state///default is false///but network image is true///better to set it's true when your image is big and take some time to readyfinalbool enableLoadState;
ExtendedImageState(LoadStateChanged call back)
parameter/method
description
default
extendedImageInfo
image info
-
extendedImageLoadState
LoadState(loading,completed,failed)
-
returnLoadStateChangedWidget
if this is true, return widget which from LoadStateChanged function immediately(width/height/gesture/border/shape etc, will not effect on it)
-
imageProvider
ImageProvider
-
invertColors
invertColors
-
imageStreamKey
key of image
-
reLoadImage()
if image load failed,you can reload image by call it
-
completedWidget
return completed widget include gesture or editor
-
loadingProgress
return the loading progress for network image (ImageChunkEvent )
-
abstractclassExtendedImageState{
voidreLoadImage();
ImageInfoget extendedImageInfo;
LoadStateget extendedImageLoadState;
///return widget which from LoadStateChanged function immediatelybool returnLoadStateChangedWidget;
ImageProviderget imageProvider;
boolget invertColors;
Objectget imageStreamKey;
Widgetget completedWidget;
}
init GestureConfig when image is ready,for example, base on image width/height
-
onDoubleTap
call back of double tap under ExtendedImageMode.gesture
-
extendedImageGestureKey
you can handle zoom/pan by using this key manually
-
GestureConfig
parameter
description
default
minScale
min scale
0.8
animationMinScale
the min scale for zooming then animation back to minScale when scale end
minScale _ 0.8
maxScale
max scale
5.0
animationMaxScale
the max scale for zooming then animation back to maxScale when scale end
maxScale _ 1.2
speed
speed for zoom/pan
1.0
inertialSpeed
inertial speed for zoom/pan
100
cacheGesture
save Gesture state (for example in ExtendedImageGesturePageView, gesture state will not change when scroll back),remember clearGestureDetailsCache at right time
false
inPageView
whether in ExtendedImageGesturePageView
false
initialAlignment
init image rect with alignment when initialScale > 1.0
onDoubleTap: (ExtendedImageGestureState state) {
///you can use define pointerDownPosition as you can,///default value is double tap pointer down postion.var pointerDownPosition = state.pointerDownPosition;
double begin = state.gestureDetails.totalScale;
double end;
//remove old
_animation?.removeListener(animationListener);
//stop pre
_animationController.stop();
//reset to use
_animationController.reset();
if (begin == doubleTapScales[0]) {
end = doubleTapScales[1];
} else {
end = doubleTapScales[0];
}
animationListener = () {
//print(_animation.value);
state.handleDoubleTap(
scale: _animation.value,
doubleTapPosition: pointerDownPosition);
};
_animation = _animationController
.drive(Tween<double>(begin: begin, end: end));
_animation.addListener(animationListener);
_animationController.forward();
},
providing functions like rotating, flipping, undoing, redoing and reset actions.
null
crop aspect ratio
it's a double value, so it's easy for you to define by yourself.
following are official values
classCropAspectRatios{
/// no aspect ratio for cropstaticconstdouble custom = null;
/// the same as aspect ratio of image/// [cropAspectRatio] is not more than 0.0, it's originalstaticconstdouble original = 0.0;
/// ratio of width and height is 1 : 1staticconstdouble ratio1_1 = 1.0;
/// ratio of width and height is 3 : 4staticconstdouble ratio3_4 = 3.0 / 4.0;
/// ratio of width and height is 4 : 3staticconstdouble ratio4_3 = 4.0 / 3.0;
/// ratio of width and height is 9 : 16staticconstdouble ratio9_16 = 9.0 / 16.0;
/// ratio of width and height is 16 : 9staticconstdouble ratio16_9 = 16.0 / 9.0;
}
crop layer painter
you can define your crop layer by override [EditorConfig.editorCropLayerPainter].
add Image library into your pubspec.yaml, it's used to crop/rotate/flip image data
dependencies:image:any
get crop rect and raw image data from ExtendedImageEditorState
///crop rect base on raw imagefinalRect cropRect = state.getCropRect();
var data = state.rawImageData;
convert raw image data to image library data.
/// it costs much time and blocks ui.//Image src = decodeImage(data);/// it will not block ui with using isolate.//Image src = await compute(decodeImage, data);//Image src = await isolateDecodeImage(data);final lb = await loadBalancer;
Image src = await lb.run<Image, List<int>>(decodeImage, data);
output is raw image data, you can use it to save or any other thing.
/// you can encode your image////// it costs much time and blocks ui.//var fileData = encodeJpg(src);/// it will not block ui with using isolate.//var fileData = await compute(encodeJpg, src);//var fileData = await isolateEncodeImage(src);var fileData = await lb.run<List<int>, Image>(encodeJpg, src);
native library(faster)
add ImageEditor library into your pubspec.yaml, it's used to crop/rotate/flip image data
dependencies:image_editor:any
get crop rect and raw image data from ExtendedImageEditorState
///crop rect base on raw imagefinalRect cropRect = state.getCropRect();
var data = state.rawImageData;
prepare crop option
if (action.hasRotateDegrees) {
finalint rotateDegrees = action.rotateDegrees.toInt();
option.addOption(RotateOption(rotateDegrees));
}
if (action.flipY) {
option.addOption(constFlipOption(horizontal: true, vertical: false));
}
if (action.needCrop) {
Rect cropRect = imageEditorController.getCropRect()!;
option.addOption(ClipOption.fromRect(cropRect));
}
crop with editImage
output is raw image data, you can use it to save or any other thing.
final result = awaitImageEditor.editImage(
image: img,
imageEditorOption: option,
);
ExtendedImageGesturePageView is the same as PageView and it's made for show zoom/pan image.
if you have cache the gesture, remember call clearGestureDetailsCache() method at the right time.(for example,page view page is disposed)
ExtendedImageGesturePageView
parameter
description
default
canMovePage
whether should move page
true
allowImplicitScrolling
whether to respond to implicit accessibility scrolling requests (keeps neighboring pages alive)
false
GestureConfig
parameter
description
default
cacheGesture
save Gesture state (for example in ExtendedImageGesturePageView, gesture state will not change when scroll back),remember clearGestureDetailsCache at right time
false
inPageView
whether in ExtendedImageGesturePageView
false
ExtendedImageGesturePageView.builder(
itemBuilder: (BuildContext context, int index) {
var item = widget.pics[index].picUrl;
Widget image = ExtendedImage.network(
item,
fit: BoxFit.contain,
mode: ExtendedImageMode.gesture,
gestureConfig: GestureConfig(
inPageView: true, initialScale: 1.0,
//you can cache gesture state even though page view page change.//remember call clearGestureDetailsCache() method at the right time.(for example,this page dispose)
cacheGesture: false
),
);
image = Container(
child: image,
padding: EdgeInsets.all(5.0),
);
if (index == currentIndex) {
returnHero(
tag: item + index.toString(),
child: image,
);
} else {
return image;
}
},
itemCount: widget.pics.length,
onPageChanged: (int index) {
currentIndex = index;
rebuild.add(index);
},
controller: PageController(
initialPage: currentIndex,
),
scrollDirection: Axis.horizontal,
),
Slide Out Page
Extended Image support to slide out page as WeChat.
enable slide out page
ExtendedImage
parameter
description
default
enableSlideOutPage
whether enable slide out page
false
heroBuilderForSlidingPage
build Hero only for sliding page, the transform of sliding page must be working on Hero,so that Hero animation wouldn't be strange when pop page
null
include your page in ExtendedImageSlidePage
take care of onSlidingPage call back, you can update other widgets' state as you want.
but, do not setState directly here, image state will changed, you should only notify the widgets which are needed to change
returnExtendedImageSlidePage(
child: result,
slideAxis: SlideAxis.both,
slideType: SlideType.onlyImage,
onSlidingPage: (state) {
///you can change other widgets' state on page as you want///base on offset/isSliding etc//var offset= state.offset;var showSwiper = !state.isSliding;
if (showSwiper != _showSwiper) {
// do not setState directly here, the image state will change,// you should only notify the widgets which are needed to change// setState(() {// _showSwiper = showSwiper;// });
_showSwiper = showSwiper;
rebuildSwiper.add(_showSwiper);
}
},
);
ExtendedImageGesturePage
parameter
description
default
child
The [child] contained by the ExtendedImageGesturePage.
-
slidePageBackgroundHandler
build background when slide page
defaultSlidePageBackgroundHandler
slideScaleHandler
customize scale of page when slide page
defaultSlideScaleHandler
slideEndHandler
call back of slide end,decide whether pop page
defaultSlideEndHandler
slideAxis
axis of slide(both,horizontal,vertical)
SlideAxis.both
resetPageDuration
reset page position when slide end(not pop page)
milliseconds: 500
slideType
slide whole page or only image
SlideType.onlyImage
onSlidingPage
call back when it's sliding page, change other widgets state on page as you want
BoxShape.circle and BoxShape.rectangle,If this is [BoxShape.circle] then [borderRadius] is ignored.
-
borderRadius
If non-null, the corners of this box are rounded by this [BorderRadius].,Applies only to boxes with rectangular shapes; ignored if [shape] is not [BoxShape.rectangle].
-
shape
BoxShape.circle and BoxShape.rectangle,If this is [BoxShape.circle] then [borderRadius] is ignored.
to clear disk cached , call clearDiskCachedImages method.
// Clear the disk cache directory then return if it succeed./// <param name="duration">timespan to compute whether file has expired or not</param>Future<bool> clearDiskCachedImages({Duration duration})
to clear disk cached with specific url, call clearDiskCachedImage method.
/// clear the disk cache image then return if it succeed./// <param name="url">clear specific one</param>Future<bool> clearDiskCachedImage(String url) async {
By setting layoutInsets, you can ensure the image is positioned outside of obstructing elements such as
the phone notch or home indicator if displayed in full screen. This will still allow the image margin to
show underneath the notch if zoomed in.
You can reduce memory usage with following settings now.
ExtendedResizeImage
parameter
description
default
[ExtendedResizeImage.compressionRatio]
The images size will resize to original * [compressionRatio].It's ExtendedResizeImages first pick.The compressionRatio`s range is from 0.0 (exclusive), to 1.0 (exclusive).
null
[ExtendedResizeImage.maxBytes]
[ExtendedResizeImage] will compress the image to a size that is smaller than [maxBytes]. The default size is 50KB. It's actual bytes of Image, not decode bytes
The name of [ImageCache], you can define custom [ImageCache] to store this image. In this way you can work with them without affecting other [ImageCache]
null
ExtendedImage.network(
'imageUrl',
imageCacheName: 'MemoryUsage',
)
/// clear when this page is disposed @overridevoiddispose() {
// clear ImageCache which named 'MemoryUsage'clearMemoryImageCache(imageCacheName);
super.dispose();
}
Other APIs
ExtendedImage
parameter
description
default
enableMemoryCache
whether cache in PaintingBinding.instance.imageCache)
true
clearMemoryCacheIfFailed
when failed to load image, whether clear memory cache.if true, image will reload in next time.
true
clearMemoryCacheWhenDispose
when image is removed from the tree permanently, whether clear memory cache.