FlutterFlutter · Chapterبەش 5 · Lectureوانە 5.1

Meet Dartناسینی Dart

What kind of language Dart is today: object-oriented, C-style, open source, statically typed with inference and sound null safety; the three ways Dart is compiled (JIT, AOT, JavaScript/WebAssembly); the dart command; why Flutter uses Dart; and how Flutter and Dart differ.

ئەمڕۆ چ جۆرە زمانێکە: تەنخواز، شێوەی C، ، خاوەن لەگەڵ و تەواو؛ سێ ڕێگەی کۆمپایلکردنی (JIT، AOT، ⁦JavaScript/WebAssembly⁩)؛ فەرمانی dart؛ بۆچی بەکار دەهێنێت؛ و جیاوازیی و .

17 min read18 خولەک خوێندنەوە · 17 stepsهەنگاو

What you will learnچی فێر دەبیت

  • Describe Dart's main features and correct the out-of-date claims “dynamic language” and “optional typing”.
  • Explain static typing and type inference, and tell a compile-time error from a runtime error.
  • Explain when Flutter uses JIT, AOT and the web compilers.
  • Run and compile Dart programs with the dart command.
  • Say what belongs to Flutter and what to Dart.
  • تایبەتمەندییە سەرەکییەکانی وەسف بکەیت و بانگەشە کۆنەکانی «زمانی ناجێگیر» و «جۆرداریی ئارەزوومەندانە» ڕاست بکەیتەوە.
  • و ڕوون بکەیتەوە و لە جیا بکەیتەوە.
  • ڕوونی بکەیتەوە کەی JIT، AOT و وێب بەکار دەهێنێت.
  • بە فەرمانی dart کار پێبکەیت و وەریانبگێڕیت.
  • بڵێیت چی سەر بە و چی سەر بە .

What Dart isDart چییە

Every Flutter app is written in Dart, a general-purpose made by Google. It was first shown in 2011, reached version 1.0 in 2013 and is now at Dart 3. Dart is (BSD licence), object-oriented, and its code looks like C, Java or JavaScript, with braces and semicolons. Google describes it as a client-optimised language: it is built for the part of software that people see and touch — apps — but it also runs command-line tools and servers.

هەموو بە دەنووسرێت، گشتی کە Google دروستی کردووە. یەکەم جار لە ⁦2011⁩دا نیشان درا، لە ⁦2013⁩دا گەیشتە ⁦1.0⁩ و ئێستا لە 3دایە. (مۆڵەتی BSD)، پشت بە دەبەستێت و کۆدەکەی لە C، Java یان JavaScript دەچێت، بە کەوانەی لوولی و فاریزەخاڵ. Google بە زمانێکی بۆ لای ڕێکخراو وەسفی دەکات: بۆ ئەو بەشەی دروست کراوە کە خەڵک دەیبینن و دەستی لێ دەدەن — — بەڵام ئامرازی و کار پێدەکات.

The smallest Dart programبچووکترین بەرنامەی Darthello.dartDARTType in a terminalلە تێرمیناڵدا بینووسە
void main() {
  print('Hello from Dart!');
}
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 1

Every Dart program starts in main().

هەموو لە main()ـەوە دەست پێدەکات.

Lineدێڕی 2

print writes a line of text. The statement ends with ;.

print دێڕێک دەق دەنووسێت. بە ; کۆتایی دێت.

If you have never met programming languages, compilers or types before, read Programming Languages and How Code Becomes a Running Program first: this lesson shows how Dart does those general ideas.

ئەگەر پێشتر ، یان جۆرەکانت نەناسیوە، سەرەتا زمانەکانی بەرنامەسازی و چۆن کۆد دەبێتە بەرنامەیەکی کارپێکراو بخوێنەرەوە: ئەم وانەیە نیشان دەدات ئەو بیرۆکە گشتییانە چۆن جێبەجێ دەکات.

Quick checkپشکنینی خێراWhich statement about Dart is true?کام ڕستە دەربارەی ڕاستە؟

Welcome to the Dart and Flutter tutorial!Flutter · Englishئینگلیزی · 64K viewsبینین · 1.4K likesلایک · Partبەشی 0:37–1:43 (ofلە 3:18)

A short official overview: what Dart is, how it compiles for many platforms, and how Flutter builds apps for all of them from one codebase.

پوختەیەکی فەرمیی کورت: چییە، چۆن بۆ چەندین کۆمپایل دەکرێت و چۆن لە یەک بۆ هەموویان دروست دەکات.

Plays 0:37-1:43: what Dart is, its developer experience and its multiplatform compilation.

لە ⁦0:37⁩ تا ⁦1:43⁩ پەخش دەبێت: چییە، کارکردن پێی چەند ئاسانە بۆ و چۆن بۆ چەندین کۆمپایل دەکرێت.

Dart in ten pointsDart لە دە خاڵدا

The course notes describe Dart with ten features. Some of them describe the old Dart 1 and are no longer true, so the right-hand column says what is true today, in Dart 3:

تێبینییەکانی وانەکە بە دە تایبەتمەندی وەسف دەکەن. هەندێکیان 1ـی کۆن وەسف دەکەن و ئیتر ڕاست نین، بۆیە ستوونی ڕاست دەڵێت ئەمڕۆ لە 3دا چی ڕاستە:

