Flutter 无法导入svg颤振

Flutter 无法导入svg颤振,flutter,dart,Flutter,Dart,这是我的代码中几分钟前不存在的错误。sintax是完美的,因此我找不到错误:/ 这是欢迎页面类,我有我的按钮 class WelcomePage extend StatelessWidget{ @override Widget build(BuildContext context){ return Scaffold( body: DefaultSocialButton( screen: screens, txt: 'Facebook',

这是我的代码中几分钟前不存在的错误。sintax是完美的,因此我找不到错误:/

这是欢迎页面类,我有我的按钮

class WelcomePage extend StatelessWidget{
  @override
  Widget build(BuildContext context){
    return Scaffold(
      body: DefaultSocialButton(
        screen: screens,
        txt: 'Facebook',
        style: kWhiteButtonTextStyle,
        color: kFacebookColor,
        direct: kFacebookIcon,
        function: () {},
      ),
    );
 }
}
导入svg目录的常量文件代码

import 'package:flutter/material.dart';

final kWhiteButtonTextStyle = GoogleFonts.lato(
  textStyle: TextStyle(
    fontSize: 22,
    color: kWhiteColor,
    fontWeight: FontWeight.w700,
  ),
);
const kFacebookColor = Color(0xFF1778F2);
const kFacebookIcon = 'assets/icons/facebook.svg';
这是按钮类

class DefaultSocialButton extends StatelessWidget {
  final Size screen;
  final String txt;
  final TextStyle style;
  final String direct;
  final Color color;
  final Function function;

  DefaultSocialButton({
    this.screen,
    this.txt,
    this.style,
    this.color = kBlackColor,
    this.direct,
    this.function,
  });

  _defaultSocialButton() {
    return FlatButton(
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          SvgPicture.asset(
            direct,
            fit: BoxFit.fill,
          ),
          Text(
            txt,
            style: style,
          ),
        ],
      ),
      color: color,
      padding: EdgeInsets.only(
        top: screen.height * 0.02,
        bottom: screen.height * 0.02,
      ),
      onPressed: function,
    );
  }

  @override
  Widget build(BuildContext context) {
    return _defaultSocialButton();
  }
}
下面是错误消息:

发生异常。 FormatException(FormatException:无效的双精度
100%)

字体在很多情况下都是不错的选择

我一直在开发一个在画布上渲染SVG的库,可用

现在的API看起来像

 new SvgPicture.asset(
'assets/images/candle.svg',
 height: 20.0,
 width: 20.0,
 allowDrawingOutsideViewBox: true,
 ),
这是一个你也可以检查的小例子

呈现asset_name.svg(大小与其父级相同,例如大小框)。还可以指定用于为资源着色的颜色和blendMode

现在,它可以在pub上使用,并且最低版本为0.3.6。它可以处理很多情况,但不是所有情况—请参阅GitHub repo以获取更新。

这将帮助您:这是在Flatter中使用自定义svg的更好方法