I am very new to flutter and i would like make a widget that automatically execute every time at the start of dart file coming from other dart file.
This is the button that I would like to be automatically execute:
onPressed: isConnected ? () => _sendMessage('1') : null
Kindly make it a widget so i can understand easily.
CodePudding user response:
As far as I understand your question, you wants to execute onPress event every time whenever you redirect to that dart file from another file.
In this case you can add this function to initState() method at start of your file
refer : here
or simply create a function and call it at start of file.
If you want something different can you please elaborate more.
CodePudding user response:
Use initState method in your stateful widget, which is called when the page is inserted into Widget tree.
@override
void initState() {
super.initState();
if(isConnected)
_sendMessage('1')
}
