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<String> 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); }
This commit is contained in:
parent
8963525b9a
commit
f0da2a3397
@ -842,7 +842,8 @@ Future<String> login() {
|
||||
// 异步
|
||||
main() async {
|
||||
print('Authenticating please wait...');
|
||||
print(await userName());
|
||||
String result = await login();
|
||||
print(result);
|
||||
}
|
||||
```
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user