Dart's features, checked (1–5)تایبەتمەندییەکانی ، پشکنراو (١–٥)
The notes sayتێبینییەکان دەڵێنToday (Dart 3)ئەمڕۆ ( ⁦3⁩)
1. Object-oriented١. تەنخوازYes. Every value is an object made from a class, and functions are values too.بەڵێ. هەموو لە دروست کراوە و .
2. Dynamic language٢. زمانێکی ناجێگیرNot any more. Dart 1 (2011–2018) was. Since Dart 2 types are checked before the program runs (see Types).ئیتر نا. ⁦1 (2011–2018)⁩ وا بوو. لە 2ـەوە جۆرەکان پێش کارکردنی دەپشکنرێن (سەیری جۆرەکان بکە).
3. C-style syntax٣. شێوەی CYes: braces { }, semicolons ;, if (…), for (…).بەڵێ: کەوانەی لوولی { }، فاریزەخاڵ ;، if (…)، for (…).
4. Open source٤. Yes: BSD licence, and Ecma approved the language as the ECMA-408 standard in 2014.بەڵێ: مۆڵەتی BSD و Ecma لە ⁦2014⁩دا زمانەکەی وەک ستانداردی ⁦ECMA-408⁩ پەسەند کرد.
5. Scalable language for UI web and mobile apps٥. زمانێکی فراوانبوو بۆ وێب و مۆبایلYes — this is Dart's main purpose (client-optimised), from small apps to very large ones.بەڵێ — ئەمە ئامانجی سەرەکیی (بۆ لای ڕێکخراو)، لە بچووکەوە تا زۆر گەورە.
Quick checkپشکنینی خێراWhich feature from the notes is no longer true for Dart 3?کام تایبەتمەندیی تێبینییەکان بۆ 3 ئیتر ڕاست نییە؟

Dart in 100 SecondsFireship · Englishئینگلیزی · 1.1M viewsبینین · 42K likesلایک

Dart in under three minutes: JIT and AOT compiling, the event loop and isolates, static types with type inference, sound null safety and the pub package manager.

لە کەمتر لە سێ خولەکدا: کۆمپایلکردنی JIT و AOT، و isolates، لەگەڵ ، و pub.

Whole video (2:30, October 2021): its Dart code (int? age, var, a function that takes a callback) still runs in Dart 3.

هەموو ڤیدیۆکە (⁦2:30⁩، ساڵی ⁦2021⁩): کۆدە (⁦int? age⁩، var، کە callback وەردەگرێت) هێشتا لە ⁦Dart 3⁩ـدا کار دەکات.

Dart in ten pointsDart لە دە خاڵدا

Points 6 to 10خاڵەکانی ٦ تا ١٠

The second half of the list. Point 6 is the other claim that only fits the old Dart 1:

نیوەی دووەمی لیستەکە. خاڵی ٦ ئەو بانگەشەیەی ترە کە تەنها لەگەڵ 1ـی کۆن دەگونجێت:

Dart's features, checked (6–10)تایبەتمەندییەکانی ، پشکنراو (٦–١٠)
The notes sayتێبینییەکان دەڵێنToday (Dart 3)ئەمڕۆ ( ⁦3⁩)
6. Optional static typing and type checks٦. ئارەزوومەندانە و پشکنینی جۆرCorrected. Types are always there; only writing them is optional, because Dart infers them. Most checks happen before running.ڕاستکراوەتەوە. جۆرەکان هەمیشە هەن؛ تەنها نووسینیان ئارەزوومەندانەیە، چونکە خۆی دەیاندۆزێتەوە. زۆربەی پشکنینەکان پێش کارکردن ڕوو دەدەن.
7. Single inheritance with mixins٧. تاک لەگەڵ Yes: a class extends one class, and can add extra abilities with mixins (see Dart Classes, Inheritance and Mixins).بەڵێ: تەنها لە یەک وەردەگرێت و دەتوانێت توانای زیادە بە زیاد بکات (سەیری کلاسەکان، بۆماوە و میکسینەکان بکە).
8. Influenced by Java, C++, C# and JavaScript٨. کاریگەریی Java، ⁦C++⁩، ⁦C#⁩ و JavaScriptـی لەسەرەYes: strongly typed languages (Java, C++, C#) and the loosely typed JavaScript.بەڵێ: زمانە جۆرداری بەهێزەکان (Java، ⁦C++⁩، ⁦C#⁩) و JavaScriptـی جۆرداری لاواز.
9. Used for mobile, web, desktop and IoT with Flutter٩. بۆ مۆبایل، وێب، کۆمپیوتەر و لەگەڵ Yes; Flutter apps can also run on some embedded devices.بەڵێ؛ دەتوانن لەسەر هەندێک ئامێری ناوەکیش کار بکەن.
10. Compiled language١٠. زمانێکی کۆمپایلکراوYes, in three ways: JIT, AOT and to JavaScript/WebAssembly (see Compilation).بەڵێ، بە سێ ڕێگە: JIT، AOT و بۆ ⁦JavaScript/WebAssembly⁩ (سەیری کۆمپایلکردن بکە).
Quick checkپشکنینی خێراIn Dart 3, what is optional about types?لە 3دا چی دەربارەی جۆرەکان ئارەزوومەندانەیە؟

Dart in ten pointsDart لە دە خاڵدا

C-style syntaxداڕستنی شێوەی C

Dart was influenced by strongly typed languages such as , C++ and C#, and by the loosely typed . From the C family it took its look: braces { } group statements, a semicolon ; ends each statement, and conditions go in parentheses. Line breaks and indentation do not change the meaning — they only help people read the code. (In Python, indentation is the meaning; see Your First Program.)

