Skip to content

Commit 505a182

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 0f41586 commit 505a182

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

packages/xdg_icons/lib/src/icon.dart

Lines changed: 30 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,39 @@ 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 SizedBox(
137+
width: size.toDouble(),
138+
height: size.toDouble(),
139+
child: ScalableImageWidget.fromSISource(
140+
si: ScalableImageSource.fromSvgFile(
141+
file.path,
142+
file.readAsStringSync,
143+
),
144+
),
145+
);
146+
}
147+
148+
return Image.file(
136149
file,
137150
width: size.toDouble(),
138151
height: size.toDouble(),
139152
);
140153
} else if (_icon?.data != null) {
141-
final builder = _icon!.isScalable ? SvgPicture.memory : Image.memory;
142-
return builder(
154+
if (_icon!.isScalable) {
155+
return SizedBox(
156+
width: size.toDouble(),
157+
height: size.toDouble(),
158+
child: ScalableImageWidget.fromSISource(
159+
si: ScalableImageSource.fromSvgFile(
160+
file.path,
161+
() => utf8.decode(_icon!.data!),
162+
),
163+
),
164+
);
165+
}
166+
167+
return Image.memory(
143168
Uint8List.fromList(_icon!.data!),
144169
width: size.toDouble(),
145170
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)