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؛ بۆچی بەکار دەهێنێت؛ و جیاوازیی و .
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
dartcommand. - 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 بە زمانێکی بۆ لای ڕێکخراو وەسفی دەکات: بۆ ئەو بەشەی دروست کراوە کە خەڵک دەیبینن و دەستی لێ دەدەن — — بەڵام ئامرازی و کار پێدەکات.
void main() {
print('Hello from Dart!');
}Hello from Dart!
Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 1
Every Dart program starts in
main().هەموو لە
main()ـەوە دەست پێدەکات.- Lineدێڕی 2
printwrites 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.
ئەگەر پێشتر ، یان جۆرەکانت نەناسیوە، سەرەتا زمانەکانی بەرنامەسازی و چۆن کۆد دەبێتە بەرنامەیەکی کارپێکراو بخوێنەرەوە: ئەم وانەیە نیشان دەدات ئەو بیرۆکە گشتییانە چۆن جێبەجێ دەکات.
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دا چی ڕاستە:
| 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٣. شێوەی C | Yes: 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.بەڵێ — ئەمە ئامانجی سەرەکیی (بۆ لای ڕێکخراو)، لە بچووکەوە تا زۆر گەورە. |
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ـی کۆن دەگونجێت:
| 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 (سەیری کۆمپایلکردن بکە). |
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 { } 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');
}
}Total is 6
Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 4-6
The
forloop's three parts are in parentheses; its body is in braces.سێ بەشەکەی
forلە ناو کەوانەدان؛ ناوەڕۆکەکەی لە ناو کەوانەی لوولیدایە.- Lineدێڕی 7
The condition of
ifmust be in parentheses.ifدەبێت لە ناو کەوانەدا بێت.
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 بنووسیت و ڕێگە بدەیت لە یەکەم بیدۆزێتەوە. ڕێگەی دووەم پێی دەوترێت . بە هەر ڕێگەیەک بێت، جۆرێکی جێگیر وەردەگرێت.
void main() {
int age = 25; // explicit type
var name = 'Aram'; // type inferred as String
print('$age ${name.runtimeType}');
}25 String
Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 2
intis written by you.intخۆت دەینووسیت.- Lineدێڕی 3
var: Dart sees'Aram'and decides thatnameis aString.var:'Aram'دەبینێت و بڕیار دەدات کەname(String).- Lineدێڕی 4
runtimeTypeasks 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ـە، ڕێگە نادات ژمارەیەکی تێدا دابنرێت. چاوەڕێ ناکات تا کار دەکات — هەڵەکە پێش کارکردن دەدۆزرێتەوە، لەلایەن دەستکاریکەر و :
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);
}type_error.dart:3:10: Error: A value of type 'int' can't be assigned to a variable of type 'String'.
name = 5; // a number is not a String
^Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 3
The compiler stops here. The program does not start at all.
لێرەدا دەوەستێت. هەر دەست پێناکات.


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
}Aram 5 Unhandled exception: NoSuchMethodError: Class 'int' has no instance getter 'length'. Receiver: 5 Tried calling: length #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:38:5) #1 main (dynamic.dart:6:13)
Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 4
Allowed: a
dynamicvariable 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 هەمان هەڵە پێش کارکردن گیرا. ئەمە هەموو مەبەستی جۆرە جێگیرەکانە. دەربارەی ئەم دوو شێوازە لە زمانەکانی بەرنامەسازی زیاتر بخوێنەرەوە و ڕێگەی لە گۆڕاوەکان و جۆرەکانی دراوە ببینە.
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 فێر دەبیت.
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
dart2jscompiler) or to WebAssembly, so it runs in every modern browser.
- (JIT) — لە کاتی گەشەپێداندا. کۆد لە کاتی کارکردندا وەردەگێڕێت، تەنها ئەو بەشانەی بە ڕاستی بەکار دێن. کاتێک کۆد دەگۆڕیت، تەنها بەشە گۆڕاوەکان دووبارە وەردەگێڕێت — ئەمە وا دەکات و بێ بیلدکردنەوەی تەواو بکرێن.
- (AOT) — بۆ . پێش ئەوەی جێگیر بکرێت، هەموو وەردەگێڕدرێت بۆ بۆ پرۆسێسەری مۆبایلەکە یان کۆمپیوتەرەکە (ARM یان x64). خێرا دەست پێدەکات و نەرم کار دەکات، چونکە هیچ شتێک نەماوە لەسەر مۆبایلی وەربگێڕدرێت.
- بۆ وێب. بۆ ، وەردەگێڕدرێت بۆ باشکراو (
dart2js) یان بۆ WebAssembly، بۆیە لە هەموو نوێدا کار دەکات.
In short: AOT gives speed in production; JIT gives flexibility and quick updates while you develop.
بە کورتی: AOT خێرایی لە بەرهەمی کۆتاییدا دەدات؛ JIT نەرمی و نوێکردنەوەی خێرا لە کاتی گەشەپێداندا دەدات.
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 — بۆ هەموو زمانێک لە چۆن کۆد دەبێتە بەرنامەیەکی کارپێکراو ڕوون کراونەتەوە.
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ـن لە یەکەم شاشەوە:
$ 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 resulthellois 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.
Why Dart?بۆچی Dart؟
The course gives six reasons to use Dart. Here they are, each explained and brought up to date:
وانەکە شەش هۆکار بۆ بەکارهێنانی دەدات. ئەمانەن، هەریەکەیان ڕوون کراوەتەوە و نوێ کراوەتەوە:
- 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.
- Open source and standardised. It is free for everyone under the BSD licence, and Ecma approved its specification as ECMA-408 in 2014.
- Object-oriented. It has classes, inheritance, interfaces and mixins. (The notes add “optional type features”; today types are static and inferred — see Types.)
- 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.
- Compiles to JavaScript. The
dart2jscompiler turns Dart into JavaScript that runs in all modern browsers; WebAssembly is now possible too. - 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.
- سەربەخۆ لە . لەسەر Windows، macOS و Linux کار دەکات و هەمان کۆدی دەتوانرێت بۆ ئەندرۆید، iOS، وێب و کۆمپیوتەر وەربگێڕدرێت.
- و ستانداردکراو. بە مۆڵەتی BSD بۆ هەمووان بێبەرانبەرە و Ecma لە 2014دا وەسفەکەی وەک ECMA-408 پەسەند کرد.
- . ، ، و هەیە. (تێبینییەکان «تایبەتمەندیی جۆری ئارەزوومەندانە» زیاد دەکەن؛ ئەمڕۆ جۆرەکان جێگیرن و دەدۆزرێنەوە — سەیری جۆرەکان بکە.)
- باش بۆ . تێبینییەکان دەڵێن «بەهۆی جێگیرییەکەیەوە». هۆکارە ڕوونەکان ئەمانەن: AOT (دەستپێکردنی خێرا، نەرم بەبێ وەستان) و کۆکەرەوەی خۆکاری کە بۆ ئەو هەموو کورتخایەنە دروست کراوە کە ڕووکارێک دروستیان دەکات.
- بۆ وەردەگێڕدرێت.
dart2jsدەگۆڕێت بۆ کە لە هەموو نوێدا کار دەکات؛ WebAssemblyـش ئێستا دەکرێت. - کە بە تەنها کار دەکات. لە پەنجەرەی کار پێدەکات (
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 چییە؟ ڕوون کراوەتەوە.
Flutter and Dart are not the sameFlutter و Dart یەک شت نین
| Aspectلایەن | Flutter | Dart |
|---|---|---|
| Purposeئامانج | A UI framework (toolkit) for building apps for mobile, web and desktop from one codebase. ڕووکار بۆ دروستکردنی بۆ مۆبایل، وێب و کۆمپیوتەر لە یەک . | A general-purpose programming language. گشتی. |
| Syntax | You 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++ دەچێت. |
| Architecture | Widget-based: “everything is a widget” — text, padding, rows and whole screens.لەسەر بنەمای : «هەموو شتێک » — دەق، بۆشایی، ڕیز و شاشەی تەواو. | Supports several programming styles, including object-oriented and functional.پشتگیریی چەند شێوازێکی دەکات، لەوانە تەنخواز و کرداری. |
| Platforms | Android, iOS, web, Windows, macOS and Linux.ئەندرۆید، iOS، وێب، Windows، macOS و Linux. | Apps (through Flutter), web pages, servers and command-line tools. (لە ڕێگەی )، پەڕەی وێب، و ئامرازی . |
Flutter and Dart are not the sameFlutter و Dart یەک شت نین
An analogy: a language and a book of 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++ نووسراوە و هەموو خۆی دەکێشێت.
Common mistakesهەڵە باوەکان
| 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ڕاهێنانەکان
What happens when you run this program with dart run? Explain in one sentence.
کاتێک ئەم بە dart run کار پێدەکەیت چی ڕوو دەدات؟ بە یەک ڕستە ڕوونی بکەرەوە.
void main() {
var x = 3;
x = 'three';
print(x);
}Show answerوەڵامەکە پیشان بدە
void main() {
var x = 3; // x is an int from now on
x = 'three';
print(x);
}predict.dart:3:7: Error: A value of type 'String' can't be assigned to a variable of type 'int'.
x = 'three';
^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 .
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 — ڕەسەنی جێبەجێکراو.
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
varDart 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.
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ـەکەمان) و ئەو بەشانەی لە خۆ دەگرێت کە بۆ کارکردن پێویستن (بەڕێوەبردنی و )، بۆیە لەسەر کۆمپیوتەرێک کار دەکات کە لەسەر جێگیر نەکراوە.
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;
dynamicis only an opt-out. - JIT while you develop (hot reload), AOT machine code for release, JavaScript or WebAssembly for the web.
- The
dartcommand 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). - ڕووکارە؛ زمانەکەی ژێرەوەیە.
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.ڤیدیۆیەک کە بینەران زۆریان پێ خۆش بووە و لە کۆمێنتەکانیاندا ستایشیان کردووە، بۆ ئەم وانەیە هەڵبژێردراوە.
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زاراوە سەرەکییەکان
Dart Basics: Variables, Types and Control Flowبنەماکانی Dart: گۆڕاوەکان، جۆرەکان و ڕێڕەوی کۆنترۆڵ
Related lecturesوانە پەیوەندیدارەکان
- Programming Languagesزمانەکانی بەرنامەسازی
- How Code Becomes a Running Program: Compilers and Interpretersچۆن کۆد دەبێت بە بەرنامەیەک کە کار دەکات: کۆمپایلەرەکان و ئینتەرپرێتەرەکان
- Dart Basics: Variables, Types and Control Flowبنەماکانی Dart: گۆڕاوەکان، جۆرەکان و ڕێڕەوی کۆنترۆڵ
- What Is Flutter?Flutter چییە؟
- How Flutter Is Built: Framework, Engine, EmbedderFlutter چۆن دروست کراوە: فرەیموۆرک، بزوێنەر، Embedder
References and further readingسەرچاوەکان و خوێندنەوەی زیاتر
This lecture is a first edition. The Kurdish text and terminology are waiting for review by Kurdish IT teachers.ئەم وانەیە چاپی یەکەمە. دەقە کوردییەکە و زاراوەکانی چاوەڕێی پێداچوونەوەی مامۆستایانی کوردی بواری IT ن.