简体   繁体   中英

Flutter "RangeError (index): Invalid value: Valid value range is empty: 0 with WidgetSpan

I am trying to create the picture below in Flutter. As you can see, I need a link and an image icon. However, I am getting the "range" error in the console.

Here a snippet of my code

Widget build(BuildContext context) {
return Row(
  mainAxisAlignment: MainAxisAlignment.start,
  crossAxisAlignment: CrossAxisAlignment.start,
  children: <Widget>[
      Image.asset(
        "assets/images/checkbox-check.png",
      ),
    Expanded(
      child: Container(
        child: Wrap(
          children: [
            RichText(
              text: new TextSpan(
                children: [
                  TextSpan(
                    text: 'Email opportunities.  ',
                    style: TextStyle(
                        color: Palette.DARK_BLUE, fontSize: 16.0),
                  ),
                  TextSpan(
                    text: 'privacy policy',
                    style: TextStyle(
                        color: Palette.DARK_BLUE,
                        decoration: TextDecoration.underline),
                    recognizer: TapGestureRecognizer()
                      ..onTap = () {
                        launch();
                      },
                  ),
                  TextSpan(
                    text: ' and ',
                    
                  ),
                  TextSpan(
                    text: 'terms of use',
                    style: TextStyle(
                        decoration: TextDecoration.underline),
                    recognizer: TapGestureRecognizer()
                      ..onTap = () {
                        launch();
                      },
                  ),
                  WidgetSpan(
                    child: Icon(
                      Icons.info_outline,
                      color: Colors.red,
                    ),
                  )
                ],
              ),
            ),
          ],
        ),
      ),
    )
  ],
);

} }

Is there another method to create my UI? I don't get an error screen but I see the error in the console. I have a wrap in the widget tree but don't think I need it. but never the less, same issue if I remove it.

在此处输入图片说明

在此处输入图片说明

This is a Flutter issue when you use TextSpan with recognizer together with WidgetSpan: https://github.com/flutter/flutter/issues/51936

A workaround is to wrap RichText in ExcludeSemantics :

ExcludeSemantics(
  excluding: true,
  child: RichText( ... ),
),

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM