dart 有人能帮我解决我的问题吗

tcomlyy6  于 2023-09-28  发布在  其他
关注(0)|答案(1)|浏览(112)
void main() async {
  int myDelay = 5;
  print('Hello');
  var value = await _customDelay(myDelay);
  var customText = myDelay == 1 ? "second later" : "seconds later";
  print('Its $value $customText');
}

Future<int> _customDelay(int delay) async {
  try {
    await Future.delayed(Duration(seconds: delay));
    return delay;
  } catch (e) {
    print(e);
    return delay;
  }
}

它不显示在调试控制台或在我的输出,我已经找到了我的文件夹,但仍然不工作

qij5mzcb

qij5mzcb1#

试试这个:

Future<void> main() async {
  print("Hello");
  const int myDelay = 5;
  await _customDelay(myDelay);
  print('Its $myDelay ${myDelay == 1 ? "second" : "seconds"} later');
}

Future<void> _customDelay(int delay) async {
  return Future<void>.value(Future<void>.delayed(Duration(seconds: delay)));
}

相关问题