From f0da2a3397bdd279679c345fbdef270d82d4bf60 Mon Sep 17 00:00:00 2001 From: openapphub Date: Thu, 15 Aug 2024 09:09:47 +0800 Subject: [PATCH] doc: update docs/dart.md (#814) ### Current behavior The current asynchronous login sample code has the following issues: 1. The `main` function tries to use `await userName()`, but `userName` is a string variable, not a function. 2. the `login` function should be called and `await` should be used to wait for its result. ### Expected behavior The `main` function should correctly call the `login` function and use `await` to wait for the result, then print out the username. ### Sample code Here is the corrected code: ```dart Future login() { String userName = "Temidjoy"; return Future.delayed( Duration(seconds: 4), () => userName ). } main() async { print('Authenticating please wait...') The String result = await login(); String result = await login(); print(result); } --- docs/dart.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/dart.md b/docs/dart.md index 45a429a6..82a083b7 100644 --- a/docs/dart.md +++ b/docs/dart.md @@ -842,7 +842,8 @@ Future login() { // 异步 main() async { print('Authenticating please wait...'); - print(await userName()); + String result = await login(); + print(result); } ```