【问题标题】:Flutter/Dart - Why would onPressed on my iconButton workFlutter/Dart - 为什么我的 iconButton 上的 onPressed 会起作用
【发布时间】:2021-08-12 13:01:35
【问题描述】:

我在 Flutter 中有以下 IconButton,当 onPressed 时,它会触发音频播放器播放;

  IconButton(
          key: const Key('play_button'),
          onPressed: _play,
          iconSize: 30,
          icon: Icon(PlayerButtons.playbuttonbig),
        ),

但是为什么当我这样做时它会无法播放?

  IconButton(
          key: const Key('play_button'),
          onPressed:(){
            _play;
          },
          iconSize: 30,
          icon: Icon(PlayerButtons.playbuttonbig),
        ),

我需要使用第二个的原因是因为我想在“_play”之前或之后调用另一个函数

【问题讨论】:

    标签: flutter function dart flutter-onpressed


    【解决方案1】:
    IconButton(
              key: const Key('play_button'),
              onPressed:(){
                _play(); //<- call the play function like this
              }, 
              iconSize: 30,
              icon: Icon(PlayerButtons.playbuttonbig),
            ),
    

    【讨论】:

      【解决方案2】:
      IconButton(
            key: const Key('play_button'),
            onPressed:(){
              _play();
            },
            iconSize: 30,
            icon: Icon(PlayerButtons.playbuttonbig),
          ),
      

      如果 _play() 是一个应该可以工作的函数

      【讨论】:

        猜你喜欢
        • 2022-08-23
        • 2018-08-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-02-18
        • 2020-04-02
        • 1970-01-01
        • 2022-10-01
        相关资源
        最近更新 更多