کاریگەریی زمانە جۆرداری بەهێزەکانی وەک ، ⁦C++⁩ و ⁦C#⁩ـی لەسەرە و هەروەها جۆرداری لاواز. لە خێزانی Cـەوە شێوەکەی وەرگرتووە: کەوانەی لوولی { } کۆ دەکاتەوە، فاریزەخاڵ ; کۆتایی بە هەر دەهێنێت و لە ناو کەوانەدا دەنووسرێن. دێڕی نوێ و واتاکە ناگۆڕن — تەنها یارمەتی خەڵک دەدەن کۆدەکە بخوێننەوە. (لە خودی واتاکەیە؛ سەیری یەکەم بەرنامەکەت بکە.)

Braces, semicolons and parenthesesکەوانەی لوولی، فاریزەخاڵ و کەوانەcstyle.dartDARTType in a terminalلە تێرمیناڵدا بینووسە
// Braces { } group statements; a semicolon ends each statement.
void main() {
  var total = 0;
  for (var i = 1; i <= 3; i++) {
    total += i;
  }
  if (total > 5) {
    print('Total is $total');
  }
}
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 4-6

The for loop's three parts are in parentheses; its body is in braces.

سێ بەشەکەی for لە ناو کەوانەدان؛ ناوەڕۆکەکەی لە ناو کەوانەی لوولیدایە.

Lineدێڕی 7

The condition of if must be in parentheses.

if دەبێت لە ناو کەوانەدا بێت.

Quick checkپشکنینی خێراIn Dart, what tells the computer where a statement ends?لە چی بە کۆمپیوتەر دەڵێت لە کوێ کۆتایی دێت؟

Types: static, with inferenceجۆرەکان: جێگیر، لەگەڵ دەرەنجامگیریی جۆر

Every value in Dart has a : int for whole numbers, String for text and so on. You may write the type yourself, or write var and let Dart work it out from the first value. That second way is called . Either way, the variable gets a fixed type.

هەموو لە هەیە: int بۆ ، String بۆ دەق و هتد. دەتوانیت جۆرەکە خۆت بنووسیت، یان var بنووسیت و ڕێگە بدەیت لە یەکەم بیدۆزێتەوە. ڕێگەی دووەم پێی دەوترێت . بە هەر ڕێگەیەک بێت، جۆرێکی جێگیر وەردەگرێت.

A written type and an inferred typeجۆرێکی نووسراو و جۆرێکی دۆزراوەtyping.dartDARTType in a terminalلە تێرمیناڵدا بینووسە
void main() {
  int age = 25; // explicit type
  var name = 'Aram'; // type inferred as String
  print('$age ${name.runtimeType}');
}
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 2

int is written by you.

int خۆت دەینووسیت.

Lineدێڕی 3

var: Dart sees 'Aram' and decides that name is a String.

var: 'Aram' دەبینێت و بڕیار دەدات کە name (String).

Lineدێڕی 4

runtimeType asks a value for its type while the program runs.

runtimeType لە کاتی کارکردنی جۆری دەپرسێت.

Because name is a String, Dart refuses to put a number in it. It does not wait until the program runs — the mistake is found before running, by the editor and the compiler:

چونکە name Stringـە، ڕێگە نادات ژمارەیەکی تێدا دابنرێت. چاوەڕێ ناکات تا کار دەکات — هەڵەکە پێش کارکردن دەدۆزرێتەوە، لەلایەن دەستکاریکەر و :

Putting an int into a String variableدانانی int لە گۆڕاوێکی Stringـداtype_error.dartDARTType in a terminalلە تێرمیناڵدا بینووسە
void main() {
  var name = 'Aram'; // Dart infers String
  name = 5; // a number is not a String
  print(name);
}
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3

The compiler stops here. The program does not start at all.

لێرەدا دەوەستێت. هەر دەست پێناکات.

Four frames in a code editor. 1: var name = 'Aram' and a label that name is a String. 2: the line name = 5 gets a red underline and the message that an int can't be assigned to a String. 3: the run button is blocked: the program does not start. 4: the line is changed to name = 'Hana', the mark turns green and the program prints Hana.
Four frames in a code editor. 1: var name = 'Aram' and a label that name is a String. 2: the line name = 5 gets a red underline and the message that an int can't be assigned to a String. 3: the run button is blocked: the program does not start. 4: the line is changed to name = 'Hana', the mark turns green and the program prints Hana.
The type checker catches the mistake while you type, before the program can run.پشکنەری جۆر لە کاتی نووسیندا هەڵەکە دەگرێت، پێش ئەوەی کار بکات.CêIT
Quick checkپشکنینی خێراvar count = 10; What is the type of count, and can it later hold 'ten'?var count = 10; جۆری count چییە و دواتر دەتوانێت 'ten' هەڵبگرێت؟

Types: static, with inferenceجۆرەکان: جێگیر، لەگەڵ دەرەنجامگیریی جۆر

Is Dart “dynamic”?ئایا Dart «ناجێگیر»ـە؟

In , as in Python, a variable can hold a number now and text later, and type mistakes appear only while the program runs. Dart 1 worked like that. Modern Dart uses , but it keeps one door open: the type dynamic switches the checks off for one variable. Use it only when you really cannot know a type (for example raw JSON), because the mistakes come back at runtime:

لە ، وەک ، دەتوانێت ئێستا ژمارەیەک و دواتر دەقێک هەڵبگرێت و هەڵەکانی جۆر تەنها لە کاتی کارکردنی دەردەکەون. 1 بەو شێوەیە بوو. ئەمڕۆ بەکار دەهێنێت، بەڵام دەرگایەکی کراوە هێشتووەتەوە: جۆری dynamic پشکنینەکان بۆ یەک دەکوژێنێتەوە. تەنها کاتێک بەکاری بهێنە کە بە ڕاستی ناتوانیت جۆرەکە بزانیت (بۆ نموونە JSONـی خاو)، چونکە هەڵەکان لە دەگەڕێنەوە:

