首页 > 解决方案 > 如何将 Dart 中的命名参数传递给另一个班级讲师?

问题描述

例如我有一个用户类

class User {
 String name;
 String address;
 String weaponId;
 String weaponMerchant;
 Date weaponExpiration;

 Weapon weapon;

 User({this.name, this.address, this.weaponId, this.weaponMerchant, this.weaponExpiration}) {
  weapon = new Weapon(weaponId: weaponId, weaponMerchant: weaponMerchant, weaponExpiration: weaponExpiration);
 }
}

class Weapon {
 String id;
 
 Weapon({this.id, this.weaponId, this.weaponMerchant, this.weaponExpiration});
}

飞镖中有什么方法可以使用扩展运算符或任何东西,这样我就不需要一个一个地传递这些属性?

weapon = new Weapon(weaponId: weaponId, weaponMerchant: weaponMerchant, weaponExpiration: weaponExpiration);

标签: dart

解决方案


推荐阅读