Skip to content

Instantly share code, notes, and snippets.

@yuki2021
Created May 24, 2023 06:59
Show Gist options
  • Save yuki2021/3d3913d8282673513a75ce8f0f48b612 to your computer and use it in GitHub Desktop.
Save yuki2021/3d3913d8282673513a75ce8f0f48b612 to your computer and use it in GitHub Desktop.
Completerの使い方の例
import 'dart:async';
void main() async {
Completer completer = Completer<String>();
// 非同期処理を開始します(ここでは2秒待つだけ)
Future.delayed(Duration(seconds: 2)).then((_) {
// 非同期処理が完了したらCompleterを完成させます
completer.complete("Hello, World!");
});
// Completerの結果を待ちます
print(await completer.future); // "Hello, World!"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment