我在我的第一个屏幕上有一个List_view,其标题填充了一个字符串列表,通过点击list_view的每个项目,显示一个新页面,计算一个值并将该值发送回第一个屏幕,我需要这个计算值只显示在列表视图的选定项目的副标题上,而不是我的代码中发生的所有字幕!我该怎么办?
这是我的第一个屏幕的List_view
:
ListView.builder(
itemCount: MyList.length,
itemBuilder: (context, position){
return Card(
child:ListTile(
title:Padding(
padding: const EdgeInsets.all(5.0),
child: Text(
MyList.isEmpty ? "click button to add movement": selectedMovementList.elementAt(position), style: TextStyle(fontSize: 16.0),),
),
//Here is my problem!!!!!!!
subtitle: Text(subTileInfoText),
trailing:Icon(Icons.arrow_right),
onTap:() {
_awaitReturnValueFromDetailScreen(context,position);
},
),
);
}
void _awaitReturnValueFromDetailScreen(BuildContext context,int position) async {
// start the SecondScreen and wait for it to finish with a result
final result = await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => detailMovementEntry(selectedMovementList.elementAt(position)),
));
// after the SecondScreen result comes back update the Text widget with it
setState(() {
subTileInfoText = result;
});
}
这是我的第二个屏幕发送回数据:
RaisedButton(
child: const Text('Save'),
onPressed: (){
_sendDataBack(context);
},)
void _sendDataBack(BuildContext context) {
String textToSendBack = "SomeText"
Navigator.pop(context, textToSendBack);
}
我只需要更改所选拼贴的副标题而不是所有拼贴的副标题!
我找到了答案!!通过定义字幕列表(命名为:subList
)来解决问题,在_awaitReturnValueFromDetailScreen
中我将返回的值放在subList[position]
中,而在subtitle
中我只是从这个列表中读取。