[flutter_svg] feat: Expose the colorMapper property in SvgPicture (#9043)
## Description
This pull request exposes the existing colorMapper functionality in the flutter_svg package, allowing developers to customize SVG colors during parsing.
## Related Issue
- https://github.com/flutter/flutter/issues/158634
## Motivation
The colorMapper functionality was already present within the flutter_svg package but was not directly accessible through the SvgPicture constructors. By exposing this property, developers gain a powerful and flexible way to dynamically modify the colors of SVG assets based on custom logic. This can be useful for various scenarios, such as theming or branding.
## Example Usage
```dart
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
const String svgString = '''
<svg viewBox="0 0 100 100">
<rect width="50" height="50" fill="#FF0000" />
<circle cx="75" cy="75" r="25" fill="#00FF00" />
</svg>
''';
class MyColorMapper extends ColorMapper {
const MyColorMapper();
@override
Color substitute(
String? id, String elementName, String attributeName, Color color) {
if (color == const Color(0xFFFF0000)) {
return Colors.blue;
}
if (color == const Color(0xFF00FF00)) {
return Colors.yellow;
}
return color;
}
}
void main() {
runApp(MaterialApp(
home: Scaffold(
body: Center(
child: SvgPicture.string(
svgString,
width: 200,
height: 200,
colorMapper: const MyColorMapper(),
),
),
),
));
}
```
[flutter_svg] Initial import
Imports https://github.com/dnfield/flutter_svg into this repository,
with history, and updates it to follow repository conventions:
- Updates min SDKs.
- Removes analysis options and fixes resulting warnings.
- Autoformats.
- Updates pubspecs to follow repo standard.
- Updates repo tooling to allow the flutter_svg_test non-dev
dependency on flutter_test.
- Adds repo metadata.
- Adds METADATA files.
- Adds commemoration to README.
- Updates example app Android build files to current standards.
- Bumps versions and slightly relax version constraints for
vector_graphics* to allow the new versions.
- Moves gitignore of golden test diffs into the package.
[all] Omit obvious local types (#10511)
Makes the analysis options changes described in
https://github.com/flutter/flutter/issues/178827:
- Adding
[omit_obvious_local_variable_types](https://dart.dev/tools/linter-rules/omit_obvious_local_variable_types)
- Adding
[specify_nonobvious_local_variable_types](https://dart.dev/tools/linter-rules/specify_nonobvious_local_variable_types)
- Adding
[specify_nonobvious_property_types](https://dart.dev/tools/linter-rules/specify_nonobvious_property_types)
- Adding
[type_annotate_public_apis](https://dart.dev/tools/linter-rules/type_annotate_public_apis)
- Removing
[always_specify_types](https://dart.dev/tools/linter-rules/always_specify_types)
After those changes, makes the following repo-wide changes:
- dart fix --apply in all packages and in script/tool/
- dart format in all packages and in script/tool/
- update-excerpts repo tooling command to update excerpts based on the
changes to their sources
Also updates the min Flutter/Dart SDK version to 3.35/3.9 for the
following packages, to avoid analyze failures in the N-2 legacy
analysis run due to what appears to be a 3.9 change in what the Dart
analyzer continues to be an obvious local type in loop iterations:
- go_router
- google_fonts
- google_identity_services_web
- google_maps_flutter_web
- local_auth_platform_interface
- metrics_center
- multicast_dns
- pigeon
- rfw
- shared_preferences
- two_dimensional_scrollables
- vector_graphics_compiler
- mustache_template
- path_parsing
Because this is causing a significant amount of format churn already, I
took this opportunity to update the repository tooling to a min Dart SDK
of 3.8 (the N-2 stable version, so the earliest version we need the
tooling to support) to pick up the new format style, so the amount of
automated formatter change is higher in script/tool/ than in the
packages.
This does contain two manual changes (other than the repo tooling min
version):
-
https://github.com/flutter/packages/commit/d700b45c7df3a79f66dc119ad36dd2bc1e042acf
changes dynamic to Object? in a few places where dynamic caused
analyzer warnings under the new rule set.
- Updates the repo tooling to ignore .dart_tool/ when looking for
unexpected local analysis_options.yaml files, to fix issues running
the repo tool's analyze command locally based on recent changes in
dart behavior.
This does not include any CHANGELOG or version updates; even though we
normally version any changes to production code, mass automated changes
like this aren't worth the churn of releasing. This includes changes to
lib/example/main.dart and to README.md excerpts; while the style changes
will be user-visible on pub.dev, it's fine for those changes to wait for
the next release of each package.
Part of https://github.com/flutter/flutter/issues/178827
[all] Omit obvious local types (#10511)
Makes the analysis options changes described in
https://github.com/flutter/flutter/issues/178827:
- Adding
[omit_obvious_local_variable_types](https://dart.dev/tools/linter-rules/omit_obvious_local_variable_types)
- Adding
[specify_nonobvious_local_variable_types](https://dart.dev/tools/linter-rules/specify_nonobvious_local_variable_types)
- Adding
[specify_nonobvious_property_types](https://dart.dev/tools/linter-rules/specify_nonobvious_property_types)
- Adding
[type_annotate_public_apis](https://dart.dev/tools/linter-rules/type_annotate_public_apis)
- Removing
[always_specify_types](https://dart.dev/tools/linter-rules/always_specify_types)
After those changes, makes the following repo-wide changes:
- dart fix --apply in all packages and in script/tool/
- dart format in all packages and in script/tool/
- update-excerpts repo tooling command to update excerpts based on the
changes to their sources
Also updates the min Flutter/Dart SDK version to 3.35/3.9 for the
following packages, to avoid analyze failures in the N-2 legacy
analysis run due to what appears to be a 3.9 change in what the Dart
analyzer continues to be an obvious local type in loop iterations:
- go_router
- google_fonts
- google_identity_services_web
- google_maps_flutter_web
- local_auth_platform_interface
- metrics_center
- multicast_dns
- pigeon
- rfw
- shared_preferences
- two_dimensional_scrollables
- vector_graphics_compiler
- mustache_template
- path_parsing
Because this is causing a significant amount of format churn already, I
took this opportunity to update the repository tooling to a min Dart SDK
of 3.8 (the N-2 stable version, so the earliest version we need the
tooling to support) to pick up the new format style, so the amount of
automated formatter change is higher in script/tool/ than in the
packages.
This does contain two manual changes (other than the repo tooling min
version):
-
https://github.com/flutter/packages/commit/d700b45c7df3a79f66dc119ad36dd2bc1e042acf
changes dynamic to Object? in a few places where dynamic caused
analyzer warnings under the new rule set.
- Updates the repo tooling to ignore .dart_tool/ when looking for
unexpected local analysis_options.yaml files, to fix issues running
the repo tool's analyze command locally based on recent changes in
dart behavior.
This does not include any CHANGELOG or version updates; even though we
normally version any changes to production code, mass automated changes
like this aren't worth the churn of releasing. This includes changes to
lib/example/main.dart and to README.md excerpts; while the style changes
will be user-visible on pub.dev, it's fine for those changes to wait for
the next release of each package.
Part of https://github.com/flutter/flutter/issues/178827
[all] Omit obvious local types (#10511)
Makes the analysis options changes described in
https://github.com/flutter/flutter/issues/178827:
- Adding
[omit_obvious_local_variable_types](https://dart.dev/tools/linter-rules/omit_obvious_local_variable_types)
- Adding
[specify_nonobvious_local_variable_types](https://dart.dev/tools/linter-rules/specify_nonobvious_local_variable_types)
- Adding
[specify_nonobvious_property_types](https://dart.dev/tools/linter-rules/specify_nonobvious_property_types)
- Adding
[type_annotate_public_apis](https://dart.dev/tools/linter-rules/type_annotate_public_apis)
- Removing
[always_specify_types](https://dart.dev/tools/linter-rules/always_specify_types)
After those changes, makes the following repo-wide changes:
- dart fix --apply in all packages and in script/tool/
- dart format in all packages and in script/tool/
- update-excerpts repo tooling command to update excerpts based on the
changes to their sources
Also updates the min Flutter/Dart SDK version to 3.35/3.9 for the
following packages, to avoid analyze failures in the N-2 legacy
analysis run due to what appears to be a 3.9 change in what the Dart
analyzer continues to be an obvious local type in loop iterations:
- go_router
- google_fonts
- google_identity_services_web
- google_maps_flutter_web
- local_auth_platform_interface
- metrics_center
- multicast_dns
- pigeon
- rfw
- shared_preferences
- two_dimensional_scrollables
- vector_graphics_compiler
- mustache_template
- path_parsing
Because this is causing a significant amount of format churn already, I
took this opportunity to update the repository tooling to a min Dart SDK
of 3.8 (the N-2 stable version, so the earliest version we need the
tooling to support) to pick up the new format style, so the amount of
automated formatter change is higher in script/tool/ than in the
packages.
This does contain two manual changes (other than the repo tooling min
version):
-
https://github.com/flutter/packages/commit/d700b45c7df3a79f66dc119ad36dd2bc1e042acf
changes dynamic to Object? in a few places where dynamic caused
analyzer warnings under the new rule set.
- Updates the repo tooling to ignore .dart_tool/ when looking for
unexpected local analysis_options.yaml files, to fix issues running
the repo tool's analyze command locally based on recent changes in
dart behavior.
This does not include any CHANGELOG or version updates; even though we
normally version any changes to production code, mass automated changes
like this aren't worth the churn of releasing. This includes changes to
lib/example/main.dart and to README.md excerpts; while the style changes
will be user-visible on pub.dev, it's fine for those changes to wait for
the next release of each package.
Part of https://github.com/flutter/flutter/issues/178827
[various] Updates min SDK for third_party/packages to 3.29 (#9819)
For all packages in third_party/:
- Updates the min SDK version to 3.29
- Runs the autoformatter with the new format
- Runs the code-excerpt tool to pick up format changes
This does not update versions because pushing format changes (even in READMEs) isn't worth doing a release that drops an SDK version (which we don't normally version)
Prep for https://github.com/flutter/packages/pull/9816
[all] Omit obvious local types (#10511)
Makes the analysis options changes described in
https://github.com/flutter/flutter/issues/178827:
- Adding
[omit_obvious_local_variable_types](https://dart.dev/tools/linter-rules/omit_obvious_local_variable_types)
- Adding
[specify_nonobvious_local_variable_types](https://dart.dev/tools/linter-rules/specify_nonobvious_local_variable_types)
- Adding
[specify_nonobvious_property_types](https://dart.dev/tools/linter-rules/specify_nonobvious_property_types)
- Adding
[type_annotate_public_apis](https://dart.dev/tools/linter-rules/type_annotate_public_apis)
- Removing
[always_specify_types](https://dart.dev/tools/linter-rules/always_specify_types)
After those changes, makes the following repo-wide changes:
- dart fix --apply in all packages and in script/tool/
- dart format in all packages and in script/tool/
- update-excerpts repo tooling command to update excerpts based on the
changes to their sources
Also updates the min Flutter/Dart SDK version to 3.35/3.9 for the
following packages, to avoid analyze failures in the N-2 legacy
analysis run due to what appears to be a 3.9 change in what the Dart
analyzer continues to be an obvious local type in loop iterations:
- go_router
- google_fonts
- google_identity_services_web
- google_maps_flutter_web
- local_auth_platform_interface
- metrics_center
- multicast_dns
- pigeon
- rfw
- shared_preferences
- two_dimensional_scrollables
- vector_graphics_compiler
- mustache_template
- path_parsing
Because this is causing a significant amount of format churn already, I
took this opportunity to update the repository tooling to a min Dart SDK
of 3.8 (the N-2 stable version, so the earliest version we need the
tooling to support) to pick up the new format style, so the amount of
automated formatter change is higher in script/tool/ than in the
packages.
This does contain two manual changes (other than the repo tooling min
version):
-
https://github.com/flutter/packages/commit/d700b45c7df3a79f66dc119ad36dd2bc1e042acf
changes dynamic to Object? in a few places where dynamic caused
analyzer warnings under the new rule set.
- Updates the repo tooling to ignore .dart_tool/ when looking for
unexpected local analysis_options.yaml files, to fix issues running
the repo tool's analyze command locally based on recent changes in
dart behavior.
This does not include any CHANGELOG or version updates; even though we
normally version any changes to production code, mass automated changes
like this aren't worth the churn of releasing. This includes changes to
lib/example/main.dart and to README.md excerpts; while the style changes
will be user-visible on pub.dev, it's fine for those changes to wait for
the next release of each package.
Part of https://github.com/flutter/flutter/issues/178827