如果将 RawMaterial 与 Textspan 或识别器一起使用,则 Flutter 将函数传递给无状态小部件不起作用

问题描述

如果我没有传递函数而只是用打印进行测试,它就可以工作。我在小部件上传递了 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)),],),

解决方法

你需要调用函数而不是函数名。

onPressed: () => bannerTap()
,

打字错误,只需要确保自定义小部件不包含(){} functionName 并且只传递属性