【问题标题】:Start an Alert by opening page with Flutter web通过使用 Flutter web 打开页面来启动警报
【发布时间】:2021-07-12 14:11:03
【问题描述】:

解决它的最终代码

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

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

我想在我的网络应用程序中构建一个 Flutter 警报,当我打开网站时,我想立即弹出它。 警报是使用 rflutter_alert 包构建的。

有人有自动打开此警报的解决方案吗?

警报代码

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

带有初始化状态

显然,当我将其置于初始化状态时,它不起作用。 然而,另一个功能以这种方式工作,我现在想激活的功能只能通过在按钮中使用 onpressed 来工作。

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

【问题讨论】:

    标签: flutter web alert flutter-web


    【解决方案1】:

    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?

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-02-15
    • 1970-01-01
    • 2018-09-21
    • 2010-11-11
    • 2012-06-04
    • 2021-12-21
    相关资源
    最近更新 更多