将要保持状态的widget作为页面的成员变量
class _State extends State<LoginPageX> {
//定义为成员变量,为保持widget的状态
Widget _pwdLoginForm;
Widget _smsLoginForm;
@override
void initState() {
super.initState();
_pwdLoginForm = _pwdForm();
_smsLoginForm = _smsForm();
}
@override
Widget build(BuildContext context) {
return IndexedStack(
index: _tabIndex,
children: [
_pwdLoginForm,
_smsLoginForm
]
),
}
}