简体   繁体   English

Flutter DropDownButton 更改页面主体

[英]Flutter DropDownButton to change page body

I have a UI like this where there is a drop down button and below that the space which should show only the widget I choose from the DropdownButton.我有一个像这样的用户界面,其中有一个下拉按钮,下方的空间应该只显示我从 DropdownButton 中选择的小部件。

下拉按钮

The Widgets are in different classes like this小部件在这样的不同类中

List<Widget> contactItems = [
    RecentContactsScreen(),
    Contacts(),
    AgentsList(),
    OwnersList(),
];

I need to know how can I implement in a way to achieve this task.我需要知道如何以某种方式实施以完成此任务。 Thanks.谢谢。

DropdownButton 有一个名为 onChange 的属性,您可以在该函数内导航到屏幕

Widget _build(index) {
switch (index) {
  case 0:
    return Container();
  case 1:
    return Container();
  default:
    return Container();
} }

pass the index or create a global variable and change it onChange of drop down.传递索引或创建一个全局变量并在下拉菜单中更改它。 replace the Container with your UI.用你的 UI 替换容器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM