0

Beginner question:

I'm trying to display a message as soon as the page display, I can do it with a simple custom message, but I couldn't find any standard way to do it, all search I did leads me to Snackbar or Flushbar, the problem with this 2 is that u can only show it after the build is called, e.g. on onPress, which leads me to the actual question:

How do I get a call back for onMount event, e.g. something like jQuery ready method, that is triggered once the page is mounted (i.e. ready), so that I can call Snackbar for example?

Elia Weiss
  • 8,324
  • 13
  • 70
  • 110

1 Answers1

3

Duplicate to Flutter: Run method on Widget build complete

answer:

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


    if (SchedulerBinding.instance.schedulerPhase ==
        SchedulerPhase.persistentCallbacks) {
      SchedulerBinding.instance.addPostFrameCallback((_) {
        showInFlushbar("Some text");
      });
    }
    ;
  }
Elia Weiss
  • 8,324
  • 13
  • 70
  • 110