小编Pav*_*sha的帖子

Dart 中的 Kotlin `apply()` 方法模拟

我希望能够apply()在 Dart 中使用 Kotlin 做类似的事情。例如在科特林中

var userDetails: UserDetails = userRepo.getUser().apply{
    //here 'this' is UserDetails so all the further calls are made in that context
    name = "Name"
    email = "email@test.com"
    callSomeInnerMethodOfUserDetails()
};
Run Code Online (Sandbox Code Playgroud)

Dart 语言是否有类似的方法或方式?

我想知道标准库或语言本身是否有一些东西,而不是我自己的通用闭包扩展用于这种目的?

谢谢。

android dart kotlin flutter

8
推荐指数
1
解决办法
1667
查看次数

标签 统计

android ×1

dart ×1

flutter ×1

kotlin ×1