我有一个名为AuthenticationState的父小部件和下面的四个子小部件。
1.电话号码
- OneTimeCode
1.显示名称
1.公司简介
我想控制从PhoneNumber小部件到ProfilePicture小部件从父小部件AuthenticationState的移动。
下面是我的带有切换屏幕功能的父小部件,单击该功能时应导航到OneTimeCode小部件。
class _AuthenticationStateState extends State<AuthenticationState> {
Widget? setActiveAuthenticationScreen;
@override
void initState() {
super.initState();
setActiveAuthenticationScreen = PhoneNumber(switchScreen);
}
switchScreen() {
setState(() {
setActiveAuthenticationScreen = OneTimeCode(switchScreen);
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: setActiveAuthenticationScreen,
),
);
}
}
下面是PhoneNumber小部件的代码-
class PhoneNumber extends StatelessWidget {
PhoneNumber(this.nextScreen, {Key? key}) : super(key: key);
final void Function() nextScreen;
@override
Widget build(BuildContext context) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
OutlinedButton.icon(
icon: const Icon(Icons.arrow_right_alt),
onPressed: nextScreen,
style: OutlinedButton.styleFrom(foregroundColor: Colors.black),
label: const Text('Next on PhoneNumber'),
)
],
);
}
}
下面是OneTimeCode小部件的代码-
class OneTimeCode extends StatelessWidget {
const OneTimeCode(this.nextScreen, {Key? key}) : super(key: key);
final void Function() nextScreen;
@override
Widget build(BuildContext context) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
OutlinedButton.icon(
icon: const Icon(Icons.arrow_right_alt),
onPressed: nextScreen,
style: OutlinedButton.styleFrom(foregroundColor: Colors.black),
label: const Text('Next on OneTimeCode'),
)
],
);
}
}
1条答案
按热度按时间q0qdq0h21#
更新答案:
老答案:
有一个名为flutter_sliding_tutorial的pub软件包可以实现你想要做的事情。您还可以查看内置的Stepper类。