{"id":18465,"date":"2025-07-11T09:47:25","date_gmt":"2025-07-11T01:47:25","guid":{"rendered":"https:\/\/blog.ywdevops.cn\/?p=18465"},"modified":"2026-01-17T22:23:52","modified_gmt":"2026-01-17T14:23:52","slug":"18465","status":"publish","type":"post","link":"https:\/\/blog.ywdevops.cn\/index.php\/2025\/07\/11\/18465\/","title":{"rendered":"Dart\u53d8\u91cf"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u5728Dart \u4e2d\uff0c\u6211\u4eec\u6709\u591a\u79cd\u65b9\u5f0f\u6765\u58f0\u660e\u548c\u4f7f\u7528\u53d8\u91cf<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1\u3001\u4f7f\u7528var \u6765\u58f0\u660e\u4e00\u4e2a\u53d8\u91cf\uff0cDart \u4f1a\u81ea\u52a8\u63a8\u65ad\u51fa\u53d8\u91cf\u7c7b\u578b\uff0c\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>var name = \"hello\"; \/\/\u6ce8\u610f\uff1aDart\u8bed\u53e5\u8981\u4ee5\u5206\u53f7\u7ed3\u5c3e<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"653\" height=\"106\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/4-3.png\" alt=\"\" class=\"wp-image-18466\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/4-3.png 653w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/4-3-300x49.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/4-3-600x97.png 600w\" sizes=\"auto, (max-width: 653px) 100vw, 653px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"649\" height=\"85\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/5-3.png\" alt=\"\" class=\"wp-image-18467\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/5-3.png 649w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/5-3-300x39.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/5-3-600x79.png 600w\" sizes=\"auto, (max-width: 649px) 100vw, 649px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">2\u3001\u58f0\u660e\u7684\u65f6\u5019\u6307\u5b9a\u7c7b\u578b\u4e3aString\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"654\" height=\"94\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/6-3.png\" alt=\"\" class=\"wp-image-18469\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/6-3.png 654w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/6-3-300x43.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/6-3-600x86.png 600w\" sizes=\"auto, (max-width: 654px) 100vw, 654px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"652\" height=\"70\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/7-4.png\" alt=\"\" class=\"wp-image-18470\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/7-4.png 652w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/7-4-300x32.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/7-4-600x64.png 600w\" sizes=\"auto, (max-width: 652px) 100vw, 652px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">\u6ce8\u610f\uff1avar \u548c String\u7b49\u7c7b\u578b\u4e0d\u80fd\u540c\u65f6\u4f7f\u7528\uff0cvar\u662f\u81ea\u52a8\u63a8\u65ad\uff0cString\u662f\u663e\u793a\u6307\u5b9a<\/mark><\/strong>\uff0c\u5982\u4e0b\u662f\u9519\u8bef\u7684\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>var String a = \"hello\"; \/\/\u9519\u8bef,var\u548cString\u4e0d\u80fd\u540c\u65f6\u4f7f\u7528\uff0cint\u7b49\u5176\u4ed6\u7c7b\u578b\u4e5f\u662f\u4e00\u6837<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u7a7a\u5b89\u5168\uff1aDart \u8bed\u8a00\u8981\u6c42\u4ee5\u5065\u5168\u7684\u7a7a\u5b89\u5168\u65b9\u5f0f\u7f16\u5199\u4ee3\u7801\uff0c\u7a7a\u5b89\u5168\u80fd\u591f\u9632\u6b62\u610f\u5916\u8bbf\u95ee&nbsp;<code>null<\/code>&nbsp;\u7684\u53d8\u91cf\u800c\u5bfc\u81f4\u7684\u9519\u8bef\u3002\u8fd9\u6837\u7684\u9519\u8bef\u4e5f\u88ab\u79f0\u4e3a\u7a7a\u89e3\u5f15\u7528\u9519\u8bef\uff0c\u8bbf\u95ee\u4e00\u4e2a\u6c42\u503c\u4e3a&nbsp;<code>null<\/code>&nbsp;\u7684\u8868\u8fbe\u5f0f\u7684\u5c5e\u6027\u6216\u8c03\u7528\u65b9\u6cd5\u65f6\uff0c\u4f1a\u53d1\u751f\u7a7a\u89e3\u5f15\u7528\u9519\u8bef\uff0c\u4f46\u662f\u5bf9\u4e8e&nbsp;<code>toString()<\/code>&nbsp;\u65b9\u6cd5\u548c&nbsp;<code>hashCode<\/code>&nbsp;\u5c5e\u6027\uff0c\u7a7a\u5b89\u5168\u4f1a\u4f53\u73b0\u51fa\u4f8b\u5916\u60c5\u51b5\u3002 Dart \u7f16\u8bd1\u5668\u53ef\u4ee5\u5728\u7a7a\u5b89\u5168\u7684\u57fa\u7840\u4e0a\u5728\u7f16\u8bd1\u671f\u68c0\u6d4b\u5230\u8fd9\u4e9b\u6f5c\u5728\u7684\u9519\u8bef\u3002\u4f8b\u5982\uff0c\u5047\u8bbe\u4f60\u60f3\u8981\u67e5\u627e&nbsp;<code>int<\/code>&nbsp;\u53d8\u91cf&nbsp;<code>i<\/code>&nbsp;\u7684\u7edd\u5bf9\u503c\u3002\u5982\u679c&nbsp;<code>i<\/code>&nbsp;\u662f&nbsp;<code>null<\/code>&nbsp;\uff0c\u8c03\u7528&nbsp;<code>i.abs()<\/code>&nbsp;\u4f1a\u5bfc\u81f4\u7a7a\u89e3\u5f15\u7528\u9519\u8bef\u3002\u5728\u5176\u4ed6\u8bed\u8a00\u4e2d\uff0c\u5c1d\u8bd5\u8fd9\u6837\u505a\u53ef\u80fd\u4f1a\u5bfc\u81f4\u8fd0\u884c\u65f6\u9519\u8bef\uff0c\u4f46\u662f Dart \u7684\u7f16\u8bd1\u5668\u901a\u8fc7\u7981\u6b62\u8fd9\u4e9b\u64cd\u4f5c\u6765\u9632\u6b62\u6b64\u7c7b\u9519\u8bef\u53d1\u751f\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7a7a\u5b89\u5168\u5f15\u5165\u4e86\u4e09\u4e2a\u5173\u952e\u66f4\u6539\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">(1)\u3001\u5f53\u4f60\u4e3a\u53d8\u91cf\u3001\u53c2\u6570\u6216\u53e6\u4e00\u4e2a\u76f8\u5173\u7ec4\u4ef6\u6307\u5b9a\u7c7b\u578b\u65f6\uff0c\u53ef\u4ee5\u63a7\u5236\u8be5\u7c7b\u578b\u662f\u5426\u5141\u8bb8&nbsp;<code>null<\/code>&nbsp;\u3002\u8981\u8ba9\u4e00\u4e2a\u53d8\u91cf\u53ef\u4ee5\u4e3a\u7a7a\uff0c\u4f60\u53ef\u4ee5\u5728\u7c7b\u578b\u58f0\u660e\u7684\u672b\u5c3e\u6dfb\u52a0&nbsp;<code>?<\/code>\uff0c\u5982\u4e0b\u56fe\uff0c\u5373\u4f7f\u4e0d\u76f4\u63a5\u8bbe\u7f6e\u503c\u4e3anull\uff0c\u9ed8\u8ba4\u4e5f\u662fnull<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"606\" height=\"98\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2026\/01\/1-4.png\" alt=\"\" class=\"wp-image-19512\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2026\/01\/1-4.png 606w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2026\/01\/1-4-300x49.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2026\/01\/1-4-600x97.png 600w\" sizes=\"auto, (max-width: 606px) 100vw, 606px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"600\" height=\"98\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2026\/01\/1-3.png\" alt=\"\" class=\"wp-image-19510\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2026\/01\/1-3.png 600w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2026\/01\/1-3-300x49.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">(2)\u3001\u4f60\u5fc5\u987b\u5728\u4f7f\u7528\u53d8\u91cf\u4e4b\u524d\u5bf9\u5176\u8fdb\u884c\u521d\u59cb\u5316\u3002\u53ef\u7a7a\u53d8\u91cf\u662f\u9ed8\u8ba4\u521d\u59cb\u5316\u4e3a&nbsp;<code>null<\/code>&nbsp;\u7684\u3002 Dart \u4e0d\u4f1a\u4e3a\u975e\u53ef\u7a7a\u7c7b\u578b\u8bbe\u7f6e\u521d\u59cb\u503c\uff0c\u5b83\u5f3a\u5236\u8981\u6c42\u4f60\u8bbe\u7f6e\u521d\u59cb\u503c\u3002 Dart \u4e0d\u5141\u8bb8\u4f60\u89c2\u5bdf\u672a\u521d\u59cb\u5316\u7684\u53d8\u91cf\u3002\u8fd9\u53ef\u4ee5\u9632\u6b62\u4f60\u5728\u63a5\u6536\u8005\u7c7b\u578b\u53ef\u4ee5\u4e3a&nbsp;<code>null<\/code>&nbsp;\u4f46&nbsp;<code>null<\/code>&nbsp;\u4e0d\u652f\u6301\u7684\u76f8\u5173\u65b9\u6cd5\u6216\u5c5e\u6027\u7684\u60c5\u51b5\u4e0b\u4f7f\u7528\u5b83<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">(3)\u3001\u4f60\u4e0d\u80fd\u5728\u53ef\u7a7a\u7c7b\u578b\u7684\u8868\u8fbe\u5f0f\u4e0a\u8bbf\u95ee\u5c5e\u6027\u6216\u8c03\u7528\u65b9\u6cd5\u3002\u540c\u6837\u7684\u4f8b\u5916\u60c5\u51b5\u9002\u7528\u4e8e&nbsp;<code>null<\/code>&nbsp;\u652f\u6301\u7684\u5c5e\u6027\u6216\u65b9\u6cd5\uff0c\u4f8b\u5982&nbsp;<code>hashCode<\/code>&nbsp;\u6216&nbsp;<code>toString()<\/code>&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7a7a\u5b89\u5168\u5c06\u6f5c\u5728\u7684&nbsp;<strong>\u8fd0\u884c\u65f6\u9519\u8bef<\/strong>&nbsp;\u8f6c\u53d8\u4e3a&nbsp;<strong>\u7f16\u8f91\u65f6<\/strong>&nbsp;\u5206\u6790\u9519\u8bef\u3002\u5f53\u975e\u7a7a\u53d8\u91cf\u5904\u4e8e\u4ee5\u4e0b\u4efb\u4e00\u72b6\u6001\u65f6\uff0c\u7a7a\u5b89\u5168\u4f1a\u8bc6\u522b\u8be5\u53d8\u91cf\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u672a\u4f7f\u7528\u975e\u7a7a\u503c\u8fdb\u884c\u521d\u59cb\u5316<\/li>\n\n\n\n<li>\u8d4b\u503c\u4e3a\u7a7a<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f60\u4e0d\u5fc5\u5728\u58f0\u660e\u53d8\u91cf\u65f6\u521d\u59cb\u5316\u53d8\u91cf\uff0c\u4f46\u5728\u4f7f\u7528\u4e4b\u524d\u9700\u8981\u4e3a\u5176\u8d4b\u503c\u3002\u4f8b\u5982\u4ee5\u4e0b\u4ee3\u7801\u662f\u5408\u6cd5\u7684\uff0c\u56e0\u4e3a Dart \u53ef\u4ee5\u68c0\u6d4b\u5230\u00a0abcd\u5728\u4f20\u9012\u7ed9\u00a0<code>print()<\/code>\u00a0\u65f6\u662f\u975e\u7a7a\u7684\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"602\" height=\"211\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2026\/01\/2-2.png\" alt=\"\" class=\"wp-image-19517\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2026\/01\/2-2.png 602w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2026\/01\/2-2-300x105.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2026\/01\/2-2-600x210.png 600w\" sizes=\"auto, (max-width: 602px) 100vw, 602px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"599\" height=\"90\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2026\/01\/3-2.png\" alt=\"\" class=\"wp-image-19518\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2026\/01\/3-2.png 599w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2026\/01\/3-2-300x45.png 300w\" sizes=\"auto, (max-width: 599px) 100vw, 599px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u6ce8\uff1a\u4e0a\u8ff0\u4ee3\u7801\u4e2d\u5982\u679cif\u6761\u4ef6\u6ca1\u6709\u5199else\uff0c\u90a3\u4e48\u6267\u884c\u540e\u5c31\u4f1a\u62a5\u9519\u63d0\u793a\u53d8\u91cf\u672a\u521d\u59cb\u5316\uff0c\u56e0\u4e3aDart\u7f16\u8bd1\u5668\u770b\u5230\u4e86if\u6761\u4ef6\u540e\u5c31\u4f1a\u8003\u8651\u8fd8\u6709else\u6761\u4ef6\u4e2d\u6ca1\u6709\u521d\u59cb\u5316\uff0c\u6240\u4ee5\u5c31\u4f1a\u62a5\u9519<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">3\u3001\u5982\u679c\u4e00\u4e2a\u5bf9\u8c61\u4e0d\u9650\u4e8e\u5355\u4e00\u7c7b\u578b\uff0c\u53ef\u901a\u8fc7Object\u6765\u6307\u5b9a\uff0c\u4f46\u662f\u9700\u8981\u5224\u65ad\u7c7b\u578b\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"652\" height=\"167\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/1-4.png\" alt=\"\" class=\"wp-image-18480\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/1-4.png 652w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/1-4-300x77.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/1-4-600x154.png 600w\" sizes=\"auto, (max-width: 652px) 100vw, 652px\" \/><\/figure>\n\n\n\n<p class=\"has-luminous-vivid-amber-background-color has-background wp-block-paragraph\">\u6ce8\uff1aDart3\u540e\u4e0d\u63a8\u8350\u4f7f\u7528\u4e86\uff0c\u53ef\u901a\u8fc7\u6cdb\u578b\u66ff\u4ee3\uff0c\u9664\u975e<strong>\u4e0e\u67d0\u4e9b\u539f\u751f\u5e73\u53f0\u4ea4\u4e92\u200b<\/strong>\u200b\uff08\u5982\u901a\u8fc7&nbsp;<code>dart:ffi<\/code>&nbsp;\u8c03\u7528 C \u51fd\u6570\uff09<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">4\u3001\u5982\u679c\u4e00\u4e2a\u53d8\u91cf\u5728\u521d\u59cb\u5316\u540e\u503c\u4e0d\u518d\u6539\u53d8\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528final \u6216const \u58f0\u660e\u5b83\uff0c\u4f46\u662ffinal\u548cconst\u6709\u70b9\u533a\u522b<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>const\u662f\u7f16\u8bd1\u65f6\u5e38\u91cf\uff0c\u5728\u7f16\u8bd1\u4e4b\u524d\u5c31\u8981\u6307\u5b9a\u503c\uff0c\u4e0d\u80fd\u5728\u8fd0\u884c\u8fc7\u7a0b\u4e2d\u6307\u5b9a<\/li>\n\n\n\n<li>final\u548cconst\u90fd\u662f\u4e00\u65e6\u8bbe\u7f6e\u4e86\u503c\u5c31\u4e0d\u80fd\u6539\u53d8<\/li>\n\n\n\n<li>\u5982\u679c&nbsp;<code>const<\/code>&nbsp;\u53d8\u91cf\u5728\u7c7b\u7ea7\u522b\uff0c\u8bf7\u5c06\u5176\u6807\u8bb0\u4e3a&nbsp;<code>static const<\/code><\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"650\" height=\"163\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/2-4.png\" alt=\"\" class=\"wp-image-18484\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/2-4.png 650w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/2-4-300x75.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/2-4-600x150.png 600w\" sizes=\"auto, (max-width: 650px) 100vw, 650px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"652\" height=\"164\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/3-4.png\" alt=\"\" class=\"wp-image-18485\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/3-4.png 652w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/3-4-300x75.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/3-4-600x151.png 600w\" sizes=\"auto, (max-width: 652px) 100vw, 652px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u9762\u4f8b\u5b50\u4e2dfinal\u5728\u8fd0\u884c\u65f6\u5019\u6307\u5b9a\u7684\u503c\u4e0d\u4f1a\u62a5\u9519\uff0c\u4f46\u662fconst\u5c31\u4f1a\u62a5\u9519\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"653\" height=\"165\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/7-5.png\" alt=\"\" class=\"wp-image-18494\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/7-5.png 653w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/7-5-300x76.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/7-5-600x152.png 600w\" sizes=\"auto, (max-width: 653px) 100vw, 653px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"655\" height=\"100\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/8-5.png\" alt=\"\" class=\"wp-image-18495\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/8-5.png 655w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/8-5-300x46.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/8-5-600x92.png 600w\" sizes=\"auto, (max-width: 655px) 100vw, 655px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u4efb\u4f55\u53d8\u91cf\u90fd\u53ef\u4ee5\u62e5\u6709\u5e38\u91cf\u503c\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"650\" height=\"178\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/9-3.png\" alt=\"\" class=\"wp-image-18499\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/9-3.png 650w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/9-3-300x82.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/9-3-600x164.png 600w\" sizes=\"auto, (max-width: 650px) 100vw, 650px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"652\" height=\"115\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/1-5.png\" alt=\"\" class=\"wp-image-18501\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/1-5.png 652w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/1-5-300x53.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/1-5-600x106.png 600w\" sizes=\"auto, (max-width: 652px) 100vw, 652px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><code>final<\/code> \u5173\u952e\u5b57\u7528\u4e8e\u58f0\u660e\u4e00\u4e2a\u4e0d\u53ef\u53d8\u7684\u53d8\u91cf\uff0c\u4f46\u8fd9\u4e2a\u53d8\u91cf\u53ef\u4ee5\u5f15\u7528\u4e00\u4e2a\u53ef\u53d8\u7684\u5bf9\u8c61\u3002\u6362\u53e5\u8bdd\u8bf4\uff0c\u867d\u7136 <code>final<\/code> \u53d8\u91cf\u672c\u8eab\u4e0d\u80fd\u88ab\u91cd\u65b0\u8d4b\u503c\uff0c\u4f46\u5b83\u7684\u5b57\u6bb5\uff08\u5373\u5bf9\u8c61\u7684\u5c5e\u6027\uff09\u4ecd\u7136\u53ef\u4ee5\u88ab\u4fee\u6539\u3002<strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">\u4e0b\u9762\u662f\u4e0d\u53ef\u53d8\u53d8\u91cf\u5f15\u7528\u53ef\u53d8\u5bf9\u8c61\u7684\u4f8b\u5b50<\/mark><\/strong>\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"655\" height=\"382\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/3-5.png\" alt=\"\" class=\"wp-image-18505\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/3-5.png 655w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/3-5-300x175.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/3-5-600x350.png 600w\" sizes=\"auto, (max-width: 655px) 100vw, 655px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"649\" height=\"128\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/4-5.png\" alt=\"\" class=\"wp-image-18506\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/4-5.png 649w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/4-5-300x59.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/4-5-600x118.png 600w\" sizes=\"auto, (max-width: 649px) 100vw, 649px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><code>const<\/code>&nbsp;\u5bf9\u8c61\u53ca\u5176\u5b57\u6bb5\u90fd\u4e0d\u80fd\u88ab\u6539\u53d8\uff1a\u5b83\u4eec\u662f<em>\u4e0d\u53ef\u53d8<\/em>\u7684\uff0c\u4e0b\u9762\u662f\u4e0d\u53ef\u53d8\u53d8\u91cf\u5f15\u7528\u4e0d\u53ef\u53d8\u5bf9\u8c61\u7684\u4f8b\u5b50\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"650\" height=\"324\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/5-5.png\" alt=\"\" class=\"wp-image-18508\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/5-5.png 650w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/5-5-300x150.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/5-5-600x299.png 600w\" sizes=\"auto, (max-width: 650px) 100vw, 650px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4f7f\u7528 <code>const<\/code> \u65f6\uff0c\u5bf9\u8c61\u7684\u5b57\u6bb5\u4e5f\u5fc5\u987b\u662f <code>final<\/code> \u7684\uff0c\u4ee5\u786e\u4fdd\u6574\u4e2a\u5bf9\u8c61\u662f\u4e0d\u53ef\u53d8\u7684<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">5\u3001<code>late<\/code>&nbsp;\u5173\u952e\u5b57\u7528\u4e8e\u58f0\u660e \u200b<strong>\u200b\u5ef6\u8fdf\u521d\u59cb\u5316\u200b<\/strong>\u200b \u7684\u975e\u7a7a\u53d8\u91cf\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"649\" height=\"258\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/4-4.png\" alt=\"\" class=\"wp-image-18488\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/4-4.png 649w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/4-4-300x119.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/4-4-600x239.png 600w\" sizes=\"auto, (max-width: 649px) 100vw, 649px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4f18\u52bf\uff1a\u907f\u514d\u4f7f\u7528\u53ef\u7a7a\u7c7b\u578b\uff08<code>String?<\/code>\uff09\uff0c\u540c\u65f6\u5141\u8bb8\u5ef6\u8fdf\u521d\u59cb\u5316<\/li>\n\n\n\n<li>\u5982\u679c\u53d8\u91cf\u200b<strong>\u200b\u53ef\u80fd\u6c38\u8fdc\u4e0d\u88ab\u521d\u59cb\u5316\u200b<\/strong>\u200b\uff0c\u5e94\u4f7f\u7528\u53ef\u7a7a\u7c7b\u578b\uff08<code>String?<\/code>\uff09\u800c\u975e&nbsp;<code>late<\/code><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u4f7f\u7528late \u58f0\u660e\u53d8\u91cf\u6ca1\u521d\u59cb\u5316\uff0c\u76f4\u63a5\u8bf7\u6c42\u53d8\u91cf\u4f1a\u62a5\u9519\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"647\" height=\"97\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/5-4.png\" alt=\"\" class=\"wp-image-18490\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/5-4.png 647w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/5-4-300x45.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/5-4-600x90.png 600w\" sizes=\"auto, (max-width: 647px) 100vw, 647px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"651\" height=\"103\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/6-4.png\" alt=\"\" class=\"wp-image-18491\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/6-4.png 651w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/6-4-300x47.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/6-4-600x95.png 600w\" sizes=\"auto, (max-width: 651px) 100vw, 651px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">late\u53d8\u91cf\u9ed8\u8ba4\u4e3a\u975e\u7a7a\uff0c\u56e0\u6b64\u4e0d\u80fd\u58f0\u660e\u540e\u518d\u6b21\u7ed9\u53d8\u91cf\u8d4b\u503c\u4e3anull\uff0c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>late String name;\nname = null;  \/\/\u62a5\u9519<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u9700\u8981\u4e3anull\u7684late\u53d8\u91cf\uff0c\u9700\u8981\u663e\u5f0f\u58f0\u660e\u7c7b\u578b\u4e3a\u53ef\u7a7a\uff0c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>late String? name;  \/\/\u52a0?\u8868\u793a\u53ef\u4e3a\u7a7a\nname = null;       \/\/\u4e0d\u4f1a\u62a5\u9519<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">6\u3001\u901a\u914d\u7b26\u53d8\u91cf(\u901a\u914d\u7b26\u53d8\u91cf\u8981\u6c42<a href=\"https:\/\/dart.ac.cn\/resources\/language\/evolution#language-versioning\">\u8bed\u8a00\u7248\u672c<\/a>\u81f3\u5c11\u4e3a 3.7)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u540d\u79f0\u4e3a&nbsp;<code>_<\/code>&nbsp;\u7684\u901a\u914d\u7b26\u53d8\u91cf\u58f0\u660e\u4e86\u4e00\u4e2a\u975e\u7ed1\u5b9a\u7684\u5c40\u90e8\u53d8\u91cf\u6216\u53c2\u6570\uff1b\u672c\u8d28\u4e0a\uff0c\u5b83\u662f\u4e00\u4e2a\u5360\u4f4d\u7b26\u3002\u5982\u679c\u5b58\u5728\u521d\u59cb\u5316\u5668\uff0c\u5b83\u4ecd\u4f1a\u6267\u884c\uff0c\u4f46\u503c\u4e0d\u53ef\u8bbf\u95ee\u3002\u5728\u540c\u4e00\u547d\u540d\u7a7a\u95f4\u4e2d\u53ef\u4ee5\u5b58\u5728\u591a\u4e2a\u540d\u4e3a&nbsp;<code>_<\/code>&nbsp;\u7684\u58f0\u660e\uff0c\u800c\u4e0d\u4f1a\u53d1\u751f\u547d\u540d\u51b2\u7a81\u9519\u8bef\uff0c\u9876\u5c42\u58f0\u660e\u6216\u53ef\u80fd\u5f71\u54cd\u5e93\u9690\u79c1\u7684\u6210\u5458\u4e0d\u9002\u7528\u4e8e\u901a\u914d\u7b26\u53d8\u91cf\uff0c\u5757\u8303\u56f4\u5185\u7684\u5c40\u90e8\u53d8\u91cf\u53ef\u4ee5\u7528\u901a\u914d\u7b26\uff0c\u5982\u4e0b<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"651\" height=\"118\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/7-6.png\" alt=\"\" class=\"wp-image-18511\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/7-6.png 651w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/7-6-300x54.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/7-6-600x109.png 600w\" sizes=\"auto, (max-width: 651px) 100vw, 651px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>for (var _ in list) {}   \/\/for\u5faa\u73af\u4e2d\u4f7f\u7528<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ try...catch\u4e2d\u4f7f\u7528\ntry {\n  throw '!';\n} catch (_) {\n  print('oops');\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5728Dart \u4e2d\uff0c\u6211\u4eec\u6709\u591a\u79cd\u65b9\u5f0f\u6765\u58f0\u660e\u548c\u4f7f\u7528\u53d8\u91cf 1\u3001\u4f7f\u7528var \u6765\u58f0\u660e\u4e00\u4e2a\u53d8\u91cf\uff0cDart \u4f1a\u81ea\u52a8\u63a8\u65ad\u51fa\u53d8\u91cf\u7c7b\u578b [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":18471,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[158],"tags":[],"class_list":["post-18465","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dart"],"blocksy_meta":{"styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[],"version":8}},"_links":{"self":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts\/18465","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/comments?post=18465"}],"version-history":[{"count":33,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts\/18465\/revisions"}],"predecessor-version":[{"id":19520,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts\/18465\/revisions\/19520"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/media\/18471"}],"wp:attachment":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/media?parent=18465"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/categories?post=18465"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/tags?post=18465"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}