简体   繁体   中英

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.

下拉按钮

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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