跳至主要內容
產品桌面工具TASTECAD圖面檢視TASTEFILES檔案管理TASTEFTP檔案傳輸TASTESSH遠端工作空間TASTEZIP壓縮與解壓縮TASTEWINM檔案管理開發工具TASTECODERust 整合開發環境TASTESTUDIO整合開發與測試環境TASTEETL資料整合(ETL)伺服器TASTEREMOTE遠端桌面伺服器TASTEGEO空間資訊伺服器TASTEMAIL郵件工作空間投資TASTESTOCK股票自動交易桌面應用程式開始使用下載文件購買所有產品
市集
資訊
技術資訊今日開發資訊開發文件程式語言RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDartWeb 前端框架Next.jsReactVue.js · NuxtSvelteKitAngular伺服器框架Spring BootDjangoFastAPIASP.NET CoreNestJS · Express應用程式與桌面框架TauriFlutterReact NativeElectron演算法演算法基礎核心演算法進階演算法實務演算法
社群專案開發日誌提示詞AI 工具問題作品展示社群指南
合作技術傳授網站建置桌面應用程式建置發布與付款流程銷售合作夥伴聯絡我們
服務遠端桌面安裝包客製
TASTEDEV
產品

桌面工具

TASTECAD再複雜的圖面,也能輕鬆開啟TASTEFILES只挑需要的檔案,最快送達TASTEFTP讓檔案往來,走最俐落的路TASTESSH在你與伺服器之間,築起更穩固的連線TASTEZIP壓得更快,解得更安心TASTEWINM以鍵盤為主、用兩個窗格整理檔案的檔案管理器

開發工具

TASTECODE在一個視窗中完成 Rust 應用程式的編輯、建置、偵錯與測試TASTESTUDIO從編輯到遠端測試,再到經核准的 AI 修正TASTEETL邊看數值,邊搬資料

伺服器

TASTEREMOTE在自己的伺服器上運行的遠端桌面TASTEGEO以 Rust 重新打造相容 GeoServer 的空間資訊伺服器TASTEMAIL把郵件的主導權拿回自己手上

投資

TASTESTOCK何時、做什麼——依你訂下的規則運作的股票自動交易

開始使用

下載所有產品的最新版本文件各產品使用方法購買訂閱與永久授權所有產品一覽全部產品
所有產品
市集資訊
技術

資訊

今日開發資訊語言、框架、GitHub 與 AI 官方發布開發文件語言、框架與演算法指南

程式語言

RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDart

框架

Web 前端框架Next.jsReactVue.js · NuxtSvelteKitAngular
伺服器框架Spring BootDjangoFastAPIASP.NET CoreNestJS · Express
應用程式與桌面框架TauriFlutterReact NativeElectron

演算法

演算法基礎複雜度分析 · 排序 · 搜尋 · 基礎資料結構 · 樹與堆積核心演算法圖形走訪 · 最短路徑與最小生成樹 · 動態規劃 · 貪婪演算法 · 分治法 · 回溯法進階演算法字串演算法 · 數學與數論 · 位元運算 · 線段樹 · 併查集實務演算法程式面試解題策略 · LRU 快取 · 速率限制 · 一致性雜湊
查看全部開發文件
社群
專案探索開發者與作品開發日誌決策與試錯提示詞可重複使用的指令AI 工具問題Claude、Codex、Gemini 的問題與替代做法作品展示已完成的成果社群指南我們如何公開打造
合作
技術傳授用 Rust 與 egui 打造原生應用程式網站建置10 種語言、帳號、文件與下載桌面應用程式建置Rust 與 egui,不用 WebView發布與付款流程簽章、MSI、deb、rpm、AppImage、雜湊銷售合作夥伴推薦即得 30%聯絡我們開發、合作與投資諮詢
服務
遠端桌面用瀏覽器連線你的電腦安裝包客製只裝需要的,設定預先放好
購買
繁
한국어EnglishDeutschEspañolFrançaisItalianoPortuguês (Brasil)日本語简体中文繁體中文
登入
登入
TASTEDEV

從小工具到更好的開發。

support@tastedev.net支持 TASTEDEV
產品產品系列購買文件下載市集客戶支援
社群專案開發日誌提示詞AI 工具問題作品展示
政策關於我們隱私權政策服務條款訂閱條款退款政策社群規範
帳戶登入註冊
訪客
今天
昨天
累計瀏覽
公司名稱
GXSOFT
負責人
CHOI YOUNG GU
營業登記號碼
853-44-00368
地址
9F V24, 351 Gyeongin-ro, Michuhol-gu, Incheon, Republic of Korea
電話
+82-10-4404-1523
電子郵件
whitecalvin@tastedev.net
個人資料保護負責人
CHOI YOUNG GU

© 2026 TASTEDEV產品資訊以經驗證的開發原始碼為準。已發布·持續改進

Dart 文件
Dart
Getting Started with DartSyntax BasicsTypes and DataLibraries and PackagesErrors and TestingKey Concepts
討論

Dart 指南 · 2/6

Syntax Basics

本章目前僅提供英文版。

Dart's syntax is easy to read if you know C, Java or JavaScript. Blocks use curly braces and statements end with semicolons. This chapter covers variable declarations, functions, string interpolation, control flow and collection literals.

