{"id":580,"date":"2023-02-18T18:35:45","date_gmt":"2023-02-18T10:35:45","guid":{"rendered":"http:\/\/gjweb.top\/?p=580"},"modified":"2023-02-18T18:35:47","modified_gmt":"2023-02-18T10:35:47","slug":"12-dialog-%e5%bc%b9%e7%aa%97%e7%bb%84%e4%bb%b6-toast-%e7%bb%84%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/gjweb.top\/?p=580","title":{"rendered":"12. Dialog \u5f39\u7a97\u7ec4\u4ef6 &#038; toast \u7ec4\u4ef6"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"alterdialog-\u63d0\u793a\u5f39\u7a97\">AlterDialog \u63d0\u793a\u5f39\u7a97<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>_alterFun() async{<br> &nbsp; &nbsp;var result = await showDialog(<br> &nbsp;      barrierDismissible:false,\/\/ \u7981\u7528\u70b9\u51fb\u7a7a\u767d\u5904\u9000\u51fa<br> &nbsp; &nbsp; &nbsp; &nbsp;context:context,<br> &nbsp; &nbsp; &nbsp; &nbsp;builder:(context){<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return AlterDialog(<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;      title:const Text(\"\u63d0\u793a\u4fe1\u606f\"),<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;content:Text(\"\u786e\u8ba4\u5220\u9664\u5417\"),<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;actions:&#91;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TextButton(<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;      child:Text(\"\u53d6\u6d88\"),<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;onPressed:(){<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Navigator.pop(context,\"\u53d6\u6d88\") \/\/ \u6d88\u9664\u5f39\u7a97<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  }<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  ),<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TextButton(<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;      child:Text(\"ok\"),<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;onPressed:(){<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Navigator.pop(context,\"ok\")<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  }<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  )<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  ]<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  )<br> &nbsp; &nbsp; &nbsp;  }<br> &nbsp;  );<br> &nbsp; &nbsp;print(result)<br>}<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u5f85\u9009\u9879\u7684\u7ec4\u4ef6-simpledialog-simpledialogoption\">\u5f85\u9009\u9879\u7684\u7ec4\u4ef6 SimpleDialog\u3001SimpleDialogOption<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>_simpleDialog() async {<br>    var result = await showDialog(<br>    barrierDismissible: true, \/\/\u8868\u793a\u70b9\u51fb\u7070\u8272\u80cc\u666f\u7684\u65f6\u5019\u662f\u5426\u6d88\u5931\u5f39\u51fa\u6846<br>    context: context,<br>    builder: (context) {<br>        return SimpleDialog(<br>            title: const Text(\"\u8bf7\u9009\u62e9\u5185\u5bb9\"),<br>            children: &lt;Widget&gt;&#91;<br>                SimpleDialogOption(<br>                    child: const Text(\"Option A\"),<br>                    onPressed: () {<br>                        print(\"Option A\");<br>                        Navigator.pop(context, \"A\");<br>                    },<br>                ),<br>                const Divider(),<br>                SimpleDialogOption(<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;child: const Text(\"Option B\"),<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;onPressed: () {<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;      print(\"Option B\");<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;      Navigator.pop(context, \"B\");<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  },<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  ),<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;const Divider(),<br>                SimpleDialogOption(<br>                    child: const Text(\"Option C\"),<br>                    onPressed: () {<br>                        print(\"Option C\");<br>                        Navigator.pop(context, \"C\");<br>                    },<br>                ),<br>            ],<br>        );<br>    });<br>    print(result);<br>}<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u5e95\u90e8\u5f39\u51fa\u5c42-showmodalbottomsheet\">\u5e95\u90e8\u5f39\u51fa\u5c42 showModalBottomSheet<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>_modelBottomSheet() async {<br> &nbsp; &nbsp;var result = await showModalBottomSheet(<br> &nbsp;      context: context,<br> &nbsp; &nbsp; &nbsp; &nbsp;builder: (context) {<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return SizedBox(<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;      height: 220,<br>                child: Column(<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;      chilren:&#91;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ListTile(<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;      title: const Text(\"\u5206\u4eab A\"),<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;      onTap: () {<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;          Navigator.pop(context, \"\u5206\u4eab A\");<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;      },<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  ),<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;const Divider(),<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ListTile(<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;      title: const Text(\"\u5206\u4eab B\"),<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;      onTap: () {<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;          Navigator.pop(context, \"\u5206\u4eab B\");<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;      },<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  ),<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;const Divider(),<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  ]<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  )<br>\u200b<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  )<br> &nbsp; &nbsp; &nbsp;  }<br> &nbsp;  );<br> &nbsp; &nbsp;print(result)<br>}<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u81ea\u5b9a\u4e49\u5f39\u51fa\u5c42\">\u81ea\u5b9a\u4e49\u5f39\u51fa\u5c42<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>String title;<br>String content;<br>Function()? onClosed;<br>MyDialog({Key? key, required this.title,required this.onClosed,this.content=\"\"}) : super(key: key);<br>Material(<br>    type:MateralType.transparency,\/\/ \u8bbe\u7f6e\u900f\u660e\u80cc\u666f<br> &nbsp; &nbsp;child:Inkwell(<br> &nbsp;      onTap:onClosed,<br> &nbsp; &nbsp; &nbsp; &nbsp;child:Text(\"$title\")<br> &nbsp;  )<br>)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f7f\u7528<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void _myDialog() async {<br>    await showDialog(<br>        barrierDismissible: true, \/\/\u8868\u793a\u70b9\u51fb\u7070\u8272\u80cc\u666f\u7684\u65f6\u5019\u662f\u5426\u6d88\u5931\u5f39\u51fa\u6846<br>        context: context,<br>        builder: (context) {<br>            return MyDialog(<br>                title: '\u6807\u9898',<br>                onClosed: () {<br>                    print(\"\u5173\u95ed\");<br>                    Navigator.of(context).pop();<br>                },  <br>            content: \"\u6211\u662f\u4e00\u4e2a\u5185\u5bb9\");<br>        }<br> &nbsp;  );<br>}<br>\u200b<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toast-\u7ec4\u4ef6\">toast \u7ec4\u4ef6<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u7b2c\u4e09\u65b9\u6a21\u5757<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>fluttertoast: ^8.0.9<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>import 'package:fluttertoast\/fluttertoast.dart';<br>Fluttertoast.showToast(<br>    msg: \"\u63d0\u793a\u4fe1\u606f\",<br>    toastLength: Toast.LENGTH_SHORT,<br>    gravity: ToastGravity.BOTTOM,<br>    timeInSecForIosWeb: 1,<br>    backgroundColor: Colors.black,<br>    textColor: Colors.white,<br>    fontSize: 16.0<br>);<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>AlterDialog \u63d0\u793a\u5f39\u7a97 \u5f85\u9009\u9879\u7684\u7ec4\u4ef6 SimpleDialog\u3001SimpleDialogOption [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[31],"tags":[],"class_list":["post-580","post","type-post","status-publish","format-standard","hentry","category-flutter"],"_links":{"self":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts\/580","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=580"}],"version-history":[{"count":1,"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts\/580\/revisions"}],"predecessor-version":[{"id":581,"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts\/580\/revisions\/581"}],"wp:attachment":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=580"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=580"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=580"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}