dynamic turns the checks offdynamic پشکنینەکان دەکوژێنێتەوەdynamic.dartDARTType in a terminalلە تێرمیناڵدا بینووسە
void main() {
  dynamic box = 'Aram'; // dynamic: "do not check my types"
  print(box);
  box = 5; // allowed, because box is dynamic
  print(box);
  print(box.length); // compiles, but an int has no length
}
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 4

Allowed: a dynamic variable may change type.

ڕێگەپێدراوە: dynamic دەتوانێت جۆر بگۆڕێت.

Lineدێڕی 6

The compiler cannot check this, so the error appears only when the line runs: a .

ناتوانێت ئەمە بپشکنێت، بۆیە تەنها کاتێک ئەم دێڕە کار دەکات دەردەکەوێت: .

Compare with var: with var the same mistake was caught before running. That is the whole point of static types. Read more about the two styles in Programming Languages and see Python's way in Variables and Data Types.

بەراوردی بکە لەگەڵ var: بە var هەمان هەڵە پێش کارکردن گیرا. ئەمە هەموو مەبەستی جۆرە جێگیرەکانە. دەربارەی ئەم دوو شێوازە لە زمانەکانی بەرنامەسازی زیاتر بخوێنەرەوە و ڕێگەی لە گۆڕاوەکان و جۆرەکانی دراوە ببینە.

Quick checkپشکنینی خێراWhy should you avoid dynamic when you know the type?بۆچی کاتێک جۆرەکە دەزانیت دەبێت خۆت لە dynamic بپارێزیت؟

Types: static, with inferenceجۆرەکان: جێگیر، لەگەڵ دەرەنجامگیریی جۆر

Sound null safetyپاراستن لە بێنرخ

Dart 3 adds one more promise: sound . A normal type such as String can never be null (“no value”). If a variable may be empty, you must say so with a question mark: String?. The compiler then makes you check for null before you use it. In many languages a forgotten null crashes apps; in Dart it becomes a compile-time error. You will learn the syntax — ?, !, ?? and late — in Dart Basics.

3 بەڵێنێکی تر زیاد دەکات: تەواو. جۆرێکی ئاسایی وەک String هەرگیز ناتوانێت null (، «هیچ ») بێت. ئەگەر لەوانەیە بەتاڵ بێت، دەبێت بە نیشانەی پرسیار بیڵێیت: String?. ئینجا ناچارت دەکات پێش بەکارهێنان null بپشکنیت. لە زۆر زماندا nullـێکی لەبیرکراو دەڕووخێنێت؛ لە دەبێتە . — ?، !، ?? و late — لە بنەماکانی Dart فێر دەبیت.

Quick checkپشکنینی خێراWhich variable may hold null in Dart 3?لە 3دا کام دەتوانێت null هەڵبگرێت؟

Three ways to compile Dartسێ ڕێگەی کۆمپایلکردنی Dart

A computer cannot run Dart text directly; a must translate it. Dart has three ways, and Flutter uses each one at a different moment:

کۆمپیوتەر ناتوانێت ڕاستەوخۆ دەقی کار پێبکات؛ دەبێت وەریبگێڕێت. سێ ڕێگەی هەیە و هەریەکەیان لە کاتێکی جیاوازدا بەکار دەهێنێت:

  • (JIT) — while you develop. The Dart compiles code while it runs, and only the parts that are actually used. When you change code, it recompiles just the changed parts — that is what makes hot reload and hot restart possible, without a full rebuild.
  • (AOT) — for release. Before the app is installed, the whole program is translated into for the phone's or computer's processor (ARM or x64). The app starts fast and runs smoothly, because nothing is left to translate on the user's phone.
  • To the web. For browsers, Dart is compiled to optimised (the dart2js compiler) or to WebAssembly, so it runs in every modern browser.
  • ⁦(JIT)⁩ — لە کاتی گەشەپێداندا. کۆد لە کاتی کارکردندا وەردەگێڕێت، تەنها ئەو بەشانەی بە ڕاستی بەکار دێن. کاتێک کۆد دەگۆڕیت، تەنها بەشە گۆڕاوەکان دووبارە وەردەگێڕێت — ئەمە وا دەکات و بێ بیلدکردنەوەی تەواو بکرێن.
  • ⁦(AOT)⁩ — بۆ . پێش ئەوەی جێگیر بکرێت، هەموو وەردەگێڕدرێت بۆ بۆ پرۆسێسەری مۆبایلەکە یان کۆمپیوتەرەکە (ARM یان ⁦x64⁩). خێرا دەست پێدەکات و نەرم کار دەکات، چونکە هیچ شتێک نەماوە لەسەر مۆبایلی وەربگێڕدرێت.
  • بۆ وێب. بۆ ، وەردەگێڕدرێت بۆ باشکراو ( dart2js) یان بۆ WebAssembly، بۆیە لە هەموو نوێدا کار دەکات.
One Dart source file branches into three paths. Development: the Dart VM compiles just in time, which allows hot reload. Release: the AOT compiler makes ARM or x64 machine code for Android, iOS and desktop apps. Web: dart2js or dart2wasm make JavaScript or WebAssembly for the browser.یەک فایلی Dart دەبێتە سێ ڕێگە. گەشەپێدان: ئامێرە گریمانەییەکەی Dart بە JIT وەردەگێڕێت، کە ڕێگە بە بارکردنەوەی گەرم دەدات. وەشانی بڵاوکراوە: کۆمپایلەری AOT کۆدی ئامێری ARM یان x64 بۆ ئەپی ئەندرۆید، iOS و کۆمپیوتەر دروست دەکات. وێب: dart2js یان dart2wasm JavaScript یان WebAssembly بۆ تۆڕگەڕ دروست دەکەن.
One language, three ways to run it.یەک زمان، سێ ڕێگەی کارپێکردن.CêIT

