{"id":194,"date":"2023-05-19T10:44:03","date_gmt":"2023-05-19T02:44:03","guid":{"rendered":"https:\/\/www.escook.cn\/?p=194"},"modified":"2023-09-26T21:08:02","modified_gmt":"2023-09-26T13:08:02","slug":"dart-%e5%9f%ba%e7%a1%80-%e5%86%85%e7%bd%ae%e7%b1%bb%e5%9e%8b-%e5%b8%83%e5%b0%94","status":"publish","type":"post","link":"https:\/\/www.escook.cn\/index.php\/2023\/05\/19\/dart-%e5%9f%ba%e7%a1%80-%e5%86%85%e7%bd%ae%e7%b1%bb%e5%9e%8b-%e5%b8%83%e5%b0%94\/","title":{"rendered":"Dart \u57fa\u7840 &#8211; \u5185\u7f6e\u7c7b\u578b &#8211; \u5e03\u5c14"},"content":{"rendered":"<blockquote>\n<p>\u7248\u6743\u5f52\u4f5c\u8005 <strong>\u00a9\u5218\u9f99\u5bbe<\/strong> \u6240\u6709\uff0c\u672c\u6587\u7ae0\u672a\u7ecf\u4f5c\u8005\u5141\u8bb8\uff0c\u7981\u6b62\u79c1\u81ea\u8f6c\u8f7d\uff01<\/p>\n<\/blockquote>\n<h2>1. \u5b9a\u4e49\u5e03\u5c14\u53d8\u91cf<\/h2>\n<p>Dart \u4f7f\u7528 <code>bool<\/code> \u5173\u952e\u5b57\u8868\u793a\u5e03\u5c14\u7c7b\u578b\uff0c\u5e03\u5c14\u7c7b\u578b\u53ea\u6709\u4e24\u4e2a\u5bf9\u8c61 <code>true<\/code> \u548c <code>false<\/code>\uff0c\u4e24\u8005\u90fd\u662f<strong>\u7f16\u8bd1\u65f6\u5e38\u91cf<\/strong>\u3002<\/p>\n<pre><code class=\"language-dart\">void main(List&lt;String&gt; args) {\n  \/\/ \u5b9a\u4e49\u5e03\u5c14\u53d8\u91cf boo\uff0c\u5e76\u8d4b\u503c\u4e3a true\n  bool boo = true;\n  \/\/ \u5b9a\u4e49\u5e03\u5c14\u53d8\u91cf foo\uff0c\u5e76\u8d4b\u503c\u4e3a false\n  bool foo = false;\n\n  print(boo); \/\/ \u8f93\u51fa true\n  print(foo); \/\/ \u8f93\u51fa false\n}<\/code><\/pre>\n<h2>2. \u5e03\u5c14\u503c\u5224\u65ad<\/h2>\n<p>\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\uff0cbool \u7c7b\u578b\u7ecf\u5e38\u4f1a\u7ed3\u5408<strong>\u6761\u4ef6\u5224\u65ad<\/strong>\u8bed\u53e5\u4e00\u8d77\u4f7f\u7528\u3002\u5728 Dart \u4e2d\u8fdb\u884c\u5e03\u5c14\u503c\u5224\u65ad\u65f6\uff0c<strong>\u5fc5\u987b\u663e\u793a\u5730\u8fdb\u884c\u5224\u65ad<\/strong>\uff0c\u4e0d\u5141\u8bb8\u4f7f\u7528\u7c7b\u4f3c JavaScript \u7684<strong>\u9690\u5f0f\u8f6c\u6362<\/strong>\u3002\u4f8b\u5982\uff1a\u5728 JavaScript \u4e2d\uff0c<code>NaN<\/code>\u3001<code>\u6570\u5b57 0<\/code>\u3001<code>\u7a7a\u5b57\u7b26\u4e32<\/code>\u3001<code>null<\/code>\u3001<code>undefined<\/code> \u8fd95\u4e2a\u503c\u4f1a\u9ed8\u8ba4\u8f6c\u6362\u4e3a false\uff0c\u5176\u4f59\u503c\u90fd\u9ed8\u8ba4\u8f6c\u6362\u4e3a true\u3002\u4f46\u662f\u5728 Dart \u4e2d\u6ca1\u6709\u9690\u5f0f\u8f6c\u6362\uff0c\u5fc5\u987b\u663e\u793a\u5730\u8fdb\u884c\u5224\u65ad\uff1a<\/p>\n<pre><code class=\"language-dart\">void main(List&lt;String&gt; args) {\n  String name = &#039;&#039;;\n  \/\/ 1. \u5224\u65ad name \u662f\u5426\u4e3a\u7a7a\u5b57\u7b26\u4e32\n  if (name.isEmpty) {\n    print(&#039;\u7528\u6237\u540d\u4e3a\u7a7a&#039;);\n  } else {\n    print(&#039;\u4f60\u597d&#039; + name);\n  }\n\n  int age = 17;\n  \/\/ 2. \u5224\u65ad\u662f\u201c\u6210\u5e74\u4eba\u201d\u8fd8\u662f\u201c\u672a\u6210\u5e74\u201d\n  if (age &gt;= 18) {\n    print(&#039;\u6210\u5e74\u4eba\uff0c\u62bd\u70df\u559d\u9152\u70eb\u5934&#039;);\n  } else {\n    print(&#039;\u672a\u6210\u5e74\uff0c \u5a03\u54c8\u54c8\u65fa\u4ed4AD\u9499&#039;);\n  }\n\n  int? count = int.tryParse(&#039;x&#039;);\n  \/\/ 3. \u5224\u65ad count \u7684\u503c\u662f\u5426\u4e3a null\n  if (count == null) {\n    print(&#039;\u6570\u5b57\u8f6c\u6362\u5931\u8d25\uff01&#039;);\n  } else {\n    print(&#039;\u6570\u5b57\u8f6c\u6362\u6210\u529f\uff1a$count&#039;);\n  }\n\n  double result = 0 \/ 0;\n  \/\/ 4. \u5224\u65ad\u662f\u6570\u5b57\u8fd0\u7b97\u7684\u7ed3\u679c\u662f\u5426\u4e3a NaN\n  if (result.isNaN) {\n    print(&#039;\u8ba1\u7b97\u5931\u8d25 NaN&#039;);\n  } else {\n    print(&#039;\u8ba1\u7b97\u7684\u7ed3\u679c\u662f\uff1a$result&#039;);\n  }\n}<\/code><\/pre>\n<blockquote>\n<p>\u5728 Dart \u4e2d\u4e00\u5f8b\u4f7f\u7528\u53cc\u7b49\u53f7 == \u8fdb\u884c\u76f8\u7b49\u5224\u65ad\uff0c\u4e0d\u652f\u6301 JavaScript \u4e2d\u7684\u5168\u7b49\u5224\u65ad ===\u3002<\/p>\n<\/blockquote>\n<p><\/p>\n<blockquote>\n<p>\u7248\u6743\u5f52\u4f5c\u8005 <strong>\u00a9\u5218\u9f99\u5bbe<\/strong> \u6240\u6709\uff0c\u672c\u6587\u7ae0\u672a\u7ecf\u4f5c\u8005\u5141\u8bb8\uff0c\u7981\u6b62\u79c1\u81ea\u8f6c\u8f7d\uff01<\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>\u7248\u6743\u5f52\u4f5c\u8005 \u00a9\u5218\u9f99\u5bbe \u6240\u6709\uff0c\u672c\u6587\u7ae0\u672a\u7ecf\u4f5c\u8005\u5141\u8bb8\uff0c\u7981\u6b62\u79c1\u81ea\u8f6c\u8f7d\uff01 1. \u5b9a\u4e49\u5e03\u5c14\u53d8\u91cf Dart \u4f7f\u7528 bool \u5173\u952e\u5b57\u8868\u793a\u5e03\u5c14\u7c7b\u578b\uff0c\u5e03\u5c14\u7c7b\u578b\u53ea\u6709\u4e24\u4e2a\u5bf9\u8c61 true \u548c false\uff0c\u4e24\u8005\u90fd\u662f\u7f16\u8bd1\u65f6\u5e38\u91cf\u3002 void main(List&lt;String&gt; args) { \/\/ \u5b9a\u4e49\u5e03\u5c14\u53d8\u91cf boo\uff0c\u5e76\u8d4b\u503c\u4e3a true bool boo = true; \/\/ \u5b9a\u4e49\u5e03\u5c14\u53d8\u91cf foo\uff0c\u5e76\u8d4b\u503c\u4e3a false bool foo = false; print(boo); \/\/ \u8f93\u51fa true print(foo); \/\/ \u8f93\u51fa false } 2. \u5e03\u5c14\u503c\u5224\u65ad \u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\uff0cbool \u7c7b\u578b\u7ecf\u5e38\u4f1a\u7ed3\u5408\u6761\u4ef6\u5224\u65ad\u8bed\u53e5\u4e00\u8d77\u4f7f\u7528\u3002\u5728 Dart \u4e2d\u8fdb\u884c\u5e03\u5c14\u503c\u5224\u65ad\u65f6\uff0c\u5fc5\u987b\u663e\u793a\u5730\u8fdb\u884c\u5224\u65ad\uff0c\u4e0d\u5141\u8bb8\u4f7f\u7528\u7c7b\u4f3c JavaScript \u7684\u9690\u5f0f\u8f6c\u6362\u3002\u4f8b\u5982\uff1a\u5728 JavaScript \u4e2d\uff0cNaN\u3001\u6570\u5b57 0\u3001\u7a7a\u5b57\u7b26\u4e32\u3001null\u3001undefined \u8fd95\u4e2a\u503c\u4f1a\u9ed8\u8ba4\u8f6c\u6362\u4e3a false\uff0c\u5176\u4f59\u503c\u90fd\u9ed8\u8ba4\u8f6c\u6362\u4e3a true\u3002\u4f46\u662f\u5728 Dart \u4e2d\u6ca1\u6709\u9690\u5f0f\u8f6c\u6362\uff0c\u5fc5\u987b\u663e\u793a\u5730\u8fdb\u884c\u5224\u65ad\uff1a void main(List&lt;String&gt; args) { String name = &#039;&#039;; \/\/ 1. \u5224\u65ad name \u662f\u5426\u4e3a\u7a7a\u5b57\u7b26\u4e32 if (name.isEmpty) { print(&#039;\u7528\u6237\u540d\u4e3a\u7a7a&#039;); } else { print(&#039;\u4f60\u597d&#039; + name); } int age = 17; \/\/ 2. \u5224\u65ad\u662f\u201c\u6210\u5e74\u4eba\u201d\u8fd8\u662f\u201c\u672a\u6210\u5e74\u201d if (age &gt;= 18) { print(&#039;\u6210\u5e74\u4eba\uff0c\u62bd\u70df\u559d\u9152\u70eb\u5934&#039;); } else { print(&#039;\u672a\u6210\u5e74\uff0c \u5a03\u54c8\u54c8\u65fa\u4ed4AD\u9499&#039;); } int? count = int.tryParse(&#039;x&#039;); \/\/ 3. \u5224\u65ad count \u7684\u503c\u662f\u5426\u4e3a null if (count == null) { print(&#039;\u6570\u5b57\u8f6c\u6362\u5931\u8d25\uff01&#039;); } else { print(&#039;\u6570\u5b57\u8f6c\u6362\u6210\u529f\uff1a$count&#039;); } double result = 0 \/ 0; \/\/ 4. \u5224\u65ad\u662f\u6570\u5b57\u8fd0\u7b97\u7684\u7ed3\u679c\u662f\u5426\u4e3a NaN if (result.isNaN) { print(&#039;\u8ba1\u7b97\u5931\u8d25 NaN&#039;); } else { print(&#039;\u8ba1\u7b97\u7684\u7ed3\u679c\u662f\uff1a$result&#039;); } } \u5728 Dart \u4e2d\u4e00\u5f8b\u4f7f\u7528\u53cc\u7b49\u53f7 == \u8fdb\u884c\u76f8\u7b49\u5224\u65ad\uff0c\u4e0d\u652f\u6301 JavaScript \u4e2d\u7684\u5168\u7b49\u5224\u65ad ===\u3002 \u7248\u6743\u5f52\u4f5c\u8005 \u00a9\u5218\u9f99\u5bbe \u6240\u6709\uff0c\u672c\u6587\u7ae0\u672a\u7ecf\u4f5c\u8005\u5141\u8bb8\uff0c\u7981\u6b62\u79c1\u81ea\u8f6c\u8f7d\uff01<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[9],"class_list":["post-194","post","type-post","status-publish","format-standard","hentry","category-dart","tag-dart"],"_links":{"self":[{"href":"https:\/\/www.escook.cn\/index.php\/wp-json\/wp\/v2\/posts\/194","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.escook.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.escook.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.escook.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.escook.cn\/index.php\/wp-json\/wp\/v2\/comments?post=194"}],"version-history":[{"count":3,"href":"https:\/\/www.escook.cn\/index.php\/wp-json\/wp\/v2\/posts\/194\/revisions"}],"predecessor-version":[{"id":579,"href":"https:\/\/www.escook.cn\/index.php\/wp-json\/wp\/v2\/posts\/194\/revisions\/579"}],"wp:attachment":[{"href":"https:\/\/www.escook.cn\/index.php\/wp-json\/wp\/v2\/media?parent=194"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.escook.cn\/index.php\/wp-json\/wp\/v2\/categories?post=194"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.escook.cn\/index.php\/wp-json\/wp\/v2\/tags?post=194"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}