PopupMenuButton的不同屏幕



我正在Flutter/Dat上开发一个小应用程序,以适应这种语言,因为我是新手。我正在检查应用程序栏中是否实现了PopupMenuButton,我做得很好。我想做的是获得不同的屏幕(小部件(,这取决于从PopupMenuButton中选择了哪个项目。例如:PopupMenuItems:设置、配置文件、注销。因此,每当用户选择其中一个时,它都会重定向到另一个小部件(屏幕(。到目前为止,我实现了PopupMenuBotton,不同的选项在屏幕上呈现不同的值:

class _MyHomePage extends State<MyHomePage> {
String _selectedValue;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
// centers the title in the appBar
centerTitle: true,
title: Text(
"Alba's Playground",
// Mentioning the theme
style: Theme.of(context).textTheme.headline1,
),
actions: <Widget>[
PopupMenuButton(onSelected: (String str) {
setState(() {
_selectedValue = str;
});
}, itemBuilder: (BuildContext context) {
return <PopupMenuEntry<String>>[
PopupMenuItem(
child: Text(
"Item 1",
// Mentioning the theme
style: Theme.of(context).textTheme.headline2,
),
value: "Item1",
),
PopupMenuItem(
child: Text(
"Item 2",
style: Theme.of(context).textTheme.headline2,
),
value: "Item2",
),
PopupMenuItem(
child: Text(
"Item 3",
style: Theme.of(context).textTheme.headline2,
),
value: "Item3",
),
];
})
],
),
body: Container(
Text("$_selectedValue"),

因此,每当用户访问选项"时;项目1";,值";项目1";渲染,但不会更改屏幕。我想要实现的是为不同的按钮提供不同的屏幕。如果有人知道怎么做,或者能给我一个提示,我会非常感激

谢谢。

使用此:-

GestureDetector(onTap: () {
Navigator.push(context,
MaterialPageRoute(builder: (context) => SettingScreen()),
},
child://your child 
);

看看setState((){})函数所提供的功能。此外,您需要使用onTap:按钮所具有的功能。如果您用作按钮的Widget不是这样,请查看GestureDetector。

最新更新