In short: AOT gives speed in production; JIT gives flexibility and quick updates while you develop.

بە کورتی: AOT خێرایی لە بەرهەمی کۆتاییدا دەدات؛ JIT نەرمی و نوێکردنەوەی خێرا لە کاتی گەشەپێداندا دەدات.

Quick checkپشکنینی خێراYou publish your Flutter app on Google Play. Which compilation does the app on users' phones use? لە ⁦Google Play⁩ بڵاو دەکەیتەوە. لەسەر مۆبایلی کام کۆمپایلکردن بەکار دەهێنێت؟

Three ways to compile Dartسێ ڕێگەی کۆمپایلکردنی Dart

AOT is not JavaScriptAOT JavaScript نییە

The general ideas — compilers, interpreters, bytecode and JIT — are explained for every language in How Code Becomes a Running Program.

بیرۆکە گشتییەکان — ، ، و JIT — بۆ هەموو زمانێک لە چۆن کۆد دەبێتە بەرنامەیەکی کارپێکراو ڕوون کراونەتەوە.

Quick checkپشکنینی خێراWhich tool turns Dart into JavaScript for web browsers?کام ئامراز دەگۆڕێت بۆ بۆ ؟

Three ways to compile Dartسێ ڕێگەی کۆمپایلکردنی Dart

The dart commandفەرمانی dart

Dart also runs on its own, outside Flutter: the stand-alone Dart VM runs programs in a command-line window. The dart command comes inside the Flutter SDK, so you already have it. These are real runs of the hello.dart program from the first screen:

بە تەنهاش کار دەکات، دەرەوەی : بە سەربەخۆیی لە پەنجەرەیەکی کار پێدەکات. فەرمانی dart لە ناو ، بۆیە پێشتر هەتە. ئەمانە جێبەجێکردنی ڕاستەقینەی hello.dartـن لە یەکەم شاشەوە:

Real output on a Mac (Dart 3.12.2; the long path shortened to ...)دەرخستەی ڕاستەقینە لەسەر Mac (Dart ⁦3.12.2⁩؛ ڕێڕەوە درێژەکە بە ... کورت کراوەتەوە)BASHType in a terminalلە تێرمیناڵدا بینووسە
$ dart run hello.dart
Hello from Dart!

$ dart compile exe hello.dart -o hello
Generated: .../hello
$ ./hello
Hello from Dart!

$ dart compile js hello.dart -o hello.js
Compiled 10,315,087 input bytes (5,274,447 characters source) to 12,103 characters JavaScript in 0.63 seconds

$ dart compile wasm hello.dart -o hello.wasm
Generated wasm module 'hello.wasm', and JS init file 'hello.mjs'.
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 1

dart run: the Dart VM compiles just in time and runs it — the development way.

dart run: بە JIT وەریدەگێڕێت و کاری پێدەکات — ڕێگەی گەشەپێدان.

Lineدێڕی 4-7

dart compile exe: AOT. The result hello is a native program (5.7 MB here, because the small Dart runtime is packed inside) that runs without Dart installed.

dart compile exe: AOT. ئەنجامەکە hello ڕەسەنە (لێرە ⁦5.7 MB⁩، چونکە ئەو بەشانەی کە بۆ کارکردن پێویستن لە ناویدا پێچراون) کە بەبێ کار دەکات.

Lineدێڕی 9

dart compile js: the web compiler (dart2js) makes a 12 KB JavaScript file.

dart compile js: وێب ⁦(dart2js)⁩ ⁦12 KB⁩ دروست دەکات.

Lineدێڕی 12

dart compile wasm: the same program as WebAssembly.

dart compile wasm: هەمان وەک WebAssembly.

Quick checkپشکنینی خێراWhich command runs tool.dart the quick development way, without making a file?کام فەرمان tool.dart بە ڕێگەی خێرای گەشەپێدان کار پێدەکات، بەبێ دروستکردنی ؟

Why Dart?بۆچی Dart؟

The course gives six reasons to use Dart. Here they are, each explained and brought up to date:

