flutter页面自动d出d框

flutter页面自动d出d框,第1张

import 'dart:async';
import 'package:flutter/material.dart';

class Temp3Page extends StatefulWidget {
  Temp3Page({Key key}) : super(key: key);

  _Temp3Page createState() => _Temp3Page();
}

class _Temp3Page extends State<Temp3Page> {
  Timer timer;

  @override
  void initState() {
    super.initState();
    timer = Timer(const Duration(milliseconds: 0), () {
      try {
        showDialog<Null>(
          context: context,
          barrierDismissible: true,
          builder: (BuildContext context) {
            return AlertDialog(
              title: Text('标题'),
              content: SingleChildScrollView(
                child: ListBody(
                  children: <Widget>[
                    Text('内容'),
                  ],
                ),
              ),
              actions: <Widget>[
                FlatButton(
                  child: Text('确定'),
                  onPressed: () {
                    Navigator.of(context).pop();
                  },
                ),
                FlatButton(
                  child: Text('取消'),
                  onPressed: () {
                    Navigator.of(context).pop();
                  },
                ),
              ],
            );
          },
        );
      } catch (e) {}
    });
  }

  @override
  void dispose() {
    timer.cancel();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Center(child: Text('d框'));
  }
}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/993702.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存