0

我创建了一个包含 RichText 的行,在 RichText 中我有 TextSpan,它有 TextSpan 和 WidgetSpan 的子级。

问题:当我尝试在 TextSpan 与 SVG 图像之间添加 WidgetSpan 时,网站将无法加载。如何让 SVG 图像显示在 TextSpan 之间?

当我的网站无法加载并且当我删除 WidgetSpan 时,Flutter 会给我这个错误。

抛出了另一个异常:NoSuchMethodError: '' 抛出了另一个异常:断言失败:file:///Users/ned/Developer/flutter/packages/flutter/lib/src/rendering/box.dart:1694:12 –</ p>

      Row(
        mainAxisAlignment: MainAxisAlignment.start,
        children: <Widget>[
          RichText(
            text:TextSpan(
              children: <InlineSpan> [
                TextSpan(
                  text: 'Or continue with: ',
                  style: TextStyle(color: Color.fromRGBO(85, 85, 85, 1),
                    fontSize: 13, fontWeight: FontWeight.bold,
                  ),
                ),
                WidgetSpan(
                  child: SvgPicture.asset('images/google-icon.svg'),
                  alignment: PlaceholderAlignment.middle,
                ),
                TextSpan(
                  text: 'Google',
                  style: TextStyle(color: Color.fromRGBO(3, 0, 137, 1),
                    fontSize: 13, fontWeight: FontWeight.bold,
                  ),
                  recognizer: TapGestureRecognizer()
                    ..onTap = () { launch(
                        'https://docs.flutter.io/flutter/services/UrlLauncher-class.html'
                    );
                    },
                ),
4

1 回答 1

1

问题是我用于 SVG 的包。更改为 websafe 包后:https : //pub.dev/packages/websafe_svg 并且不使用 RichText、TextSpan、WidgetSpan Widgets 它起作用了 :)

        Row(
        mainAxisAlignment: MainAxisAlignment.start,
        mainAxisSize: MainAxisSize.min,
        children: <Widget>[
          Padding(
            padding: EdgeInsets.only(right: 13.0),
            child: new Text(
              "Or continue with: ",
              style: TextStyle(
                color: Color.fromRGBO(85, 85, 85, 1),
                  fontSize: 13.0, fontWeight: FontWeight.bold),
            ),
          ),
          WebsafeSvg.asset('images/google_icon.svg',
        height: 13.0,
        width: 13.0,
          ),
          Padding(
            padding: EdgeInsets.only(left: 5.0),
            child: GestureDetector(
              child: Text(
                "Google",
                style: TextStyle(
                    color: Color.fromRGBO(3, 0, 137, 1),
                    fontSize: 13.0, fontWeight: FontWeight.bold),
              ),
                onTap: () => launch('https://google.com')
            ),
          ),
        ],
      ),
于 2020-07-02T16:04:36.443 回答