Flutter:致命错误:回调查找失败!(带有音频播放器包) [英] Flutter: Fatal Error: Callback lookup failed! (with audioplayers package)

查看:63
本文介绍了Flutter:致命错误:回调查找失败!(带有音频播放器包)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的代码段是单击该按钮的按钮,会发出一声短促的哔哔声:

The following snippet is the button by clicking which, a short beep plays:

FlatButton(
  onPressed: () => {
    final player = new AudioCache();
    player.play('note1.wav');
  }
  child: Text('Click to ding!'),
),

我面临的问题是每当我单击此按钮时,尽管声音正确播放,但在终端中却出现此错误: flutter:致命错误:回调查找失败!我想知道它是什么,我应该怎么做?

The problem I'm facing is whenever I click this button, although sound plays correctly, I get this error in terminal: flutter: Fatal Error: Callback lookup failed! I wanna know what it is and what I should do?

我检查了程序包的问题页面,但没有发现任何帮助.

I checked the package's issue page but didn't find anything helpful.

谢谢

推荐答案

看起来像一个致命错误:回调查找失败!"的错误.如果未通过 monitorNotificationStateChanges 定义回调方法,则会在日志中打印.

Looks like a bug where "Fatal Error: Callback lookup failed!" is printed in the logs if no callback method was defined via monitorNotificationStateChanges.

通过阅读源代码像这样没有任何发生.

By reading the source code it seems like this doesn't have any incidence.

但是要避免这种情况的一种方法确实是设置该回调,并且必须在类的外部中对其进行定义,如下所示:

But a way to avoid it is indeed to set that callback, and it has to be defined outside your class like so:

import 'package:audioplayers/audioplayers.dart';

class YourStatefulWidget extends StatefulWidget {
  @override
  _YourStatefulWidgetState createState() => _YourStatefulWidgetState();
}

class _YourStatefulWidgetState extends State<YourStatefulWidget> {
  ...

  @override
  void initState() {
    super.initState();

    if (Platform.isIOS) {
      // to avoid getting "Fatal Error: Callback lookup failed!"
      audioPlayer.monitorNotificationStateChanges(audioPlayerHandler);    
    }
  }

  ...
}

// must be defined globally
void audioPlayerHandler(AudioPlayerState value) => null;

这篇关于Flutter:致命错误:回调查找失败!(带有音频播放器包)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