وانەکە شەش هۆکار بۆ بەکارهێنانی دەدات. ئەمانەن، هەریەکەیان ڕوون کراوەتەوە و نوێ کراوەتەوە:

  1. Platform-independent. The Dart SDK runs on Windows, macOS and Linux, and the same Dart code can be compiled for Android, iOS, the web and desktops.
  2. Open source and standardised. It is free for everyone under the BSD licence, and Ecma approved its specification as ECMA-408 in 2014.
  3. Object-oriented. It has classes, inheritance, interfaces and mixins. (The notes add “optional type features”; today types are static and inferred — see Types.)
  4. Good for real-time apps. The notes say “because of its stability”. The concrete reasons are AOT machine code (fast start, smooth animation without pauses) and a garbage collector made for the many short-lived objects a UI creates.
  5. Compiles to JavaScript. The dart2js compiler turns Dart into JavaScript that runs in all modern browsers; WebAssembly is now possible too.
  6. A stand-alone VM. The Dart VM runs Dart programs in a command-line window (dart run), so you can practise Dart without any app.
  1. سەربەخۆ لە . لەسەر Windows، macOS و Linux کار دەکات و هەمان کۆدی دەتوانرێت بۆ ئەندرۆید، iOS، وێب و کۆمپیوتەر وەربگێڕدرێت.
  2. و ستانداردکراو. بە مۆڵەتی BSD بۆ هەمووان بێبەرانبەرە و Ecma لە ⁦2014⁩دا وەسفەکەی وەک ⁦ECMA-408⁩ پەسەند کرد.
  3. . ، ، و هەیە. (تێبینییەکان «تایبەتمەندیی جۆری ئارەزوومەندانە» زیاد دەکەن؛ ئەمڕۆ جۆرەکان جێگیرن و دەدۆزرێنەوە — سەیری جۆرەکان بکە.)
  4. باش بۆ . تێبینییەکان دەڵێن «بەهۆی جێگیرییەکەیەوە». هۆکارە ڕوونەکان ئەمانەن: AOT (دەستپێکردنی خێرا، نەرم بەبێ وەستان) و کۆکەرەوەی خۆکاری کە بۆ ئەو هەموو کورتخایەنە دروست کراوە کە ڕووکارێک دروستیان دەکات.
  5. بۆ وەردەگێڕدرێت. dart2js دەگۆڕێت بۆ کە لە هەموو نوێدا کار دەکات؛ WebAssemblyـش ئێستا دەکرێت.
  6. کە بە تەنها کار دەکات. لە پەنجەرەی کار پێدەکات (dart run)، بۆیە دەتوانیت بەبێ هیچ ڕاهێنان لەسەر بکەیت.

Why the Flutter team picked Dart for its framework (JIT for stateful hot reload, AOT for speed, layout written in the same language) is explained in What Is Flutter?.

بۆچی تیمی بۆ هەڵبژارد (JIT بۆ ، AOT بۆ خێرایی، بە هەمان زمان) لە Flutter چییە؟ ڕوون کراوەتەوە.

Quick checkپشکنینی خێراWhich reason best explains why Flutter apps start quickly on a phone?کام هۆکار باشتر ڕوونی دەکاتەوە کە بۆچی لەسەر مۆبایل خێرا دەست پێدەکەن؟

Flutter and Dart are not the sameFlutter و Dart یەک شت نین

Flutter vs Dart بەرامبەر
AspectلایەنFlutterDart
PurposeئامانجA UI framework (toolkit) for building apps for mobile, web and desktop from one codebase. ڕووکار بۆ دروستکردنی بۆ مۆبایل، وێب و کۆمپیوتەر لە یەک .A general-purpose programming language. گشتی.
SyntaxYou describe the screen declaratively with widgets: you say what it should look like, and Flutter redraws it when data changes.شاشەکە بە شێوەی وەسفی و بە دەنووسیت: دەڵێیت چۆن بێت و کاتێک دەگۆڕێت دووبارە دەیکێشێتەوە.Looks like other object-oriented languages such as Java or C++.لە زمانە تەنخوازەکانی تری وەک Java یان ⁦C++⁩ دەچێت.
ArchitectureWidget-based: “everything is a widget” — text, padding, rows and whole screens.لەسەر بنەمای : «هەموو شتێک » — دەق، بۆشایی، ڕیز و شاشەی تەواو.Supports several programming styles, including object-oriented and functional.پشتگیریی چەند شێوازێکی دەکات، لەوانە تەنخواز و کرداری.
PlatformsAndroid, iOS, web, Windows, macOS and Linux.ئەندرۆید، iOS، وێب، Windows، macOS و Linux.Apps (through Flutter), web pages, servers and command-line tools. (لە ڕێگەی )، پەڕەی وێب، و ئامرازی .
Quick checkپشکنینی خێراWhich sentence describes Dart, not Flutter?کام ڕستە وەسف دەکات، نەک ؟

Flutter and Dart are not the sameFlutter و Dart یەک شت نین

An analogy: a language and a book of formsلێکچوواندنێک: زمان و کتێبێکی فۆرم

Kurdish and a book of ready formsکوردی و کتێبێکی فۆرمی ئامادە

Dart is like the Kurdish language: you can write anything in it — a letter, a poem, a shop sign. Flutter is like a book of ready-made, well-designed forms written in Kurdish (invitations, certificates, menus) that you fill in and arrange. You still need the language to use the forms, but the forms make one job — apps — much faster.

وەک زمانی کوردییە: دەتوانیت هەموو شتێکی پێ بنووسیت — نامە، شیعر، تابلۆی دوکان. وەک کتێبێکی فۆرمی ئامادە و جوان دیزاینکراوە کە بە کوردی نووسراون (بانگهێشت، بڕوانامە، مینیو) و تۆ پڕیان دەکەیتەوە و ڕێکیان دەخەیت. هێشتا بۆ بەکارهێنانی فۆرمەکان پێویستت بە زمانەکەیە، بەڵام فۆرمەکان یەک کار — — زۆر خێراتر دەکەن.

Where the analogy stops workingسنووری ئەم نموونەیە

Flutter is not only forms written in Dart: its engine is written in C and C++, and it draws every pixel itself.

تەنها فۆرمی نووسراو بە نییە: بزوێنەرەکەی بە C و ⁦C++⁩ نووسراوە و هەموو خۆی دەکێشێت.

Quick checkپشکنینی خێراIn the analogy, which part is Flutter?لەم لێکچوواندنەدا، کام بەش ؟

Common mistakesهەڵە باوەکان

