Skip to content

Commit 48311b0

Browse files
committed
feat(xdg_icons): replace flutter_svg dependency with jovial_svg
This allows using SVG icons that have for example the <style> attribute set. An example of an icon theme using this is KDE's Breeze. flutter_svg doesn't support this and without it Breeze's dark icons would render as black even though they're supposed to be white. See dnfield/flutter_svg#105 for context.
1 parent 55c3a2a commit 48311b0

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

packages/xdg_icons/lib/src/icon.dart

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import 'dart:async';
2+
import 'dart:convert';
23
import 'dart:io';
34
import 'dart:typed_data';
45

56
import 'package:flutter/widgets.dart';
6-
import 'package:flutter_svg/flutter_svg.dart';
7+
import 'package:jovial_svg/jovial_svg.dart';
78
import 'package:path/path.dart' as path;
89

910
import 'package:xdg_icons/src/data.dart';
@@ -131,15 +132,31 @@ class XdgIconState extends State<XdgIcon> {
131132
final file = File(_icon?.fileName ?? '');
132133
final size = _resolveSize();
133134
if (file.existsSync()) {
134-
final builder = _icon!.isScalable ? SvgPicture.file : Image.file;
135-
return builder(
135+
if (_icon!.isScalable) {
136+
return ScalableImageWidget.fromSISource(
137+
si: ScalableImageSource.fromSvgFile(
138+
file.path,
139+
file.readAsString,
140+
),
141+
);
142+
}
143+
144+
return Image.file(
136145
file,
137146
width: size.toDouble(),
138147
height: size.toDouble(),
139148
);
140149
} else if (_icon?.data != null) {
141-
final builder = _icon!.isScalable ? SvgPicture.memory : Image.memory;
142-
return builder(
150+
if (_icon!.isScalable) {
151+
return ScalableImageWidget.fromSISource(
152+
si: ScalableImageSource.fromSvgFile(
153+
file.path,
154+
() => utf8.decode(_icon!.data!),
155+
),
156+
);
157+
}
158+
159+
return Image.memory(
143160
Uint8List.fromList(_icon!.data!),
144161
width: size.toDouble(),
145162
height: size.toDouble(),

packages/xdg_icons/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ dependencies:
1616
collection: ^1.18.0
1717
flutter:
1818
sdk: flutter
19-
flutter_svg: ^2.0.10+1
19+
jovial_svg: ^1.1.25
2020
mocktail: ^1.0.0
2121
path: ^1.9.0
2222
plugin_platform_interface: ^2.1.2

0 commit comments

Comments
 (0)