From e3cadc1c5f2b56fd3054e952c633d337a0fc6bcb Mon Sep 17 00:00:00 2001 From: Damian Bast Date: Mon, 13 Feb 2023 18:00:59 +0100 Subject: [PATCH 1/2] documentation: Add link to migration guide and remove no-op deprecations and add deprecation messages with suggestions on how to change the code --- README.md | 2 ++ lib/svg.dart | 87 +++++++++++++++++++++++++--------------------- vector_graphics.md | 17 ++++++++- 3 files changed, 66 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index d166a63b..03d974fc 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,8 @@ Draw SVG files using Flutter. +If you are migrating from flutter_svg 1.x to 2.x, please take a look at the [migration document](https://github.com/dnfield/flutter_svg/blob/master/vector_graphics.md) + ## Getting Started This package provides a wrapper around Dart implementations of SVG parsing, diff --git a/lib/svg.dart b/lib/svg.dart index 3e2ca5c2..6f1f9aa9 100644 --- a/lib/svg.dart +++ b/lib/svg.dart @@ -29,29 +29,13 @@ final Svg svg = Svg._(); class Svg { Svg._(); - /// A global override flag for [SvgPicture.cacheColorFilter]. - /// - /// If this is null, the value in [SvgPicture.cacheColorFilter] is used. If it - /// is not null, it will override that value. - @Deprecated('This no longer does anything.') - bool? cacheColorFilterOverride; - /// The cache instance for decoded SVGs. final Cache cache = Cache(); } -// ignore: avoid_classes_with_only_static_members -/// Deprecated class, will be removed, does not do anything. -@Deprecated('This feature does not do anything anymore.') -class PictureProvider { - /// Deprecated, use [svg.cache] instead. - @Deprecated('Use svg.cache instead.') - static Cache get cache => svg.cache; -} - /// A widget that will parse SVG data for rendering on screen. class SvgPicture extends StatelessWidget { - /// Instantiates a widget that renders an SVG picture using the `pictureProvider`. + /// Instantiates a widget that renders an SVG picture using a [BytesLoader]. /// /// Either the [width] and [height] arguments should be specified, or the /// widget should be placed in a context that sets tight layout constraints. @@ -87,8 +71,6 @@ class SvgPicture extends StatelessWidget { this.semanticsLabel, this.excludeFromSemantics = false, this.theme = const SvgTheme(), - @deprecated Clip? clipBehavior, - @deprecated bool cacheColorFilter = false, }) : super(key: key); /// Instantiates a widget that renders an SVG picture from an [AssetBundle]. @@ -182,11 +164,16 @@ class SvgPicture extends StatelessWidget { this.semanticsLabel, this.excludeFromSemantics = false, this.theme = const SvgTheme(), + + /// The [ColorFilter] to apply to the picture. An easy way to add color. + /// e.g. `ColorFilter.mode(Colors.red, BlendMode.srcIn)` ui.ColorFilter? colorFilter, - @deprecated ui.Color? color, - @deprecated ui.BlendMode colorBlendMode = ui.BlendMode.srcIn, - @deprecated Clip? clipBehavior, - @deprecated bool cacheColorFilter = false, + @Deprecated('Use colorFilter: ColorFilter.mode(color, blendMode) instead ' + '- default BlendMode is BlendMode.srcIn )') + ui.Color? color, + @Deprecated('Use colorFilter: ColorFilter.mode(color, blendMode) instead ' + '- default BlendMode is BlendMode.srcIn )') + ui.BlendMode colorBlendMode = ui.BlendMode.srcIn, }) : bytesLoader = SvgAssetLoader( assetName, packageName: package, @@ -239,13 +226,18 @@ class SvgPicture extends StatelessWidget { this.matchTextDirection = false, this.allowDrawingOutsideViewBox = false, this.placeholderBuilder, + + /// The [ColorFilter] to apply to the picture. An easy way to add color. + /// e.g. `ColorFilter.mode(Colors.red, BlendMode.srcIn)` ui.ColorFilter? colorFilter, - @deprecated ui.Color? color, - @deprecated ui.BlendMode colorBlendMode = ui.BlendMode.srcIn, + @Deprecated('Use colorFilter: ColorFilter.mode(color, blendMode) instead ' + '- default BlendMode is BlendMode.srcIn )') + ui.Color? color, + @Deprecated('Use colorFilter: ColorFilter.mode(color, blendMode) instead ' + '- default BlendMode is BlendMode.srcIn )') + ui.BlendMode colorBlendMode = ui.BlendMode.srcIn, this.semanticsLabel, this.excludeFromSemantics = false, - @deprecated Clip? clipBehavior, - @deprecated bool cacheColorFilter = false, this.theme = const SvgTheme(), }) : bytesLoader = SvgNetworkLoader(url, headers: headers, theme: theme), colorFilter = colorFilter ?? _getColorFilter(color, colorBlendMode), @@ -291,14 +283,21 @@ class SvgPicture extends StatelessWidget { this.matchTextDirection = false, this.allowDrawingOutsideViewBox = false, this.placeholderBuilder, + + /// The [ColorFilter] to apply to the picture. An easy way to add color. + /// e.g. `ColorFilter.mode(Colors.red, BlendMode.srcIn)` ui.ColorFilter? colorFilter, - @deprecated ui.Color? color, - @deprecated ui.BlendMode colorBlendMode = ui.BlendMode.srcIn, + @Deprecated('Use colorFilter: ColorFilter.mode(color, blendMode) instead ' + '- default BlendMode is BlendMode.srcIn )') + ui.Color? color, + @Deprecated('Use colorFilter: ColorFilter.mode(color, blendMode) instead ' + '- default BlendMode is BlendMode.srcIn )') + ui.BlendMode colorBlendMode = ui.BlendMode.srcIn, this.semanticsLabel, this.excludeFromSemantics = false, this.theme = const SvgTheme(), - @deprecated Clip? clipBehavior, - @deprecated bool cacheColorFilter = false, + @Deprecated('This has property has been removed') + Clip? clipBehavior, }) : bytesLoader = SvgFileLoader(file, theme: theme), colorFilter = colorFilter ?? _getColorFilter(color, colorBlendMode), super(key: key); @@ -340,14 +339,19 @@ class SvgPicture extends StatelessWidget { this.matchTextDirection = false, this.allowDrawingOutsideViewBox = false, this.placeholderBuilder, + + /// The [ColorFilter] to apply to the picture. An easy way to add color. + /// e.g. `ColorFilter.mode(Colors.red, BlendMode.srcIn)` ui.ColorFilter? colorFilter, - @deprecated ui.Color? color, - @deprecated ui.BlendMode colorBlendMode = ui.BlendMode.srcIn, + @Deprecated('Use colorFilter: ColorFilter.mode(color, blendMode) instead ' + '- default BlendMode is BlendMode.srcIn )') + ui.Color? color, + @Deprecated('Use colorFilter: ColorFilter.mode(color, blendMode) instead ' + '- default BlendMode is BlendMode.srcIn )') + ui.BlendMode colorBlendMode = ui.BlendMode.srcIn, this.semanticsLabel, this.excludeFromSemantics = false, this.theme = const SvgTheme(), - @deprecated Clip? clipBehavior, - @deprecated bool cacheColorFilter = false, }) : bytesLoader = SvgBytesLoader(bytes, theme: theme), colorFilter = colorFilter ?? _getColorFilter(color, colorBlendMode), super(key: key); @@ -389,14 +393,19 @@ class SvgPicture extends StatelessWidget { this.matchTextDirection = false, this.allowDrawingOutsideViewBox = false, this.placeholderBuilder, + + /// The [ColorFilter] to apply to the picture. An easy way to add color. + /// e.g. `ColorFilter.mode(Colors.red, BlendMode.srcIn)` ui.ColorFilter? colorFilter, - @deprecated ui.Color? color, - @deprecated ui.BlendMode colorBlendMode = ui.BlendMode.srcIn, + @Deprecated('Use colorFilter: ColorFilter.mode(color, blendMode) instead ' + '- default BlendMode is BlendMode.srcIn )') + ui.Color? color, + @Deprecated('Use colorFilter: ColorFilter.mode(color, blendMode) instead ' + '- default BlendMode is BlendMode.srcIn )') + ui.BlendMode colorBlendMode = ui.BlendMode.srcIn, this.semanticsLabel, this.excludeFromSemantics = false, this.theme = const SvgTheme(), - @deprecated Clip? clipBehavior, - @deprecated bool cacheColorFilter = false, }) : bytesLoader = SvgStringLoader(string, theme: theme), colorFilter = colorFilter ?? _getColorFilter(color, colorBlendMode), super(key: key); diff --git a/vector_graphics.md b/vector_graphics.md index 46a12682..e1144489 100644 --- a/vector_graphics.md +++ b/vector_graphics.md @@ -61,7 +61,7 @@ SVGs, and the way that Flutter ties together byte acquisition and image decoding makes things a bit complicated. Instead, `vector_graphics` introduces the concept of a `BytesLoader` class, which knows how to obtain encoded bytes to feed to the runtime via an asynchronous method that optionally receives a -`BuildContext`. See the `loaders.dart` file in this package for examples. +`BuildContext`. See the `loaders.dart` file in this package for examples. As of this writing, the optimizations that are available include: @@ -167,3 +167,18 @@ await tester.pump(); to make sure that the image decode(s) finish and the placeholder widget is replaced with the actual picture. + +### Widget testing + +For creating matchers for an svg asset you can use the following as suggested in [#852](https://github.com/dnfield/flutter_svg/issues/852): + +```dart +final findAsset = find.byWidgetPredicate( + (widget) => + widget is SvgPicture && + (widget.bytesLoader as SvgAssetLoader) // Here! + .assetName + .compareTo('assets/flutter.svg') == + 0, +); +``` From 9550aa091f5c710d425e63de460b46d95f9af581 Mon Sep 17 00:00:00 2001 From: Damian Bast Date: Mon, 13 Feb 2023 19:12:28 +0100 Subject: [PATCH 2/2] improve punctuation --- README.md | 2 +- lib/svg.dart | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 03d974fc..00378949 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Draw SVG files using Flutter. -If you are migrating from flutter_svg 1.x to 2.x, please take a look at the [migration document](https://github.com/dnfield/flutter_svg/blob/master/vector_graphics.md) +If you are migrating from flutter_svg 1.x to 2.x, please take a look at the [migration document](https://github.com/dnfield/flutter_svg/blob/master/vector_graphics.md). ## Getting Started diff --git a/lib/svg.dart b/lib/svg.dart index 6f1f9aa9..0dd8df0f 100644 --- a/lib/svg.dart +++ b/lib/svg.dart @@ -169,10 +169,10 @@ class SvgPicture extends StatelessWidget { /// e.g. `ColorFilter.mode(Colors.red, BlendMode.srcIn)` ui.ColorFilter? colorFilter, @Deprecated('Use colorFilter: ColorFilter.mode(color, blendMode) instead ' - '- default BlendMode is BlendMode.srcIn )') + '- default BlendMode is BlendMode.srcIn.') ui.Color? color, @Deprecated('Use colorFilter: ColorFilter.mode(color, blendMode) instead ' - '- default BlendMode is BlendMode.srcIn )') + '- default BlendMode is BlendMode.srcIn.') ui.BlendMode colorBlendMode = ui.BlendMode.srcIn, }) : bytesLoader = SvgAssetLoader( assetName, @@ -231,10 +231,10 @@ class SvgPicture extends StatelessWidget { /// e.g. `ColorFilter.mode(Colors.red, BlendMode.srcIn)` ui.ColorFilter? colorFilter, @Deprecated('Use colorFilter: ColorFilter.mode(color, blendMode) instead ' - '- default BlendMode is BlendMode.srcIn )') + '- default BlendMode is BlendMode.srcIn.') ui.Color? color, @Deprecated('Use colorFilter: ColorFilter.mode(color, blendMode) instead ' - '- default BlendMode is BlendMode.srcIn )') + '- default BlendMode is BlendMode.srcIn.') ui.BlendMode colorBlendMode = ui.BlendMode.srcIn, this.semanticsLabel, this.excludeFromSemantics = false, @@ -288,10 +288,10 @@ class SvgPicture extends StatelessWidget { /// e.g. `ColorFilter.mode(Colors.red, BlendMode.srcIn)` ui.ColorFilter? colorFilter, @Deprecated('Use colorFilter: ColorFilter.mode(color, blendMode) instead ' - '- default BlendMode is BlendMode.srcIn )') + '- default BlendMode is BlendMode.srcIn.') ui.Color? color, @Deprecated('Use colorFilter: ColorFilter.mode(color, blendMode) instead ' - '- default BlendMode is BlendMode.srcIn )') + '- default BlendMode is BlendMode.srcIn.') ui.BlendMode colorBlendMode = ui.BlendMode.srcIn, this.semanticsLabel, this.excludeFromSemantics = false, @@ -344,10 +344,10 @@ class SvgPicture extends StatelessWidget { /// e.g. `ColorFilter.mode(Colors.red, BlendMode.srcIn)` ui.ColorFilter? colorFilter, @Deprecated('Use colorFilter: ColorFilter.mode(color, blendMode) instead ' - '- default BlendMode is BlendMode.srcIn )') + '- default BlendMode is BlendMode.srcIn.') ui.Color? color, @Deprecated('Use colorFilter: ColorFilter.mode(color, blendMode) instead ' - '- default BlendMode is BlendMode.srcIn )') + '- default BlendMode is BlendMode.srcIn.') ui.BlendMode colorBlendMode = ui.BlendMode.srcIn, this.semanticsLabel, this.excludeFromSemantics = false, @@ -398,10 +398,10 @@ class SvgPicture extends StatelessWidget { /// e.g. `ColorFilter.mode(Colors.red, BlendMode.srcIn)` ui.ColorFilter? colorFilter, @Deprecated('Use colorFilter: ColorFilter.mode(color, blendMode) instead ' - '- default BlendMode is BlendMode.srcIn )') + '- default BlendMode is BlendMode.srcIn.') ui.Color? color, @Deprecated('Use colorFilter: ColorFilter.mode(color, blendMode) instead ' - '- default BlendMode is BlendMode.srcIn )') + '- default BlendMode is BlendMode.srcIn.') ui.BlendMode colorBlendMode = ui.BlendMode.srcIn, this.semanticsLabel, this.excludeFromSemantics = false,