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

Flutter 颤振弹出菜单按钮在选择任何弹出项之前不会关闭,flutter,flutter-layout,Flutter,Flutter Layout,一切正常,但popupmenubutton在选择任何弹出项之前不会关闭。我不明白为什么在弹出菜单外单击后弹出菜单没有关闭,并且onCanceled没有调用。 请帮帮我 我在下面提供了源代码。谢谢 //Call from Here StatefulWidget> Scafold( bottomNavigation, TabBar body: widgets> //under tabBar child: callAction( too

一切正常,但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'),
        ),
      ],
    );

弹出菜单将平稳关闭,请参见以下代码示例:

   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;
  });
},

);}

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

弹出式菜单将顺利关闭,请参见以下代码示例:

   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;
  });
},

);}

如有任何疑问,请告诉我。

效果很好!谢谢你,阿米特!你能不能在我的代码中解释一下这个问题,因为我发现你的代码和我的代码非常相似?非常好!谢谢你,阿米特!你能在我的代码中解释一下这个问题吗?因为我发现你的代码和我的代码非常相似?