我用 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)