Variables: var, final, const

Dart is statically typed, but type inference is strong enough that you can omit most types. There are three ways to declare a variable.

KeywordReassignableValue fixed at
varYesRun time
finalNo (assigned once)Run time
constNoCompile time
void main() {
  var count = 0;            // inferred as int
  count = count + 1;        // can be reassigned

  final now = DateTime.now(); // set once at run time
  const maxUsers = 100;       // compile-time constant
  const colors = ['red', 'green']; // a deeply immutable constant list

  String title = 'Dart';    // explicit types are fine too
  late String description;  // a promise to initialize before use
}

The recommended style is final for local variables that are never reassigned and const for values known at compile time. late separates declaration from initialization; reading a late variable before it is set throws an error at run time.

Strings and interpolation

Strings use single or double quotes (the official style prefers single). Embed values with $variable or ${expression}.

void main() {
  final name = 'Hana';
  final items = 3;
  print('Hello, $name');
  print('Your cart has ${items * 2} items');
  print('Name length: ${name.length}');

  final multiLine = '''
  Multi-line strings
  use triple quotes.
  ''';
  final raw = r'C:\temp\$notInterpolated'; // the r prefix makes a raw string
}

Functions

A function is declared with a return type, a name and a parameter list. When the body is a single expression, the arrow (=>) syntax shortens it.

int add(int a, int b) {
  return a + b;
}

int square(int x) => x * x;

// Named parameters: braces, with required or a default value
String greet({required String name, String greeting = 'Hello'}) {
  return '$greeting, $name!';
}

// Optional positional parameters: brackets, nullable type or default
String label(String text, [String? suffix]) {
  return suffix == null ? text : '$text ($suffix)';
}

void main() {
  print(add(2, 3));                      // 5
  print(square(4));                      // 16
  print(greet(name: 'Min'));             // Hello, Min!
  print(greet(greeting: 'Hi', name: 'Jiwoo'));
  print(label('File'));                  // File
  print(label('File', 'read-only'));     // File (read-only)
}
對本章有疑問嗎?
上一章Getting Started with Dart下一章Types and Data

Named parameters are labeled at the call site, so order does not matter; most Flutter widget constructors use them. Functions are first-class values: you can store them in variables, pass them to other functions, and write anonymous functions such as (x) => x * 2.

Control flow

if/else, for, while and do-while work as in other C-family languages. Conditions must be of type bool; zero or an empty string is never treated as false.

void main() {
  final scores = [72, 95, 88];

  for (var i = 0; i < scores.length; i++) {
    print('#$i: ${scores[i]}');
  }

  for (final score in scores) {
    if (score >= 90) {
      print('$score: excellent');
    } else if (score >= 80) {
      print('$score: good');
    } else {
      print('$score: fair');
    }
  }

  var n = 3;
  while (n > 0) {
    print(n--);
  }

  // A switch expression produces a value
  final day = 6;
  final kind = switch (day) {
    6 || 7 => 'weekend',
    >= 1 && <= 5 => 'weekday',
    _ => 'unknown',
  };
  print(kind);
}

Since Dart 3, a non-empty case in a switch statement does not fall through to the next one, so break is no longer required. In a switch expression each arm yields a value, and you can use patterns such as ||, relational comparisons and _ (match anything), as shown above. Patterns are covered in more detail in the next chapter.

Null-aware operators and cascades

A few operators make everyday code much shorter.

  • a ?? b: use b if a is null.
  • a ??= b: assign b only if a is null.
  • obj?.method(): skip the call and return null if obj is null.
  • obj..a = 1..b(): a cascade that performs several operations on the same object.
void main() {
  String? nickname;
  print(nickname ?? 'Guest');      // Guest
  nickname ??= 'anon';
  print(nickname.length);          // 4 (now known to be non-null)
  String? missing;
  print(missing?.length);          // null

  final buffer = StringBuffer()
    ..write('Dart')
    ..write(' syntax')
    ..write(' notes');
  print(buffer.toString());
}

Collection literals

Lists use [], sets use {} with values, and maps use {} with key: value pairs. Inside a collection you can use if, for and the spread operator (...), which makes it easy to include items conditionally or merge other collections.

final isAdmin = true;
final base = ['Home', 'Search'];

final menu = [
  ...base,
  if (isAdmin) 'Admin',
  for (var i = 1; i <= 2; i++) 'Menu $i',
];
print(menu); // [Home, Search, Admin, Menu 1, Menu 2]

final tags = {'dart', 'flutter', 'dart'}; // Set: duplicates removed
final ages = {'Min': 31, 'Jiwoo': 27};     // Map<String, int>
final empty = <String>{};                 // an empty set needs a type argument
print(tags.length);    // 2
print(ages['Jiwoo']);  // 27

An empty {} is parsed as a map, so add a type argument such as <String>{} when you need an empty set.

Summary

Dart distinguishes variables with var, final and const, and interpolates strings with $ and ${}. Functions support named parameters, optional positional parameters and arrow syntax. Control flow resembles other C-family languages, with switch expressions and patterns on top. Learn ??, ?., cascades and collection if/for, and your code becomes shorter and easier to read.

0 則留言

熱門留言由新到舊

登入 · 登入後即可留言。