如何控制Dart中全局作用域的可见性?

时间:2019-05-10 10:40:50

标签: dart visibility

// api.dart

dynamic publicApi(String address, dynamic payload) {
    ...
}

dynamic login(String email, String password) {
  return publicApi('login', {'email': email, 'password': password});
}

// loginPage.dart

import 'api.dart' as api;
...      
final response = await api.login(emailText.text, pwdText.text);

如何使此源文件仅导出login()而不导出publicApi()?

1 个答案:

答案 0 :(得分:1)

您可以在函数之前添加_,这确实可以帮到您。

dynamic _publicApi(String address, dynamic payload) {
    ...
}

更多信息here