如何添加新的抽屉项目?但我例外

时间:2018-07-18 09:56:01

标签: flutter

当我添加更多driwerItem时,会出现异常。我该如何解决?

https://github.com/flutter-tuts/drawer_demo

2 个答案:

答案 0 :(得分:0)

您可以将新抽屉项目添加为

final drawerItems = [
new DrawerItem("Fragment 1", Icons.rss_feed),
new DrawerItem("Fragment 2", Icons.local_pizza),
new DrawerItem("Fragment 3", Icons.info),
new DrawerItem("Fragment 4", Icons.info)
];

并在处添加新片段

 _getDrawerItemWidget(int pos) {
switch (pos) {
  case 0:
    return new FirstFragment();
  case 1:
    return new SecondFragment();
  case 2:
    return new ThirdFragment();
  case 2:
    return new FourthFragment();

  default:
    return new Text("Error");
}

}

答案 1 :(得分:0)

您可以像这样构建抽屉:

$(document).ready(function(){
    //Set your array variable
    var checkboxValues = [];

    $('.chckbox').change(function(){
        var $this = $(this),
            val = $this.val();
        //Check if checkbox is checked
        if($this.prop('checked')){
            //Add value to array
            checkboxValues.push(val);
        }else{
            //Get index of current value
            var index = checkboxValues.indexOf(val);

            //Remove value from array
            checkboxValues.splice(index,1);
        }

        //Use join() for a "cleaner" approach (no trimming required)
        $('#subject_areas').val(checkboxValues.join(', '));

    });
});