Skip to content

Commit

Permalink
Merge 0ab6c15 into 2408b05
Browse files Browse the repository at this point in the history
  • Loading branch information
dnfield committed Sep 11, 2020
2 parents 2408b05 + 0ab6c15 commit c584147
Show file tree
Hide file tree
Showing 12 changed files with 187 additions and 88 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
@@ -1,7 +1,17 @@
# CHANGES

## 0.19.0

- Avoid unnecessary cache invalidation of SVGs drawn with color changes by:
- Deprecate color filter related options on PictureProvider classes.
- Make ColorFilter a property on SvgPicture
- Use the ColorFiltered widget for filtered SVGs.

## 0.18.1

- Bump the path_drawing dependency to 0.4.1+1
- Expose clipBehavior from FittedBox
- Expose SVG ids in `Drawable*` classes.
- Change type of `alignment` to `AlignmentGeometry` on `SvgPicture`.
- Fixed bug in transform parsing

Expand Down
69 changes: 33 additions & 36 deletions lib/avd.dart
Expand Up @@ -75,28 +75,28 @@ class Avd {
.map((XmlElement child) => parseAvdElement(child, viewBox.viewBoxRect))
.toList();
// todo : style on root
return DrawableRoot(
getAttribute(svg.attributes, 'id', def: ''),
viewBox,
children,
DrawableDefinitionServer(),
null
);
return DrawableRoot(getAttribute(svg.attributes, 'id', def: ''), viewBox,
children, DrawableDefinitionServer(), null);
}
}

/// Extends [VectorDrawableImage] to parse SVG data to [Drawable].
class AvdPicture extends SvgPicture {
const AvdPicture(PictureProvider pictureProvider,
{Key key,
bool matchTextDirection = false,
bool allowDrawingOutsideViewBox = false,
WidgetBuilder placeholderBuilder})
: super(pictureProvider,
key: key,
matchTextDirection: matchTextDirection,
allowDrawingOutsideViewBox: allowDrawingOutsideViewBox,
placeholderBuilder: placeholderBuilder);
const AvdPicture(
PictureProvider pictureProvider, {
Key key,
bool matchTextDirection = false,
bool allowDrawingOutsideViewBox = false,
WidgetBuilder placeholderBuilder,
ColorFilter colorFilter,
}) : super(
pictureProvider,
key: key,
matchTextDirection: matchTextDirection,
allowDrawingOutsideViewBox: allowDrawingOutsideViewBox,
placeholderBuilder: placeholderBuilder,
colorFilter: colorFilter,
);

AvdPicture.string(String bytes,
{bool matchTextDirection = false,
Expand All @@ -107,11 +107,12 @@ class AvdPicture extends SvgPicture {
Key key})
: this(
StringPicture(
allowDrawingOutsideViewBox == true
? avdStringDecoderOutsideViewBox
: avdStringDecoder,
bytes,
colorFilter: _getColorFilter(color, colorBlendMode)),
allowDrawingOutsideViewBox == true
? avdStringDecoderOutsideViewBox
: avdStringDecoder,
bytes,
),
colorFilter: _getColorFilter(color, colorBlendMode),
matchTextDirection: matchTextDirection,
allowDrawingOutsideViewBox: allowDrawingOutsideViewBox,
placeholderBuilder: placeholderBuilder,
Expand All @@ -128,13 +129,14 @@ class AvdPicture extends SvgPicture {
BlendMode colorBlendMode = BlendMode.srcIn})
: this(
ExactAssetPicture(
allowDrawingOutsideViewBox == true
? avdStringDecoderOutsideViewBox
: avdStringDecoder,
assetName,
bundle: bundle,
package: package,
colorFilter: _getColorFilter(color, colorBlendMode)),
allowDrawingOutsideViewBox == true
? avdStringDecoderOutsideViewBox
: avdStringDecoder,
assetName,
bundle: bundle,
package: package,
),
colorFilter: _getColorFilter(color, colorBlendMode),
matchTextDirection: matchTextDirection,
allowDrawingOutsideViewBox: allowDrawingOutsideViewBox,
placeholderBuilder: placeholderBuilder,
Expand Down Expand Up @@ -168,11 +170,6 @@ DrawableRoot fromAvdString(String rawSvg, Rect size) {
.map((XmlElement child) => parseAvdElement(child, size))
.toList();
// todo : style on root
return DrawableRoot(
getAttribute(svg.attributes, 'id', def: ''),
viewBox,
children,
DrawableDefinitionServer(),
null
);
return DrawableRoot(getAttribute(svg.attributes, 'id', def: ''), viewBox,
children, DrawableDefinitionServer(), null);
}
8 changes: 6 additions & 2 deletions lib/src/avd_parser.dart
Expand Up @@ -9,8 +9,12 @@ import 'avd/xml_parsers.dart';
import 'vector_drawable.dart';

class DrawableAvdRoot extends DrawableRoot {
const DrawableAvdRoot(String id, DrawableViewport viewBox, List<Drawable> children,
DrawableDefinitionServer definitions, DrawableStyle style)
const DrawableAvdRoot(
String id,
DrawableViewport viewBox,
List<Drawable> children,
DrawableDefinitionServer definitions,
DrawableStyle style)
: super(id, viewBox, children, definitions, style);
}

Expand Down
33 changes: 26 additions & 7 deletions lib/src/picture_provider.dart
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// ignore_for_file: deprecated_member_use_from_same_package

import 'dart:async';
import 'dart:io';
import 'dart:typed_data';
Expand Down Expand Up @@ -76,7 +78,7 @@ class PictureConfiguration {
this.textDirection,
this.viewBox,
this.platform,
this.colorFilter,
@deprecated this.colorFilter,
});

