在选择任何弹出项之前,Flutter弹出菜单按钮不会关闭

时间:2019-12-02 10:24:47

标签: flutter flutter-layout

一切正常,但在选择任何弹出项目之前,popupmenubutton不会关闭。我不明白为什么在弹出菜单之外单击后弹出菜单没有关闭,并且未调用onCanceled。 请帮助我。

我提供了以下源代码。谢谢。

//Call from Here
    StatefulWidget> Scafold(
    bottomNavigation,
    TabBar
    body: widgets>
//under tabBar
    child: callAction(
       tooltip: "Call Button",
       child: Container(
            height: double.infinity,
            padding: EdgeInsets.all(20),
            child: Icon(Icons.call)
        ),
      ),
    )

//PopupMenuButton widget

enum CallActionType { DataCall, Sim1Call, Sim2Call}

class callAction extends StatelessWidget {
  Widget child;
  String tooltip;
  callAction({@required this.child, @required this.tooltip});

PopupMenuButton<CallActionType>(
      elevation: 8,
      shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(15.0)),
      onSelected: (CallActionType value) {
        setState(() {
          print(value);
        });
      },

//onCanceled didn't call

      onCanceled: () {
        print('You have not chossed anything');
      },
      tooltip: widget.tooltip,
      offset: Offset(0, 100),
      child: widget.child,
      itemBuilder: (BuildContext context) => <PopupMenuEntry<CallActionType>>[
        new PopupMenuItem<CallActionType>(
          value: CallActionType,
          child: Text('Action 1'),
        ),
        new PopupMenuItem<CallActionType>(
          value: CallActionType,
          child: Text('Action 2'),
        ),
        new PopupMenuItem<CallActionType>(
          value: CallActionType,
          child: Text('Action 3'),
        ),
      ],
    );

1 个答案:

答案 0 :(得分:0)

PopupMenu将顺利关闭,请参见以下代码:

   Widget popupMenuButton(){

return PopupMenuButton<String>(
  elevation: 50,
  padding: EdgeInsets.fromLTRB(5, 0, 0, 0),
  icon: Icon(Icons.keyboard_arrow_down, size: 30, color: Colors.black),
  itemBuilder: (BuildContext context) => <PopupMenuEntry<String>>[

    PopupMenuItem<String>(
        value: "One_Val",
        child: Text("One_Val"),
    ),
     PopupMenuItem<String>(
        value: "Two_Val",
        child: Text("Two_Val"),
    ),
     PopupMenuItem<String>(
        value: "Three_Val",
        child: Text("Three_Val"),
    )

  ],
    onSelected: (String value) {
      setState(() {
        companyName = value;
  });
},

);}

如有任何疑问,请让我知道,谢谢。