public virtual void addListener(ImageListener listener, ImageErrorListener onError = null) { this._listeners.Add(new _ImageListenerPair { listener = listener, errorListener = onError }); if (this.currentImage != null) { try { listener(this.currentImage, true); } catch (Exception ex) { this.reportError( context: "by a synchronously-called image listener", exception: ex ); } } if (this.currentError != null && onError != null) { try { onError(this.currentError.exception); } catch (Exception ex) { UIWidgetsError.reportError( new UIWidgetsErrorDetails( exception: ex, library: "image resource service", context: "when reporting an error to an image listener" ) ); } } }
public HtmlOldParser( float?width = null, OnLinkTap onLinkTap = null, bool renderNewlines = false, CustomRender customRender = null, float blockSpacing = 0.0f, string html = null, ImageErrorListener onImageError = null, TextStyle linkStyle = null, bool showImages = true ) { D.assert(width != null); this.width = width.Value; this.onLinkTap = onLinkTap; this.renderNewlines = renderNewlines; this.customRender = customRender; this.blockSpacing = blockSpacing; this.html = html; this.onImageError = onImageError; this.linkStyle = linkStyle; this.showImages = showImages; this.linkStyle = linkStyle ?? new TextStyle( decoration: TextDecoration.underline, color: Colors.blueAccent, decorationColor: Colors.blueAccent); }
ImageStreamListener _getListener(ImageLoadingBuilder loadingBuilder = null) { loadingBuilder = loadingBuilder ?? widget.loadingBuilder; _lastException = null; _lastStack = null; ImageChunkListener onChunk = null; if (loadingBuilder == null) { onChunk = _handleImageChunk; } ImageErrorListener onError = null; if (widget.errorBuilder != null) { onError = error => { setState(() => { _lastException = error; // _lastStack = stackTrace; }); }; } return(new ImageStreamListener( onImage: _handleImageFrame, onChunk: onChunk, onError: onError )); }
public override void resolveStreamForKey( ImageConfiguration configuration, ImageStream stream, T key, ImageErrorListener handleError) { if (stream.completer != null || PaintingBinding.instance.imageCache.containsKey(key)) { imageProvider.resolveStreamForKey(configuration, stream, key, handleError); return; } if (context.context == null) { return; } if (Scrollable.recommendDeferredLoadingForContext(context.context)) { SchedulerBinding.instance.scheduleFrameCallback((_) => { async_.scheduleMicrotask( () => { resolveStreamForKey(configuration, stream, key, handleError); return(null); } ); }); return; } imageProvider.resolveStreamForKey(configuration, stream, key, handleError); }
public override void addListener(ImageListener listener, ImageErrorListener onError = null) { if (!this.hasListeners && this._codec != null) { this._decodeNextFrameAndSchedule(); } base.addListener(listener, onError: onError); }
BoxDecoration _createDefaultThumbDecoration(Color color, ImageProvider image, ImageErrorListener errorListener) { return(new BoxDecoration( color: color, image: image == null ? null : new DecorationImage(image: image, onError: errorListener), shape: BoxShape.circle, boxShadow: material_.kElevationToShadow[1] )); }
public ImageStreamListener( ImageListener onImage, ImageChunkListener onChunk = null, ImageErrorListener onError = null ) { D.assert(onImage != null); this.onImage = onImage; this.onChunk = onChunk; this.onError = onError; }
public _RenderSwitch( bool?value = null, Color activeColor = null, Color inactiveColor = null, Color hoverColor = null, Color focusColor = null, ImageProvider activeThumbImage = null, ImageErrorListener onActiveThumbImageError = null, ImageProvider inactiveThumbImage = null, ImageErrorListener onInactiveThumbImageError = null, Color activeTrackColor = null, Color inactiveTrackColor = null, ImageConfiguration configuration = null, BoxConstraints additionalConstraints = null, TextDirection?textDirection = null, ValueChanged <bool?> onChanged = null, DragStartBehavior?dragStartBehavior = null, bool hasFocus = false, bool hovering = false, _SwitchState state = null ) : base( value: value, tristate: false, activeColor: activeColor, inactiveColor: inactiveColor, hoverColor: hoverColor, focusColor: focusColor, onChanged: onChanged, additionalConstraints: additionalConstraints, hasFocus: hasFocus, hovering: hovering, vsync: state ) { D.assert(textDirection != null); _activeThumbImage = activeThumbImage; _onActiveThumbImageError = onActiveThumbImageError; _inactiveThumbImage = inactiveThumbImage; _onInactiveThumbImageError = onInactiveThumbImageError; _activeTrackColor = activeTrackColor; _inactiveTrackColor = inactiveTrackColor; _configuration = configuration; _drag = new HorizontalDragGestureRecognizer { onStart = _handleDragStart, onUpdate = _handleDragUpdate, onEnd = _handleDragEnd, dragStartBehavior = dragStartBehavior ?? DragStartBehavior.down }; }
public void addListener(ImageListener listener, ImageErrorListener onError = null) { if (this._completer != null) { this._completer.addListener(listener, onError); return; } if (this._listeners == null) { this._listeners = new List <_ImageListenerPair>(); } this._listeners.Add(new _ImageListenerPair { listener = listener, errorListener = onError }); }
public HtmlView( Key key = null, string data = null, EdgeInsets padding = null, Color backgroundColor = null, TextStyle defaultTextStyle = null, OnLinkTap onLinkTap = null, bool renderNewlines = false, CustomRender customRender = null, CustomEdgeInsets customEdgeInsets = null, CustomTextStyle customTextStyle = null, CustomTextAlign customTextAlign = null, float blockSpacing = 14.0f, bool useRichText = true, ImageErrorListener onImageError = null, TextStyle linkStyle = null, bool shrinkToFit = false, ImageProperties imageProperties = null, OnImageTap onImageTap = null, bool showImages = true ) : base(key: key) { D.assert(data != null); this.data = data; this.padding = padding; this.backgroundColor = backgroundColor; this.defaultTextStyle = defaultTextStyle; this.onLinkTap = onLinkTap; this.renderNewlines = renderNewlines; this.customRender = customRender; this.customEdgeInsets = customEdgeInsets; this.customTextStyle = customTextStyle ?? this._customTextStyle; this.customTextAlign = customTextAlign; this.blockSpacing = blockSpacing; this.useRichText = useRichText; this.onImageError = onImageError; this.linkStyle = linkStyle ?? new TextStyle( decoration: TextDecoration.underline, color: Colors.blueAccent, decorationColor: Colors.blueAccent); this.shrinkToFit = shrinkToFit; this.imageProperties = imageProperties; this.onImageTap = onImageTap; this.showImages = showImages; }
public _SwitchRenderObjectWidget( Key key = null, bool?value = null, Color activeColor = null, Color inactiveColor = null, Color hoverColor = null, Color focusColor = null, ImageProvider activeThumbImage = null, ImageErrorListener onActiveThumbImageError = null, ImageProvider inactiveThumbImage = null, ImageErrorListener onInactiveThumbImageError = null, Color activeTrackColor = null, Color inactiveTrackColor = null, ImageConfiguration configuration = null, ValueChanged <bool?> onChanged = null, BoxConstraints additionalConstraints = null, DragStartBehavior?dragStartBehavior = null, bool hasFocus = false, bool hovering = false, _SwitchState state = null ) : base(key: key) { D.assert(value != null); this.value = value.Value; this.activeColor = activeColor; this.inactiveColor = inactiveColor; this.hoverColor = hoverColor; this.focusColor = focusColor; this.activeThumbImage = activeThumbImage; this.onActiveThumbImageError = onActiveThumbImageError; this.inactiveThumbImage = inactiveThumbImage; this.onInactiveThumbImageError = onInactiveThumbImageError; this.activeTrackColor = activeTrackColor; this.inactiveTrackColor = inactiveTrackColor; this.configuration = configuration; this.onChanged = onChanged; this.additionalConstraints = additionalConstraints; this.dragStartBehavior = dragStartBehavior; this.hasFocus = hasFocus; this.hovering = hovering; this.state = state; }
Switch( Key key = null, bool?value = null, ValueChanged <bool?> onChanged = null, Color activeColor = null, Color activeTrackColor = null, Color inactiveThumbColor = null, Color inactiveTrackColor = null, ImageProvider activeThumbImage = null, ImageErrorListener onActiveThumbImageError = null, ImageProvider inactiveThumbImage = null, ImageErrorListener onInactiveThumbImageError = null, MaterialTapTargetSize?materialTapTargetSize = null, _SwitchType switchType = _SwitchType.material, DragStartBehavior dragStartBehavior = DragStartBehavior.start, Color focusColor = null, Color hoverColor = null, FocusNode focusNode = null, bool autofocus = false ) : base(key : key) { D.assert(value != null); this.value = value.Value; D.assert(activeThumbImage != null || onActiveThumbImageError == null); D.assert(inactiveThumbImage != null || onInactiveThumbImageError == null); this.onChanged = onChanged; this.activeColor = activeColor; this.activeTrackColor = activeTrackColor; this.inactiveThumbColor = inactiveThumbColor; this.inactiveTrackColor = inactiveTrackColor; this.activeThumbImage = activeThumbImage; this.onActiveThumbImageError = onActiveThumbImageError; this.inactiveThumbImage = inactiveThumbImage; this.onInactiveThumbImageError = onInactiveThumbImageError; this.materialTapTargetSize = materialTapTargetSize; _switchType = switchType; this.dragStartBehavior = dragStartBehavior; this.focusColor = focusColor; this.hoverColor = hoverColor; this.focusNode = focusNode; this.autofocus = autofocus; }
public DecorationImage( ImageProvider image = null, ImageErrorListener onError = null, ColorFilter colorFilter = null, BoxFit?fit = null, AlignmentGeometry alignment = null, Rect centerSlice = null, ImageRepeat repeat = ImageRepeat.noRepeat, bool matchTextDirection = false ) { D.assert(image != null); this.image = image; this.onError = onError; this.colorFilter = colorFilter; this.fit = fit; this.alignment = alignment ?? Alignment.center; this.centerSlice = centerSlice; this.repeat = repeat; this.matchTextDirection = matchTextDirection; }
public Switch( Key key = null, bool?value = null, ValueChanged <bool?> onChanged = null, Color activeColor = null, Color activeTrackColor = null, Color inactiveThumbColor = null, Color inactiveTrackColor = null, ImageProvider activeThumbImage = null, ImageErrorListener onActiveThumbImageError = null, ImageProvider inactiveThumbImage = null, ImageErrorListener onInactiveThumbImageError = null, MaterialTapTargetSize?materialTapTargetSize = null, DragStartBehavior dragStartBehavior = DragStartBehavior.start, Color focusColor = null, Color hoverColor = null, FocusNode focusNode = null, bool autofocus = false ) : this( key : key, value : value, onChanged : onChanged, activeColor : activeColor, activeTrackColor : activeTrackColor, inactiveThumbColor : inactiveThumbColor, inactiveTrackColor : inactiveTrackColor, activeThumbImage : activeThumbImage, onActiveThumbImageError : onActiveThumbImageError, inactiveThumbImage : inactiveThumbImage, onInactiveThumbImageError : onInactiveThumbImageError, materialTapTargetSize : materialTapTargetSize, switchType : _SwitchType.material, dragStartBehavior : dragStartBehavior, focusColor : focusColor, hoverColor : hoverColor, focusNode : focusNode, autofocus : autofocus ) { }
public static Future precacheImage( ImageProvider provider, BuildContext context, Size size = null, ImageErrorListener onError = null ) { var config = createLocalImageConfiguration(context: context, size: size); var completer = Completer.create(); var stream = provider.resolve(configuration: config); ImageStreamListener listener = null; listener = new ImageStreamListener( (image, sync) => { if (!completer.isCompleted) { completer.complete(); } SchedulerBinding.instance.addPostFrameCallback(timeStamp => { stream.removeListener(listener: listener); }); }, onError: error => { if (!completer.isCompleted) { completer.complete(); } stream.removeListener(listener: listener); UIWidgetsError.reportError(new UIWidgetsErrorDetails( context: new ErrorDescription("image failed to precache"), library: "image resource service", silent: true)); } ); stream.addListener(listener: listener); return(completer.future); }
public IPromise precacheImage( ImageProvider provider, BuildContext context, Size size = null, ImageErrorListener onError = null ) { ImageConfiguration config = createLocalImageConfiguration(context, size: size); var completer = new Promise(); ImageStream stream = provider.resolve(config); void listener(ImageInfo image, bool sync) { completer.Resolve(); stream.removeListener(listener); } void errorListener(Exception exception) { completer.Resolve(); stream.removeListener(listener); if (onError != null) { onError(exception); } else { UIWidgetsError.reportError(new UIWidgetsErrorDetails( context: "image failed to precache", library: "image resource service", exception: exception, silent: true )); } } stream.addListener(listener, onError: errorListener); return(completer); }
public static Ink image( Key key = null, EdgeInsetsGeometry padding = null, ImageProvider image = null, ImageErrorListener onImageError = null, ColorFilter colorFilter = null, BoxFit?fit = null, AlignmentGeometry alignment = null, Rect centerSlice = null, ImageRepeat repeat = ImageRepeat.noRepeat, float?width = null, float?height = null, Widget child = null ) { D.assert(padding == null || padding.isNonNegative); D.assert(image != null); alignment = alignment ?? Alignment.center; Decoration decoration = new BoxDecoration( image: new DecorationImage( image: image, onError: onImageError, colorFilter: colorFilter, fit: fit, alignment: alignment, centerSlice: centerSlice, repeat: repeat) ); return(new Ink( key: key, padding: padding, decoration: decoration, width: width, height: height, child: child)); }
public CircleAvatar( Key key = null, Widget child = null, Color backgroundColor = null, ImageProvider backgroundImage = null, ImageErrorListener onBackgroundImageError = null, Color foregroundColor = null, float?radius = null, float?minRadius = null, float?maxRadius = null ) : base(key: key) { D.assert(radius == null || (minRadius == null && maxRadius == null)); D.assert(backgroundImage != null || onBackgroundImageError == null); this.child = child; this.backgroundColor = backgroundColor; this.backgroundImage = backgroundImage; this.onBackgroundImageError = onBackgroundImageError; this.foregroundColor = foregroundColor; this.radius = radius; this.minRadius = minRadius; this.maxRadius = maxRadius; }
public ImageStreamCompleter putIfAbsent(object key, Func <ImageStreamCompleter> loader, ImageErrorListener onError = null) { D.assert(key != null); D.assert(loader != null); ImageStreamCompleter result = null; if (_pendingImages.TryGetValue(key, out var pendingImage)) { result = pendingImage.completer; return(result); } if (_cache.TryGetValue(key, out var image)) { if (image.node != null) { _lruKeys.Remove(image.node); } _trackLiveImage(key, new _LiveImage(image.completer, image.sizeBytes, () => _liveImages.Remove(key))); image.node = _lruKeys.AddLast(key); return(image.completer); } _liveImages.TryGetValue(key, out var liveImage); if (liveImage != null) { _touch(key, liveImage); return(liveImage.completer); } try { result = loader(); _trackLiveImage(key, new _LiveImage(result, null, () => _liveImages.Remove(key))); } catch (Exception ex) { if (onError != null) { onError(ex); } else { throw; } } bool listenedOnce = false; _PendingImage untrackedPendingImage = null; void listener(ImageInfo info, bool syncCall) { int imageSize = info?.image == null ? 0 : info.image.height * info.image.width * 4; _CachedImage cachedImage = new _CachedImage(result, imageSize); _trackLiveImage( key, new _LiveImage( result, imageSize, () => _liveImages.Remove(key) ), debugPutOk: syncCall ); _PendingImage _pendingImage = untrackedPendingImage ?? _pendingImages.getOrDefault(key); _pendingImages.Remove(key); if (_pendingImage != null) { _pendingImage.removeListener(); } if (untrackedPendingImage == null) { _touch(key, cachedImage); } listenedOnce = true; } ImageStreamListener streamListener = new ImageStreamListener(listener); if (maximumSize > 0 && maximumSizeBytes > 0) { _pendingImages[key] = new _PendingImage(result, streamListener); } else { untrackedPendingImage = new _PendingImage(result, streamListener); } result.addListener(streamListener); return(result); }
public ImageStreamCompleter putIfAbsent(object key, Func <ImageStreamCompleter> loader, ImageErrorListener onError = null) { D.assert(key != null); D.assert(loader != null); ImageStreamCompleter result = null; if (this._pendingImages.TryGetValue(key, out var pendingImage)) { result = pendingImage.completer; return(result); } if (this._cache.TryGetValue(key, out var image)) { // put to the MRU position this._lruKeys.Remove(image.node); image.node = this._lruKeys.AddLast(key); return(image.completer); } try { result = loader(); } catch (Exception ex) { if (onError != null) { onError(ex); } else { throw; } } void listener(ImageInfo info, bool syncCall) { int imageSize = info?.image == null ? 0 : info.image.height * info.image.width * 4; _CachedImage cachedImage = new _CachedImage(result, imageSize); if (this.maximumSizeBytes > 0 && imageSize > this.maximumSizeBytes) { this._maximumSizeBytes = imageSize + 1000; } this._currentSizeBytes += imageSize; if (this._pendingImages.TryGetValue(key, out var loadedPendingImage)) { loadedPendingImage.removeListener(); this._pendingImages.Remove(key); } D.assert(!this._cache.ContainsKey(key)); this._cache[key] = cachedImage; cachedImage.node = this._lruKeys.AddLast(key); this._checkCacheSize(); } if (this.maximumSize > 0 && this.maximumSizeBytes > 0) { this._pendingImages[key] = new _PendingImage(result, listener); result.addListener(listener); } return(result); }
public override void paint(PaintingContext context, Offset offset) { Canvas canvas = context.canvas; bool isEnabled = onChanged != null; float currentValue = position.value; float visualPosition = currentValue; Color trackColor = isEnabled ? Color.lerp(inactiveTrackColor, activeTrackColor, currentValue) : inactiveTrackColor; Color thumbColor = isEnabled ? Color.lerp(inactiveColor, activeColor, currentValue) : inactiveColor; ImageProvider thumbImage = isEnabled ? (currentValue < 0.5 ? inactiveThumbImage : activeThumbImage) : inactiveThumbImage; ImageErrorListener thumbErrorListener = isEnabled ? (currentValue < 0.5f ? onInactiveThumbImageError : onActiveThumbImageError) : onInactiveThumbImageError; // Paint the track Paint paint = new Paint { color = trackColor }; float trackHorizontalPadding = material_.kRadialReactionRadius - Switch._kTrackRadius; Rect trackRect = Rect.fromLTWH( offset.dx + trackHorizontalPadding, offset.dy + (size.height - Switch._kTrackHeight) / 2.0f, size.width - 2.0f * trackHorizontalPadding, Switch._kTrackHeight ); RRect trackRRect = RRect.fromRectAndRadius(trackRect, Radius.circular(Switch._kTrackRadius)); canvas.drawRRect(trackRRect, paint); Offset thumbPosition = new Offset( material_.kRadialReactionRadius + visualPosition * _trackInnerLength, size.height / 2.0f ); paintRadialReaction(canvas, offset, thumbPosition); try { _isPainting = true; BoxPainter thumbPainter; if (_cachedThumbPainter == null || thumbColor != _cachedThumbColor || thumbImage != _cachedThumbImage || thumbErrorListener != _cachedThumbErrorListener) { _cachedThumbColor = thumbColor; _cachedThumbImage = thumbImage; _cachedThumbErrorListener = thumbErrorListener; _cachedThumbPainter = _createDefaultThumbDecoration(thumbColor, thumbImage, thumbErrorListener) .createBoxPainter(_handleDecorationChanged); } thumbPainter = _cachedThumbPainter; float inset = 1.0f - (currentValue - 0.5f).abs() * 2.0f; float radius = Switch._kThumbRadius - inset; thumbPainter.paint( canvas, thumbPosition + offset - new Offset(radius, radius), configuration.copyWith(size: Size.fromRadius(radius)) ); } finally { _isPainting = false; } }