我有一个颤动项目,我正在努力我不能把整个代码导致它超过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)