Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dart.md Fix bug in asynchronous login example #814

Merged
merged 1 commit into from
Aug 15, 2024

Conversation

openapphub
Copy link
Contributor

当前行为

当前的异步登录示例代码存在以下问题:

  1. main 函数中尝试使用 await userName(),但 userName 是一个字符串变量,而不是一个函数。
  2. 应该调用 login 函数并使用 await 来等待其结果。

预期行为

main 函数应该正确地调用 login 函数,并使用 await 来等待其结果,然后打印出用户名。

示例代码

以下是修正后的代码:

Future<String> login() {
  String userName = "Temidjoy";
  return Future.delayed(
    Duration(seconds: 4), () => userName
  );
}

main() async {
  print('Authenticating please wait...');
  String result = await login();
  print(result);
}

### 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);
}
@jaywcjlove jaywcjlove merged commit f0da2a3 into jaywcjlove:main Aug 15, 2024
github-actions bot pushed a commit that referenced this pull request Aug 15, 2024
### 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);
} f0da2a3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants