首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用PopupMenuButton的不同屏幕

使用PopupMenuButton的不同屏幕
EN

Stack Overflow用户
提问于 2020-08-07 16:07:36
回答 2查看 55关注 0票数 1

我正在开发Flutter/Dart上的一个小应用程序,以适应这门语言,因为我是新手。我正在检查以在我的应用程序栏中实现一个PopupMenuButton,我做得很正确。我正在尝试做的是获得不同的屏幕(小部件),这取决于从PopupMenuButton中选择了哪一项。例如: PopupMenuItems:设置、配置文件、注销。因此,只要用户选择其中之一,它就会重定向到另一个小部件(屏幕)。到目前为止,我实现了PopupMenuBotton,并且不同的选项在屏幕上呈现不同的值:

代码语言:javascript
复制
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"),

因此,只要用户访问选项"item1",就会呈现值"item1“,但不会更改屏幕。我想要实现的是不同按钮的不同屏幕。如果有人知道怎么做,或者可以给我一个提示,我将非常感激。

谢谢。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-08-07 16:23:02

使用这个:-

代码语言:javascript
复制
GestureDetector(onTap: () {
                  Navigator.push(context,
                  MaterialPageRoute(builder: (context) => SettingScreen()),
                },
                child://your child 
);
票数 1
EN

Stack Overflow用户

发布于 2020-08-07 16:20:05

看一看必须提供的setState((){})函数。此外,您还需要使用onTap:功能按钮。如果您要用作按钮的小部件不是这种情况,请查看GestureDetector

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63297780

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档