我有一个下拉菜单,当我选择一个或多个项目时,它将显示一张卡或一张卡列表,如图像中的第一个,但是当我有两张卡并按编辑时,就会出现问题按钮,两张卡片都将在图像的第二部分更改。
这是我目前正在执行的代码。这些列表是在Change的下拉菜单上创建的。
List<Widget> _prepareTechnologies(List<Technology> _techList, List<TextEditingController> _textControllers){
List<Widget> widgets = new List();
final size = MediaQuery.of(context).size;
for(var i=0; i<_techList.length;i++){
widgets.add(
Container(
padding: EdgeInsets.fromLTRB(10.0, 10.0, 10.0, 10.0),
height: size.height*0.1,
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(color: Colors.black38),
boxShadow: <BoxShadow>[
BoxShadow(
color: Colors.black26,
)
]
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
CircleAvatar(
radius:28,
backgroundImage: AssetImage('assets/no-image.png'),
),
SizedBox(width: 8.0),
Text(_techList[i].technology, style: TextStyle(color: Colors.blue, fontSize: 20),),
Expanded(child: SizedBox(),),
Align(alignment: Alignment.center, child: Text('Dominio',)),
SizedBox(width: 5.0),
(_boolValues[i]) ? _savedDomain(_textControllers[i],_boolValues, _techList[i].technologyId, _boolValues2[i]):_domainPercentage(_textControllers[i], _boolValues, _techList[i].technologyId, _boolValues2[i]) ,
],
),
)
);
widgets.add(SizedBox(height:10.0));
}
return widgets;
}
Widget _domainPercentage(TextEditingController _controller, bool value, String tech, bool value2){
return Row(
children: <Widget>[
Container(
padding: EdgeInsets.only(left:6,),
height: 24,
width: 45,
decoration: BoxDecoration(
border: Border(
top: BorderSide(color: Colors.grey),
bottom: BorderSide(color: Colors.grey),
left: BorderSide(color: Colors.grey),
),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Flexible(
child: TextFormField(
controller: _controller,
onChanged: (value){
setState(() {
value2=!value2;
});
},
style: TextStyle(fontSize: 14),
textAlign: TextAlign.center ,
keyboardType: TextInputType.number,
inputFormatters: [
BlacklistingTextInputFormatter(RegExp('[.]')),
LengthLimitingTextInputFormatter(3)
],
decoration: InputDecoration(
focusedBorder: InputBorder.none,
enabledBorder: InputBorder.none,
),
),
),
Text('%'),
],
)
),
GestureDetector(
onTap: (value2) ? () => _registerTechnology(_controller, tech, value) : null,
child: Container(
height: 24,
decoration: BoxDecoration(
border: Border.all(color: Colors.orangeAccent)
),
child: Icon(Icons.edit, color: Colors.orangeAccent,),
),
)
],
);
}
Widget _savedDomain(TextEditingController _controller,bool value, String tech, bool value2){
return Row(
children: <Widget>[
Container(
padding: EdgeInsets.only(left:3,),
height: 45,
width: 50,
child: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Flexible(
child: TextFormField(
controller: _controller,
onChanged: (value){
setState(() {
value2=!value2;
});
},
style: TextStyle(fontSize: 20, color: Colors.green),
textAlign: TextAlign.center ,
keyboardType: TextInputType.number,
inputFormatters: [
BlacklistingTextInputFormatter(RegExp('[.]')),
LengthLimitingTextInputFormatter(3)
],
decoration: InputDecoration(
hintText: '0',
focusedBorder: InputBorder.none,
enabledBorder: InputBorder.none,
),
),
),
Text('%', style: TextStyle(fontSize:20, color: Colors.green),),
],
)
),
GestureDetector(
onTap: (value2) ? () => _registerTechnology(_controller, tech, value) : null,
child: Container(
height: 24,
child: Icon(Icons.edit, color: Colors.grey,),
),
)
],
);
}
void _registerTechnology(TextEditingController _controller, String tech, bool value)async{
final result = await widget.studentProvider.registerTechnology(widget.student.userId, tech, int.parse(_controller.text));
print(result);
if(result =='ok'){
setState(() {
value=!value;
});
}
任何建议,评论或想法都将受到欢迎,因为我也想提高自己的开发技能。 预先感谢