【问题标题】:Pass params to stateless widget in Flutter将参数传递给 Flutter 中的无状态小部件
【发布时间】:2021-01-27 07:06:55
【问题描述】:

我正在尝试为内联文本链接做一个无状态小部件。

我在这里使用这个答案https://stackoverflow.com/a/55607224/3808307 来创建链接

RichText(
  text: TextSpan(
    children: [
      TextSpan(text: 'This is a going to be a Text which has '),
      TextSpan(
        text: 'single tap',
        style: style,
        recognizer: TapGestureRecognizer()
          ..onTap = () {
            // single tapped
          },
      ),
      TextSpan(text: ' along with '),
      TextSpan(
        text: 'double tap',
        style: style,
        recognizer: DoubleTapGestureRecognizer()
          ..onDoubleTap = () {
            // double tapped
          },
      ),
      TextSpan(text: ' and '),
      TextSpan(
        text: 'long press',
        style: style,
        recognizer: LongPressGestureRecognizer()
          ..onLongPress = () {
            // long pressed
          },
      ),
    ],
  ),
)

,但我想要一个可以导入的 TextSpan,并且已经应用​​了样式,并传递了一个可以作为标签和函数的文本。

我需要一个有状态的小部件,还是我可以只使用一个无状态的小部件?

【问题讨论】:

    标签: flutter widget


    【解决方案1】:

    您可以毫无问题地使用无状态小部件。

    如果您需要在点击链接时更改文本样式,则需要使用有状态小部件。

    【讨论】:

      猜你喜欢
      • 2020-12-01
      • 1970-01-01
      • 2019-08-29
      • 2019-08-03
      • 1970-01-01
      • 1970-01-01
      • 2021-10-17
      • 2023-02-05
      相关资源
      最近更新 更多