Myths about Dartبیرۆکە هەڵەکان دەربارەی
MistakeهەڵەThe factڕاستییەکە
“Dart is dynamically typed, like JavaScript.”« هەیە، وەک JavaScript.»Since Dart 2 it is statically typed with inference; only dynamic turns checks off.لە 2ـەوە لەگەڵ هەیە؛ تەنها dynamic پشکنینەکان دەکوژێنێتەوە.
“var means the variable can hold anything.”«var واتە دەتوانێت هەموو شتێک هەڵبگرێت.»var means “Dart, find the type from the first value”. The type is then fixed.var واتە «، جۆرەکە لە یەکەم بدۆزەرەوە». پاشان جۆرەکە جێگیر دەبێت.
“AOT compiles to JavaScript.”«AOT بۆ وەردەگێڕێت.»AOT makes native machine code. JavaScript (and WebAssembly) come from the web compilers.AOT ڕەسەن دروست دەکات. (و WebAssembly) لە وێبەوە دێن.
“Release apps use hot reload.”« بەکار دەهێنن.»Hot reload needs JIT, so it works only in debug mode. پێویستی بە JIT هەیە، بۆیە تەنها لە دۆخی کار دەکات.
Installing Dart separately for Flutter بە جیا بۆ The Flutter SDK already contains the right Dart SDK. پێشتر گونجاوی تێدایە.
Calling Flutter a programming languageناونانی بە Flutter is a framework; Dart is the language. ؛ زمانەکەیە.

Exercisesڕاهێنانەکان

Exerciseڕاهێنان1. Predict the result١. ئەنجامەکە پێشبینی بکە

What happens when you run this program with dart run? Explain in one sentence.

کاتێک ئەم بە dart run کار پێدەکەیت چی ڕوو دەدات؟ بە یەک ڕستە ڕوونی بکەرەوە.

predict.dartDART
void main() {
  var x = 3;
  x = 'three';
  print(x);
}
Show answerوەڵامەکە پیشان بدە
predict.dartDARTType in a terminalلە تێرمیناڵدا بینووسە
void main() {
  var x = 3; // x is an int from now on
  x = 'three';
  print(x);
}

The program does not start. var x = 3 makes x an int, so assigning the String 'three' is a compile-time error.

دەست پێناکات. var x = 3 x دەکات بە int، بۆیە دانانی 'three'ـی String .

Exerciseڕاهێنان2. Which compilation?٢. کام کۆمپایلکردن؟

Say JIT, AOT or JavaScript/WebAssembly for each: (a) you press save and the app on the emulator updates; (b) Shilan downloads your app from the App Store; (c) your Flutter app opens in Chrome on a classmate's laptop; (d) you run dart compile exe to make a tool for a server.

بۆ هەریەکەیان بڵێ JIT، AOT یان ⁦JavaScript/WebAssembly⁩: (أ) پاشەکەوت دادەگریت و لەسەر نوێ دەبێتەوە؛ (ب) Shilan لە ⁦App Store⁩ دادەبەزێنێت؛ (ج) لە Chromeـی هاوپۆلێکتدا دەکرێتەوە؛ (د) dart compile exe جێبەجێ دەکەیت بۆ دروستکردنی ئامرازێک بۆ .

Show answerوەڵامەکە پیشان بدە
  • (a) JIT — hot reload during development.
  • (b) AOT — a release build in machine code.
  • (c) JavaScript or WebAssembly — the web compilers.
  • (d) AOT — a native executable.
  • (أ) JIT — لە کاتی گەشەپێداندا.
  • (ب) AOT — بە .
  • (ج) یان WebAssembly — وێب.
  • (د) AOT — ڕەسەنی جێبەجێکراو.
Exerciseڕاهێنان3. True or false?٣. ڕاست یان هەڵە؟

Correct the false sentences: (a) Dart is open source with a BSD licence. (b) In Dart 3 you must write the type of every variable. (c) A Dart class can extend two classes. (d) Dart was influenced by Java and JavaScript. (e) The stand-alone Dart VM can run programs from the command line.

ڕستە هەڵەکان ڕاست بکەرەوە: (أ) بە مۆڵەتی BSD. (ب) لە 3دا دەبێت جۆری هەموو بنووسیت. (ج) دەتوانێت لە دوو وەربگرێت. (د) کاریگەریی Java و JavaScriptـی لەسەرە. (هـ) بە تەنها دەتوانێت لە کار پێبکات.

