簡體   English   中英

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

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

我正在嘗試在 Flutter 中創建下面的圖片。 如您所見,我需要一個鏈接和一個圖像圖標。 但是,我在控制台中收到“范圍”錯誤。

這是我的代碼片段

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,
                    ),
                  )
                ],
              ),
            ),
          ],
        ),
      ),
    )
  ],
);

} }

是否有另一種方法來創建我的 UI? 我沒有看到錯誤屏幕,但我在控制台中看到了錯誤。 我在小部件樹中有一個包裝,但認為我不需要它。 但同樣的問題,如果我刪除它。

在此處輸入圖片說明

在此處輸入圖片說明

當您將 TextSpan 與識別器與 WidgetSpan 一起使用時,這是一個 Flutter 問題: https : //github.com/flutter/flutter/issues/51936

一種解決方法是將RichText包裝在ExcludeSemantics

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM