我有一个颤动项目,我正在努力我不能把整个代码导致它超过500行代码所以我会尝试问我的问题就像我使用imp一样简单.代码部分.
我有一个有状态的小部件,并在扩展的类下面的有状态小部件中有一些函数 State<MusicPlayer>
文件 lib\main.dart
只需要一个简单的功能
class MyAppState extends State<MyApp>{
...
void printSample (){
print("Sample text");
}
...
Run Code Online (Sandbox Code Playgroud)
此函数位于主类中的有状态小部件内.
还有另一个文件 lib\MyApplication.dart
这个文件也有一个有状态的小部件,我可以做一些事情,这样我就可以在printSample()这里调用函数..
class MyApplicationState extends State<MyApplication>{
...
@override
Widget build(BuildContext context) {
return new FlatButton(
child: new Text("Print Sample Text"),
onPressed :(){
// i want to cal the function here how is it possible to call the
// function
// printSample() from here??
}
);
}
...
}
Run Code Online (Sandbox Code Playgroud) 我现在需要检测是否有任何硬件按钮在 flutter 应用程序处于前台或打开时被按下。*
例如,当有人按下音量或其他按钮(即使是关机按钮)时,我想在我的应用程序中执行某些操作。
我知道当 Flutter 应用程序打开并且我正在查看应用程序日志时,我点击了任何硬件按钮,与该点击相关的 lops 会打印在日志中。
就像我按下 Vol down Key Down Tap 检测到的相关日志打印在日志中一样。
当执行上述任何指定操作时,我如何执行功能?
我将尝试以最简单的方式询问它。如果我的应用程序在前台运行,并且在那一刻我接到电话,有什么办法可以在发生这种情况时调用函数/执行操作。
//My App is open
// at any random time call recieved
( if call_Received)(){// how do I do this bit via dart code ??
sample()
}
void sample(){// any random function
// some code to perform
}
Run Code Online (Sandbox Code Playgroud)