我有一个类,该类具有刷新功能(名称为“ downloadMatches”)(Web请求,并且在setState调用之后)=可以正常工作。 -
我想从dragBox函数中触发此函数。
我的主要目标是: 当我导航到另一页面并返回此页面时,我想触发该功能。
class _MatchListViewState extends State<MatchListView> {
PlayerData player1;
@override
void initState() {
super.initState();
downloadMatches(0);
}
void downloadMatches(int nextorprev) async{
roundid = roundid + nextorprev;
var ws = WebRequests('https://www.sample.php');
rounds = await ws.updateRound();
setState(() {
player1 = rounds.player1;
});
}
@override
Widget build(BuildContext context) {
return Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
createMatches(matches, context),
Expanded(
flex: 1,
child: SingleChildScrollView(
child: Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
player1 != null ? dragBox(player1, 1, context) : dragBox(player0, 1, context),
],
),
],
),
],
),
),
),
)
],
)
);
}
Column dragBox(PlayerData player, int posiid, context) {
return Column(
children: <Widget>[
GestureDetector(
onTap: () async
{
await Navigator.push(context, MaterialPageRoute(builder:
(BuildContext context) {
return ChangePlayerView(
chosenPositionCategory: posiid, player: player,);
}
));
downloadMatches(0);
},
);
}
我无法运行downloadMatches(0);函数来自dragBox函数。我知道,这不是正确的方法。但是我从dragBox函数触发了Navigation.push,当Navigation带backButton回来时,我想触发downloadMatches函数,或者以某种方式刷新_MatchListViewState内容。