Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 飞镖/颤振声音示例中的未来不起作用_Flutter_Dart_Async Await - Fatal编程技术网

Flutter 飞镖/颤振声音示例中的未来不起作用

Flutter 飞镖/颤振声音示例中的未来不起作用,flutter,dart,async-await,Flutter,Dart,Async Await,开始修补飞镖/颤振,我正在尝试录制和播放音频。此库中提供的示例:使用Futures在Dart中显示异步代码 Future<String> result = await flutterSound.startRecorder(null); result.then(path) { print('startRecorder: $path'); _recorderSubscription = flutterSound.onRecorderStateChanged.liste

开始修补飞镖/颤振,我正在尝试录制和播放音频。此库中提供的示例:使用Futures在Dart中显示异步代码

Future<String> result = await flutterSound.startRecorder(null);

result.then(path) {
    print('startRecorder: $path');

    _recorderSubscription = flutterSound.onRecorderStateChanged.listen((e) {
    DateTime date = new DateTime.fromMillisecondsSinceEpoch(e.currentPosition.toInt());
    String txt = DateFormat('mm:ss:SS', 'en_US').format(date);
    });
}
未来结果=等待声音。startRecorder(空);
结果。然后(路径){
打印('startRecorder:$path');
_recorderSubscription=flatterSound.onRecorderStateChanged.listen((e){
DateTime date=新的DateTime.From毫秒新纪元(e.currentPosition.toInt());
字符串txt=DateFormat('mm:ss:ss','en_US')。格式(日期);
});
}
然而,这段代码甚至没有在我的系统中编译,所以我想知道我遗漏了什么。为了编译此代码,我必须将其更改为:

Future<String> result = widget._flutterSound.startRecorder(null);

result.then((path) {
  print('startRecorder: $path');

  var _recorderSubscription = widget._flutterSound.onRecorderStateChanged.listen((e) {
    DateTime date = new DateTime.fromMillisecondsSinceEpoch(e.currentPosition.toInt());
    print(date);
  });
});
Future result=widget.\u.startRecorder(空);
result.then((路径){
打印('startRecorder:$path');
var\u recorderSubscription=widget.\u.onRecorderStateChanged.listen((e){
DateTime date=新的DateTime.From毫秒新纪元(e.currentPosition.toInt());
打印(日期);
});
});
我错过了什么?

你试过这个吗:

Future<String> result() async => flutterSound.startRecorder(null);
Future result()async=>flatterSound.startRecorder(空);
使用futures时:异步并等待:

asyncawait关键字提供了定义异步函数并使用其结果的声明方式。使用异步等待时,请记住以下两条基本准则:

  • 要定义异步函数,请在函数体之前添加async
  • wait关键字仅在async函数中有效