Commit e0892ae
authored
## Description
This pull request exposes the existing `colorMapper` functionality in the `flutter_svg` package, allowing developers to customize SVG colors during parsing.
## Related Issue
- flutter/flutter#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(),
),
),
),
));
}
```
1 parent fdc1ec7 commit e0892ae
File tree
11 files changed
+248
-4
lines changed- third_party/packages/flutter_svg
- example/lib
- lib
- test
- golden_widget
11 files changed
+248
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
| 81 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
1 | 5 | | |
2 | 6 | | |
3 | 7 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
36 | 83 | | |
37 | 84 | | |
38 | 85 | | |
| |||
67 | 114 | | |
68 | 115 | | |
69 | 116 | | |
| 117 | + | |
70 | 118 | | |
71 | 119 | | |
72 | 120 | | |
| |||
Lines changed: 40 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
101 | 102 | | |
102 | 103 | | |
103 | 104 | | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
195 | 195 | | |
196 | 196 | | |
197 | 197 | | |
| 198 | + | |
198 | 199 | | |
199 | 200 | | |
200 | 201 | | |
| |||
205 | 206 | | |
206 | 207 | | |
207 | 208 | | |
| 209 | + | |
208 | 210 | | |
209 | 211 | | |
210 | 212 | | |
| |||
261 | 263 | | |
262 | 264 | | |
263 | 265 | | |
| 266 | + | |
264 | 267 | | |
265 | 268 | | |
266 | 269 | | |
267 | 270 | | |
268 | 271 | | |
| 272 | + | |
269 | 273 | | |
270 | 274 | | |
271 | 275 | | |
| |||
319 | 323 | | |
320 | 324 | | |
321 | 325 | | |
| 326 | + | |
322 | 327 | | |
323 | | - | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
324 | 333 | | |
325 | 334 | | |
326 | 335 | | |
| |||
369 | 378 | | |
370 | 379 | | |
371 | 380 | | |
| 381 | + | |
372 | 382 | | |
373 | | - | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
374 | 388 | | |
375 | 389 | | |
376 | 390 | | |
| |||
419 | 433 | | |
420 | 434 | | |
421 | 435 | | |
| 436 | + | |
422 | 437 | | |
423 | | - | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
424 | 443 | | |
425 | 444 | | |
426 | 445 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
0 commit comments