簡體   English   中英

Flutter 如果將 RawMaterial 與 Textspan 或識別器一起使用,則將 function 傳遞給無狀態小部件不起作用

[英]Flutter Passing a function to stateless widget not working if using RawMaterial with Textspan or recognizer

如果我沒有通過 function 並且只是使用打印進行測試,它可以工作。 我在小部件上傳遞了 3 個函數,點擊的 CircleAvatar 可以工作,但不能使用 RawMaterial / 按鈕

       RawMaterialButton(
        onPressed: () => bannerTap,//print('raw'),
        child: RichText(
          text: TextSpan(
            //recognizer: TapGestureRecognizer()..onTap  = ()=> print('Text tapped'),
            text: info,
            style: TextStyle(color: Colors.white),
            children: <TextSpan>[
              TextSpan(text: actionMessage, style: TextStyle(fontWeight: FontWeight.bold)),
            ],
          ),

        ),
      ),

您需要調用 function 而不是 function 名稱。

onPressed: () => bannerTap()

錯字,只需要確保自定義小部件不包含(){}函數名,並且只傳遞屬性

暫無
暫無

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

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