{"id":110,"date":"2026-05-19T11:49:46","date_gmt":"2026-05-19T03:49:46","guid":{"rendered":"https:\/\/tachyoncat.top\/?p=110"},"modified":"2026-05-19T11:49:46","modified_gmt":"2026-05-19T03:49:46","slug":"dart%e5%9f%ba%e6%9c%ac%e8%af%ad%e6%b3%951","status":"publish","type":"post","link":"https:\/\/tachyoncat.top\/index.php\/2026\/05\/19\/dart%e5%9f%ba%e6%9c%ac%e8%af%ad%e6%b3%951\/","title":{"rendered":"Dart\u57fa\u672c\u8bed\u6cd51"},"content":{"rendered":"<h1>Dart \u57fa\u672c\u8bed\u6cd5\u603b\u7ed3 1<\/h1>\n<h2>1. \u53d8\u91cf\u58f0\u660e\u65b9\u5f0f<\/h2>\n<p>\u5728 Dart \u4e2d\uff0c\u6211\u4eec\u6709\u4e09\u79cd\u65b9\u5f0f\u58f0\u660e\u53d8\u91cf\uff1a<\/p>\n<h3><code>var<\/code> - \u53ef\u53d8\u53d8\u91cf<\/h3>\n<pre><code class=\"language-dart line-numbers\">var name = 'Alice';\nname = 'Bob';  \/\/ \u53ef\u4ee5\u91cd\u65b0\u8d4b\u503c\n<\/code><\/pre>\n<h3><code>final<\/code> - \u8fd0\u884c\u65f6\u5e38\u91cf<\/h3>\n<pre><code class=\"language-dart line-numbers\">final currentTime = DateTime.now();  \/\/ \u5728\u8fd0\u884c\u65f6\u786e\u5b9a\u503c\n\/\/ currentTime = DateTime.now();  \/\/ \u9519\u8bef\uff01\u4e0d\u80fd\u91cd\u65b0\u8d4b\u503c\n<\/code><\/pre>\n<h3><code>const<\/code> - \u7f16\u8bd1\u65f6\u5e38\u91cf<\/h3>\n<pre><code class=\"language-dart line-numbers\">const pi = 3.14159;\nconst maxItems = 100;\n\/\/ \u5fc5\u987b\u5728\u7f16\u8bd1\u65f6\u5c31\u80fd\u786e\u5b9a\u503c\n<\/code><\/pre>\n<p><strong>\u4e09\u8005\u7684\u6838\u5fc3\u533a\u522b\uff1a<\/strong><\/p>\n<table>\n<thead>\n<tr>\n<th>\u5173\u952e\u5b57<\/th>\n<th>\u80fd\u5426\u4fee\u6539<\/th>\n<th>\u4f55\u65f6\u786e\u5b9a\u503c<\/th>\n<th>\u4f7f\u7528\u573a\u666f<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>var<\/code><\/td>\n<td>\u2705 \u53ef\u4ee5<\/td>\n<td>\u8fd0\u884c\u65f6<\/td>\n<td>\u503c\u9700\u8981\u53d8\u5316\u7684\u53d8\u91cf<\/td>\n<\/tr>\n<tr>\n<td><code>final<\/code><\/td>\n<td>\u274c \u4e0d\u884c<\/td>\n<td>\u8fd0\u884c\u65f6<\/td>\n<td>\u8fd0\u884c\u540e\u624d\u77e5\u503c\u7684\u5e38\u91cf<\/td>\n<\/tr>\n<tr>\n<td><code>const<\/code><\/td>\n<td>\u274c \u4e0d\u884c<\/td>\n<td>\u7f16\u8bd1\u65f6<\/td>\n<td>\u7f16\u8bd1\u65f6\u5df2\u77e5\u7684\u5e38\u91cf<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h2>2. \u6ce8\u91ca\u65b9\u6cd5<\/h2>\n<p>Dart \u652f\u6301\u4e09\u79cd\u6ce8\u91ca\uff1a<\/p>\n<h3>\u5355\u884c\u6ce8\u91ca<\/h3>\n<pre><code class=\"language-dart line-numbers\">\/\/ \u8fd9\u662f\u4e00\u884c\u6ce8\u91ca\nint age = 18;  \/\/ \u884c\u5c3e\u6ce8\u91ca\n<\/code><\/pre>\n<h3>\u591a\u884c\u6ce8\u91ca<\/h3>\n<pre><code class=\"language-dart line-numbers\">\/*\n  \u8fd9\u662f\u591a\u884c\u6ce8\u91ca\n  \u53ef\u4ee5\u5199\u5f88\u591a\u5185\u5bb9\n*\/\n<\/code><\/pre>\n<h3>\u6587\u6863\u6ce8\u91ca<\/h3>\n<pre><code class=\"language-dart line-numbers\">\/\/\/ \u8fd9\u662f\u4e00\u4e2a\u8ba1\u7b97\u52a0\u6cd5\u7684\u51fd\u6570\n\/\/\/ \u4f1a\u8fd4\u56de\u4e24\u4e2a\u6570\u7684\u548c\nint add(int a, int b) {\n  return a + b;\n}\n<\/code><\/pre>\n<hr \/>\n<h2>3. \u5b57\u7b26\u4e32\u63d2\u503c<\/h2>\n<p>\u5b57\u7b26\u4e32\u63d2\u503c\u8ba9\u6211\u4eec\u53ef\u4ee5\u628a\u53d8\u91cf\u7684\u503c\u5d4c\u5165\u5230\u5b57\u7b26\u4e32\u4e2d\u3002<\/p>\n<h3>\u57fa\u672c\u63d2\u503c <code>${\u8868\u8fbe\u5f0f}<\/code><\/h3>\n<pre><code class=\"language-dart line-numbers\">var name = 'Alice';\nvar greeting = 'Hello, ${name}!';  \/\/ Hello, Alice!\n<\/code><\/pre>\n<h3>\u7b80\u6d01\u5199\u6cd5 <code>$\u53d8\u91cf\u540d<\/code><\/h3>\n<pre><code class=\"language-dart line-numbers\">var name = 'Alice';\nvar greeting = 'Hello, $name!';  \/\/ Hello, Alice!\n<\/code><\/pre>\n<h3>\u63d2\u503c\u4e2d\u8fdb\u884c\u8ba1\u7b97<\/h3>\n<pre><code class=\"language-dart line-numbers\">var a = 10;\nvar b = 20;\nvar result = '${a + b}';  \/\/ 30\n<\/code><\/pre>\n<h3>\u8bbf\u95ee\u5bf9\u8c61\u5c5e\u6027<\/h3>\n<pre><code class=\"language-dart line-numbers\">var person = Person('Bob', 25);\nprint('Name: <span class=\"katex math inline\">{person.name}, Age:<\/span>{person.age}');\n<\/code><\/pre>\n<hr \/>\n<h2>\u5feb\u901f\u8bb0\u5fc6<\/h2>\n<blockquote><p>\n  \ud83c\udfaf <strong>\u53d8\u91cf\u58f0\u660e<\/strong>\uff1a\u60f3\u6539\u5c31\u7528 <code>var<\/code>\uff0c\u8fd0\u884c\u540e\u5b9a\u5c31\u7528 <code>final<\/code>\uff0c\u7f16\u8bd1\u5df2\u77e5\u5c31\u7528 <code>const<\/code><\/p>\n<p>  \ud83c\udfaf <strong>\u6ce8\u91ca<\/strong>\uff1a\u77ed\u7528 <code>\/\/<\/code>\uff0c\u957f\u7528 <code>\/* *\/<\/code>\uff0c\u6587\u6863\u7528 <code>\/\/\/<\/code><\/p>\n<p>  \ud83c\udfaf <strong>\u5b57\u7b26\u4e32<\/strong>\uff1a\u7b80\u5355\u53d8\u91cf\u7528 <code>name<\/code>\uff0c\u590d\u6742\u8868\u8fbe\u5f0f\u7528 <code>${expr}<\/code>\n<\/p><\/blockquote>\n<hr \/>\n","protected":false},"excerpt":{"rendered":"<p>Dart \u57fa\u672c\u8bed\u6cd5\u603b\u7ed3 1 1. \u53d8\u91cf\u58f0\u660e\u65b9\u5f0f \u5728 Dart \u4e2d\uff0c\u6211\u4eec\u6709\u4e09\u79cd\u65b9\u5f0f\u58f0\u660e\u53d8\u91cf\uff1a var &#8211; \u53ef\u53d8\u53d8\u91cf var name &#823","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-110","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/tachyoncat.top\/index.php\/wp-json\/wp\/v2\/posts\/110","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tachyoncat.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tachyoncat.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tachyoncat.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tachyoncat.top\/index.php\/wp-json\/wp\/v2\/comments?post=110"}],"version-history":[{"count":1,"href":"https:\/\/tachyoncat.top\/index.php\/wp-json\/wp\/v2\/posts\/110\/revisions"}],"predecessor-version":[{"id":113,"href":"https:\/\/tachyoncat.top\/index.php\/wp-json\/wp\/v2\/posts\/110\/revisions\/113"}],"wp:attachment":[{"href":"https:\/\/tachyoncat.top\/index.php\/wp-json\/wp\/v2\/media?parent=110"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tachyoncat.top\/index.php\/wp-json\/wp\/v2\/categories?post=110"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tachyoncat.top\/index.php\/wp-json\/wp\/v2\/tags?post=110"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}