通过DropdownButton

时间:2020-05-28 11:30:06

标签: flutter

所以基本上,我试图通过单击dropdownButton来更改页面,由于某种原因,我会收到此错误

我曾尝试用Material / Scaffold包装东西,但是这些都不起作用。 有帮助吗?

我曾尝试用Material / Scaffold包装东西,但是这些都不起作用。 有帮助吗?

Thanks for submitting an edit. It is only visible to you until it’s been approved by trusted community members

所以基本上我想通过单击dropdownButton来更改页面,由于某种原因,我会收到此错误

我曾尝试用Material / Scaffold包装东西,但是这些都不起作用。有帮助吗?

我曾尝试用Material / Scaffold包装东西,但是这些都不起作用。有帮助吗?

import 'package:flutter/material.dart';
import 'package:intergrative2020_UI_Rest/screens/signup.dart';


class AdminPermissions extends StatefulWidget {
  @override
  _AdminPermissionsState createState() => _AdminPermissionsState();
}

class _AdminPermissionsState extends State<AdminPermissions> {
  var _currencies = ['Create User','Delete User','Search User'];
 var _currentItemSelected = '';

  @override
  void initState() {
    super.initState();
     _currentItemSelected = _currencies[0];

  }

  @override
  Widget build(BuildContext context) {
          return MaterialApp(
                     home:Scaffold(
                     body: DropdownButton<String>(
                            items: _currencies.map((String value) {
                                                       return DropdownMenuItem(
                                                                      value: value,
                                                                      child: Text(value),
                                                                    );
                                                                    }).toList(),
                                                                    value: _currentItemSelected,
                                                                    onChanged: (String newValueSelected) {
                                                                    // Your code to execute, when a menu item is selected from dropdown
                                                                    _onDropDownItemSelected(newValueSelected);
                                                                      switch(newValueSelected){
                                                                          case "Create User" :{
                                                                            Navigator.pushReplacement(context, MaterialPageRoute(builder: (BuildContext context) => Signup()));
                                                                            break;
                                                                            }

                                                                          }
                                                                    }  
                                                                 ),
                                                     ),
                         );






  }
    void _onDropDownItemSelected(String newValueSelected) {
    setState(() {
      this._currentItemSelected = newValueSelected;
    });
}
}

1 个答案:

答案 0 :(得分:0)

您应用的窗口小部件层次结构应为MaterialApp-> Scaffold-> DropdownButton。 因此,尝试如下包装DropdownButton

MaterialApp(
  title://Title
  home:Scaffold(
    body:DropdownButton(
      .....
      .....
    )
  )
)