Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
321 views
in Technique[技术] by (71.8m points)

How do I execute a function on a page after navigating to it in Flutter?

I have a CupertinoDialogAction button in Flutter that navigates back to a page with a timer. I want to start the timer function of that page upon clicking the button. Is this possible?

Here is the current code that I have to create the dialog action and navigate to the timer page upon being clicked.

Current Code


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Create an init state method on the page with the timer and call your function there - this runs when the page is initialised


class TimerPage extends StatefulWidget {
  @override
  _TimerPageState createState() => _TimerPageState();
}

class _TimerPageState extends State<TimerPage> {

 .
 .
 .

  @override
  void initState() {
    super.initState();
    _startTimer();
  }

 .
 .
 .

}

As said in the comments, add your code in the body of your question - this will allow us to give a more complete answer.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...