简介
使用
- 修改
pubspec.yaml
文件,添加依赖flutter_svg
# ...
dev_dependencies:
# ...
flutter_svg: ^0.19.0
# ...
-
在根目录下新建
assets/
目录 -
在
assets/
目录下新建svg/
目录 -
将项目中用到的
svg
放到assets/svg/
目录下 -
修改
pubspec.yaml
文件,添加svg
目录
# ...
flutter:
# ...
assets:
- assets/svg/
# ...
# ...
- 修改
lib/utils/utils.dart
文件
import 'package:flutter_svg/flutter_svg.dart';
class Utils {
static String svgPath(String svgName) {
return "assets/svg/$svgName";
}
static SvgPicture svg(String svgName, {double width, double height}) {
var name = svgName;
if (name.endsWith(".svg") == false) {
name = "$svgName.svg";
}
return SvgPicture.asset(Utils.svgPath(name), width: width, height: height,);
}
}
- 代码中使用
Utils.svg("share", width: 44, height: 44)
发表评论