/// Creates an object holding the configuration information for an [PictureProvider].
Expand Down Expand Up @@ -121,6 +123,8 @@ class PictureConfiguration {
final TargetPlatform platform;

/// The [ColorFilter], if any, that was applied to the drawing.
@Deprecated(
'Use a ColorFilter widget instead, or the color parameter on SvgPicture.')
final ColorFilter colorFilter;

/// a picture configuration that provides no additional information.
Expand Down Expand Up @@ -378,7 +382,9 @@ class AssetBundlePictureKey {
///
/// The arguments must not be null.
const AssetBundlePictureKey(
{@required this.bundle, @required this.name, this.colorFilter})
{@required this.bundle,
@required this.name,
@deprecated this.colorFilter})
: assert(bundle != null),
assert(name != null);

Expand All @@ -393,6 +399,8 @@ class AssetBundlePictureKey {
final String name;

/// The [ColorFilter], if any, to be applied to the drawing.
@Deprecated(
'Use a ColorFilter widget instead, or the color parameter on SvgPicture.')
final ColorFilter colorFilter;

@override
Expand Down Expand Up @@ -472,7 +480,8 @@ class NetworkPicture extends PictureProvider<NetworkPicture> {
/// Creates an object that fetches the picture at the given URL.
///
/// The arguments must not be null.
const NetworkPicture(this.decoder, this.url, {this.headers, this.colorFilter})
const NetworkPicture(this.decoder, this.url,
{this.headers, @deprecated this.colorFilter})
: assert(url != null);

/// The decoder to use to turn a [Uint8List] into a [PictureInfo] object.
Expand All @@ -485,6 +494,8 @@ class NetworkPicture extends PictureProvider<NetworkPicture> {
final Map<String, String> headers;

/// The [ColorFilter], if any, to apply to the drawing.
@Deprecated(
'Use a ColorFilter widget instead, or the color parameter on SvgPicture.')
final ColorFilter colorFilter;

@override
Expand Down Expand Up @@ -540,7 +551,7 @@ class FilePicture extends PictureProvider<FilePicture> {
/// Creates an object that decodes a [File] as a picture.
///
/// The arguments must not be null.
const FilePicture(this.decoder, this.file, {this.colorFilter})
const FilePicture(this.decoder, this.file, {@deprecated this.colorFilter})
: assert(decoder != null),
assert(file != null);

Expand All @@ -551,6 +562,8 @@ class FilePicture extends PictureProvider<FilePicture> {
final PictureInfoDecoder<Uint8List> decoder;

/// The [ColorFilter], if any, to use when drawing this picture.
@Deprecated(
'Use a ColorFilter widget instead, or the color parameter on SvgPicture.')
final ColorFilter colorFilter;

@override
Expand Down Expand Up @@ -614,13 +627,15 @@ class MemoryPicture extends PictureProvider<MemoryPicture> {
/// Creates an object that decodes a [Uint8List] buffer as a picture.
///
/// The arguments must not be null.
const MemoryPicture(this.decoder, this.bytes, {this.colorFilter})
const MemoryPicture(this.decoder, this.bytes, {@deprecated this.colorFilter})
: assert(bytes != null);

/// The [PictureInfoDecoder] to use when drawing this picture.
final PictureInfoDecoder<Uint8List> decoder;

/// The [ColorFilter], if any, to use when drawing this picture.
@Deprecated(
'Use a ColorFilter widget instead, or the color parameter on SvgPicture.')
final ColorFilter colorFilter;

/// The bytes to decode into a picture.
Expand Down Expand Up @@ -679,13 +694,15 @@ class StringPicture extends PictureProvider<StringPicture> {
/// Creates an object that decodes a [Uint8List] buffer as a picture.
///
/// The arguments must not be null.
const StringPicture(this.decoder, this.string, {this.colorFilter})
const StringPicture(this.decoder, this.string, {@deprecated this.colorFilter})
: assert(string != null);

/// The [PictureInfoDecoder] to use for decoding this picture.
final PictureInfoDecoder<String> decoder;

/// The [ColorFilter], if any, to use when drawing this picture.
@Deprecated(
'Use a ColorFilter widget instead, or the color parameter on SvgPicture.')
final ColorFilter colorFilter;

/// The string to decode into a picture.
Expand Down Expand Up @@ -817,7 +834,7 @@ class ExactAssetPicture extends AssetBundlePictureProvider {
this.assetName, {
this.bundle,
this.package,
this.colorFilter,
@deprecated this.colorFilter,
}) : assert(assetName != null),
super(decoder);

Expand All @@ -830,6 +847,8 @@ class ExactAssetPicture extends AssetBundlePictureProvider {
package == null ? assetName : 'packages/$package/$assetName';

/// The [ColorFilter], if any, to use when drawing this picture.
@Deprecated(
'Use a ColorFilter widget instead, or the color parameter on SvgPicture.')
final ColorFilter colorFilter;

/// The bundle from which the picture will be obtained.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/svg/parser_state.dart
Expand Up @@ -79,7 +79,7 @@ class _Elements {
static Future<void> svg(SvgParserState parserState) {
final DrawableViewport viewBox = parseViewBox(parserState.attributes);
final String id = parserState.attribute('id', def: '');

// TODO(dnfield): Support nested SVG elements. https://github.com/dnfield/flutter_svg/issues/132
if (parserState._root != null) {
FlutterError.reportError(FlutterErrorDetails(
Expand Down
2 changes: 0 additions & 2 deletions lib/src/vector_drawable.dart
Expand Up @@ -23,7 +23,6 @@ final Paint _grayscaleDstInPaint = Paint()
/// Base interface for vector drawing.
@immutable
abstract class Drawable {

/// A string that should uniquely identify this [Drawable] within its [DrawableRoot].
String get id;

Expand Down Expand Up @@ -859,7 +858,6 @@ class DrawableRoot implements DrawableParent {
this.transform,
});


/// The expected coordinates used by child paths for drawing.
final DrawableViewport viewport;

Expand Down

0 comments on commit c584147

Please sign in to comment.