【发布时间】:2023-02-26 11:11:34
【问题描述】:
我想为我的 riverpod_hook 项目创建一个动态小部件,例如
final value = ref.watch(trProvider)
TrText(value : value,fliedName: 'newPassword', placeHolder: 'New Password');
我正在尝试类似的东西
class TrText extends StatelessWidget {
const TrText({
super.key,
required this.value,
required this.fieldName,
required this.placeHolder,
this.textStyle,
});
final AsyncValue<Translation> value;
final TextStyle? textStyle;
final String placeHolder;
final String fieldName;
@override
Widget build(BuildContext context) {
return value.when(
data: (Translation tr) => Text(
tr.fieldName ?? placeHolder,
style: textStyle,
),
error: (error, stackTrace) => Text(placeHolder),
loading: () => const SecondaryLoader(),
);
}
}
我的翻译类代码:
class Translation {
final int? id;
final String? profile;
final String? changePassword;
final String? login;
final String? logout;
final String? oldPassword;
final String? newPassword;
Translation(
{this.id,
this.profile,
this.changePassword,
this.login,
this.logout,
this.oldPassword,
this.newPassword,
});
}
现在我得到“getter 'fieldName' 没有为类型 'Translation' 定义。”错误。
【问题讨论】: