小编use*_*497的帖子

如何在 ModalRoute 上 setState()?

我用 flutter 写了一个应用程序。我想更改字符串变量的状态。设置字符串变量的状态后,ModalRoute PopUpMenu 不显示更改后的变量。如果我关闭 ModalRoute PopUpMenu 并再次打开它,我可以看到更改后的变量。

我尝试弹出上下文,但我希望在 PopUpMenu 上进行更改。我有自己的覆盖小部件。


    class MyOverlay extends ModalRoute {
    ...
    }

    // this is my main.dart: 

    List<String> categories = ['please', 'help', 'me'];
    String _selectedCategory = 'category';

    // this is where the PopUpMenu starts
    floatingActionButton: FloatingActionButton(
            child: ...,
            onPressed: () {
              _showPopup(context, _popupBody(), 'Add');
            },
    ),

    _showPopup(BuildContext context, Widget widget, String title, {BuildContext popupContext}) {
        Navigator.push(
          context,
          MyOverlay(
               ...
                  onPressed: () {
                    try {
                      Navigator.pop(context); //close the popup
                    } catch (e) {
                      print(e);
                    } …
Run Code Online (Sandbox Code Playgroud)

text refresh navigator dart flutter

5
推荐指数
1
解决办法
1149
查看次数

标签 统计

dart ×1

flutter ×1

navigator ×1

refresh ×1

text ×1