Show answerوەڵامەکە پیشان بدە
  • (a) True.
  • (b) False — writing the type is optional; with var Dart infers it. The type itself is always there.
  • (c) False — single inheritance: one superclass, plus any number of mixins.
  • (d) True (also C++ and C#).
  • (e) True — dart run.
  • (أ) ڕاستە.
  • (ب) هەڵەیە — نووسینی جۆرەکە ئارەزوومەندانەیە؛ بە var خۆی دەیدۆزێتەوە. خودی جۆرەکە هەمیشە هەیە.
  • (ج) هەڵەیە — تاک: یەک باوان، لەگەڵ هەر ژمارەیەک .
  • (د) ڕاستە (هەروەها ⁦C++⁩ و ⁦C#⁩).
  • (هـ) ڕاستە — dart run.
Exerciseڕاهێنان4. Try the dart command٤. فەرمانی dart تاقی بکەرەوە

Save the hello.dart program from the first screen. Run it with dart run, then make a native program with dart compile exe hello.dart -o hello and run that. Why is the native file several megabytes, although the program is one line?

hello.dartـی یەکەم شاشە پاشەکەوت بکە. بە dart run کاری پێبکە، پاشان بە dart compile exe hello.dart -o hello ڕەسەن دروست بکە و کاری پێبکە. بۆچی چەند مێگابایتە، هەرچەندە یەک دێڕە؟

Show answerوەڵامەکە پیشان بدە

Both print Hello from Dart!. The native file (about 5.7 MB on our Mac) contains the machine code and a small Dart runtime (memory management, the core libraries it needs), so it runs on a computer with no Dart installed.

هەردووکیان Hello from Dart! چاپ دەکەن. (نزیکەی ⁦5.7 MB⁩ لەسەر Macـەکەمان) و ئەو بەشانەی لە خۆ دەگرێت کە بۆ کارکردن پێویستن (بەڕێوەبردنی و )، بۆیە لەسەر کۆمپیوتەرێک کار دەکات کە لەسەر جێگیر نەکراوە.

Exerciseڕاهێنان5. Flutter or Dart?٥. Flutter یان Dart؟

Sort these into Flutter and Dart: (a) if, for and var; (b) Text and Scaffold widgets; (c) hot reload; (d) dart2js; (e) “one codebase for six platforms”.

ئەمانە دابەش بکە بەسەر و : (أ) if، for و var؛ (ب) Text و Scaffold؛ (ج) ؛ (د) dart2js؛ (هـ) «یەک بۆ شەش ».

Show answerوەڵامەکە پیشان بدە
  • Dart: (a) and (d) — language keywords and the language's web compiler.
  • Flutter: (b) and (e). Hot reload (c) is a Flutter feature built on Dart's JIT — both are involved.
  • : (أ) و (د) — زمانەکە و وێبی زمانەکە.
  • : (ب) و (هـ). (ج) تایبەتمەندییەکی کە لەسەر JITـی دروست کراوە — هەردووکیان بەشدارن.

Summaryپوختە

  • Dart is Google's open-source (BSD, ECMA-408), object-oriented, C-style language; Flutter apps are written in it.
  • Dart 3 is statically typed with type inference and sound null safety. “Dynamic” and “optional typing” describe old Dart 1; dynamic is only an opt-out.
  • JIT while you develop (hot reload), AOT machine code for release, JavaScript or WebAssembly for the web.
  • The dart command runs (dart run) and compiles (dart compile exe/js/wasm) programs without Flutter.
  • Flutter is the UI framework; Dart is the language underneath.
  • (BSD، ⁦ECMA-408⁩)، تەنخواز و شێوەی Cـی Googleـە؛ پێی دەنووسرێن.
  • 3 لەگەڵ و تەواوی هەیە. «ناجێگیر» و «جۆرداریی ئارەزوومەندانە» 1ـی کۆن وەسف دەکەن؛ dynamic تەنها دەرچوونێکە.
  • JIT لە کاتی گەشەپێداندا ()، AOT بۆ ، یان WebAssembly بۆ وێب.
  • فەرمانی dart بەبێ کار پێدەکات (dart run) و وەردەگێڕێت (dart compile exe/js/wasm).
  • ڕووکارە؛ زمانەکەی ژێرەوەیە.
Review questionsپرسیارەکانی پێداچوونەوە
What is type inference?دەرەنجامگیریی جۆر چییە؟

Dart works out a variable's type from its first value, as with var name = 'Aram'; (a String).

جۆری لە یەکەم دەدۆزێتەوە، وەک var name = 'Aram'; ⁦(String)⁩.

Why is a compile-time error better than a runtime error?بۆچی هەڵەیەکی کاتی کۆمپایلکردن لە هەڵەی کاتی جێبەجێکردن باشترە؟

It is found before the app runs, so no user ever sees it.

پێش کارکردنی دەدۆزرێتەوە، بۆیە هیچ هەرگیز نایبینێت.

What does AOT give a released app?AOT چی بە ئەپێکی بڵاوکراوە دەدات؟

Native machine code, so it starts fast and runs smoothly.

ڕەسەن، بۆیە خێرا دەست پێدەکات و نەرم کار دەکات.

Videoڤیدیۆ

Watch a videoسەیری ڤیدیۆیەک بکە

A video that viewers liked a lot and praised in their comments, chosen for this lesson.ڤیدیۆیەک کە بینەران زۆریان پێ خۆش بووە و لە کۆمێنتەکانیاندا ستایشیان کردووە، بۆ ئەم وانەیە هەڵبژێردراوە.

Dart - Introduction 01 | KurdishFawzi Dev · Kurdish (Sorani)کوردی (سۆرانی) · 4.5K viewsبینین · 124 likesلایک

A short Kurdish introduction to Dart: what the language is, who made it and what you can build with it.

ناساندنێکی کورتی کوردی بۆ : ئەم زمانە چییە، کێ دروستی کردووە و چی پێ دروست دەکرێت.

Kurdish, whole video (4:44), June 2022.

بە کوردی، هەموو ڤیدیۆکە ⁦(4:44)⁩، حوزەیرانی ⁦2022⁩.

Lesson complete!وانەکە تەواو بوو!

Well done. Review the key terms, then go on to the next lesson.دەستخۆش. سەیرێکی زاراوە سەرەکییەکان بکەرەوە، پاشان بڕۆ بۆ وانەی داهاتوو.

Key termsزاراوە سەرەکییەکان

Next lessonوانەی داهاتوو

Dart Basics: Variables, Types and Control Flowبنەماکانی Dart: گۆڕاوەکان، جۆرەکان و ڕێڕەوی کۆنترۆڵ

References and further readingسەرچاوەکان و خوێندنەوەی زیاتر

This lecture is a first edition. The Kurdish text and terminology are waiting for review by Kurdish IT teachers.ئەم وانەیە چاپی یەکەمە. دەقە کوردییەکە و زاراوەکانی چاوەڕێی پێداچوونەوەی مامۆستایانی کوردی بواری IT ن.