Start an Alert by opening page with Flutter web

303

Call your method in the initState()

class StatefulWrapper extends StatefulWidget {

  @override
  _StatefulWrapperState createState() => _StatefulWrapperState();
}

class _StatefulWrapperState extends State<StatefulWrapper> {

 @override
  void initState() {
     Alert(
       context: context,
       title: "JOJOJO",
       desc: "Flutter is more awesome with RFlutter Alert.",
     ).show();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Container();
  }
}

What is init state?

Share:
303
Charles Down
Author by

Charles Down

Updated on December 29, 2022

Comments

  • Charles Down
    Charles Down over 1 year

    Final Code which solved it

      @override
    void initState() {
    super.initState();
    
    Future.delayed(Duration.zero, () {
      Alert(
        context: context,
        title: "JOJOJO",
        desc: "Flutter is more awesome with RFlutter Alert.",
      ).show();
    });
    }
    

    I want to build an Flutter alert into my web app and when I open the website I want to pop it up immediately. The alert is build with the rflutter_alert package.

    Does somebody have a solution to open this alert automatically?

    Code of the Alert

    _onBasicAlertPressed(context) {
    Alert(
      context: context,
      title: "JOJOJO",
      desc: "Flutter is more awesome with RFlutter Alert.",
    ).show();
    }
    

    With the init State

    Apparently it doesn't work when I just put it into the init state. However another function works with this way, the function that i want to activate for now only works by using onpressed in a button.

      @override
      void initState() {
        Alert(
      context: context,
      title: "JOJOJO",
      desc: "Flutter is more awesome with RFlutter Alert.",
    ).show();
    super.initState();
    callSendData();
    }
    
  • Charles Down
    Charles Down about 3 years
    Ok i tried this but it didn't worked out. I updated my question
  • Charles Down
    Charles Down about 3 years
    Ok i got a Problem but it worked out now Solutino: stackoverflow.com/questions/56395081/…