很简单,您需要将SinglePlayMode :: toggleCoin函数作为回调发送到dropDownMenu类。
class dropDownMenu extends StatefulWidget { final _callback; // callback reference holder //you will pass the callback here in constructor dropDownMenu( {@required void toggleCoinCallback() } ) : _callback = toggleCoinCallback; @override _dropDownMenuState createState() => _dropDownMenuState(); } class _dropDownMenuState extends State<dropDownMenu> { @override Widget build(BuildContext context) { return Stack( children: <Widget> [ Column( mainAxisAlignment: MainAxisAlignment.end, children: <Widget>[ Container( child: Opacity( opacity: 0.0, child: FloatingActionButton(heroTag: null,onPressed: (){ widget?._callback(); // callback calling}, ), ), );} }然后,当您在SinglePlayerMode类中创建dropDownMenu类实例时,您将执行
dropDownMenu( toggleCoinCallback: toogleCoin, );



