目的
首次進入頁面執(zhí)行initState()方法,后面再返回頁面不再執(zhí)行initState()方法。
解決方法
第一步:在繼承的類后面加上with AutomaticKeepAliveClientMixin
class _OrderFinishPageState extends State<OrderFinishPage>
with AutomaticKeepAliveClientMixin {
}
第二步:在extends State類中加入@override bool get wantKeepAlive => true;
@override
bool get wantKeepAlive => true;
第三步:在build中加入super.build(context);
@override
Widget build(BuildContext context) {
super.build(context);
return Container(
child: orderList.length == 0 ? _defaultPage() : _orderList(),
);
}