【发布时间】:2019-12-10 19:47:58
【问题描述】:
我想做一个非常通用的小部件,我可以给它我想要的任何对象。在这个小部件中,根据我给它的对象,我需要用一个文本小部件来表示对象。我的问题是我要使用的对象没有所有相同的成员名称。假设在一种情况下,我要给对象 Carrot,在这种情况下,我想在文本小部件中显示名为“name”的成员,但在另一种情况下,我可以给它对象模板,在这种情况下,我想显示会员“代码”。它们总是字符串类型。因此,在小部件中,“标题”部分将替换为我要显示的内容。
class DialogDropdown extends StatelessWidget with TextStylesHelper{
final SizingInformation _sizeInfo;
final Function _onChanged;
final List _objectList;
DialogDropdown(
this._sizeInfo,
this._onChanged,
this._objectList,
);
@override
Widget build(BuildContext context) {
return Dialog(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10.0)),
child: ListView.separated(
itemBuilder: (context, index) {
var item = _objectList[index];
return ListTile(
title: Text('titre', style: labelTextStyle(_sizeInfo.scaleFactor),),
onTap: (){
Navigator.pop(context, item);
},
);
},
separatorBuilder: (context, index) => Divider(
thickness: 1.5,
height: _sizeInfo.screenSize.height / 40,
),
itemCount: _objectList.length,
),
);
}
}
希望你能帮助我。
【问题讨论】: