call method in one stateful widget from another stateful widget - Flutter

后端 未结 7 951
耶瑟儿~
耶瑟儿~ 2020-11-29 17:59

I have a flutter project that i am working on i cant put the whole code cause its more than 500 lines of code so i will try to ask my question as simply as i acn using the i

相关标签:
7条回答
  • 2020-11-29 18:37

    if you want to call printSample() func you can use:

    class Myapp extends StatefulWidget{
    ...
        MyappState myAppState=new MyappState();
        @override
        MyappState createState() => myAppState;
        void printSample(){
            myAppState.printSample();
        }
    }
    class MyAppState extends State<MyApp>{
        void printSample (){
            print("Sample text");
        }
    }
    
    ...............
    Myapp _myapp = new Myapp();
    myapp.printSample();
    ...
    
    0 讨论(0)
提交回复
热议问题