Trigger a function from a widget to a State object

前端 未结 3 1619
情深已故
情深已故 2020-12-05 12:33

This is a simplified version of the scenario:

class ParentWdiegt extends StatelessWidget{
//
//
floatinActionButton: FloatingActionButtonWidget(onPressed:()=         


        
3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-05 12:54

    You can use GlobalKey for that:

    // some global place
    final customWidgetKey = new GlobalKey();
    

    ...

      // import the file with "customWidgetKey"
    
      new CustomWidget(key: customWidetKey, ...)
    

    ...

      // import the file with "customWidgetKey"
    
      floatinActionButton: FloatingActionButtonWidget(
          onPressed: ()=>customWidgetKey.currentState.someMethod(someValue))
    

提交回复
热议问题