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

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

Dart's syntax from main() to loops: comments, var/final/const, int, double, String and bool, string interpolation, sound null safety with ?, !, ??, ??= and late, operators, the course's even/odd program, if/else, switch with Dart 3 patterns, and for, while and do-while loops.

لە ⁦main()⁩ـەوە تا : ، ⁦var/final/const⁩، int، double، String و bool، ، تەواو بە ?، !، ??، ??= و late، ، جووت/تاکی وانەکە، ⁦if/else⁩، switch لەگەڵ patternـەکانی 3 و for، while و ⁦do-while⁩.

21 min read20 خولەک خوێندنەوە · 21 stepsهەنگاو

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

  • Write a Dart program with main(), statements and comments.
  • Declare variables with var, a type, final or const, and choose the right one.
  • Use int, double, String and bool, string interpolation and type conversion.
  • Handle nullable values safely with ?, ??, ?., ??=, and know the risks of ! and late.
  • Control the flow with if/else, switch (and switch expressions), loops, break and continue.
  • بە main()، و بنووسیت.
  • بە var، جۆرێک، final یان const ڕابگەیەنیت و گونجاوەکەیان هەڵبژێریت.
  • int، double، String و bool، و بەکاربهێنیت.
  • ئەو دەشێت null بن بە ?، ??، ?.، ??= بە سەلامەتی بەکاربهێنیت و مەترسییەکانی ! و late بزانیت.
  • ڕێڕەوی بە ⁦if/else⁩، switch (و ⁦switch expression⁩)، ، break و continue کۆنترۆڵ بکەیت.

main, print and commentsmain، print و لێدوانەکان

A Dart program starts in the function main(). Each instruction inside it is a that ends with a semicolon, and print() writes a line of . Text that the computer should ignore is a : // to the end of the line, /* … */ for several lines, and /// for documentation that tools show as help. The ideas are the same in every language (see Your First Program for Python); here is the Dart way. You can run every example of this lesson with dart run file.dart, or paste it into DartPad.

لە main()ـەوە دەست پێدەکات. هەر فەرمانێک لە ناویدا کە بە فاریزەخاڵ کۆتایی دێت و print() دێڕێک دەنووسێت. ئەو دەقەی کۆمپیوتەر دەبێت پشتگوێی بخات : // تا کۆتایی دێڕەکە، /* … */ بۆ چەند دێڕێک و /// بۆ ڕوونکردنەوە کە ئامرازەکان وەک یارمەتی نیشانی دەدەن. بیرۆکەکان لە هەموو زمانێکدا وەک یەکن (بۆ سەیری یەکەم بەرنامەکەت بکە)؛ ئەمە ڕێگەی . دەتوانیت هەموو نموونەیەکی ئەم وانەیە بە dart run file.dart کار پێبکەیت، یان لە DartPadـدا دایبنێیت.

Comments, main and printلێدوانەکان، main و printfirst.dartDARTType in a terminalلە تێرمیناڵدا بینووسە
// A single-line comment: Dart ignores it.

/* A comment that can
   cover several lines. */

/// A documentation comment. Tools show it as help text.
void main() {
  print('Welcome to CêIT!'); // every statement ends with ;
  print(2 + 3);
}
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 1

A single-line comment.

یەک دێڕی.

Lineدێڕی 3-4

A comment over several lines.

بۆ چەند دێڕێک.

Lineدێڕی 6

A documentation comment, shown by the editor as help.

ڕوونکردنەوە، دەستکاریکەرەکە وەک یارمەتی نیشانی دەدات.

Lineدێڕی 8

A statement ends with ;. A comment can follow it on the same line.

بە ; کۆتایی دێت. دەتوانێت لە هەمان دێڕدا بە دوایدا بێت.

Lineدێڕی 9

print can print any value; 2 + 3 is worked out first.

print دەتوانێت هەر چاپ بکات؛ سەرەتا 2 + 3 حیساب دەکرێت.

Quick checkپشکنینی خێراWhich line is a comment in Dart?کام دێڕ لە ؟

Variablesگۆڕاوەکان

A is a named box for a value. In Dart you create one with var (Dart infers the type) or with a type name such as int, double, String or bool. Either way the box has a fixed type: it can get a new value later, but only of the same type. Names use lowerCamelCase: studentCount, isOpen. The general idea is in Variables and Data Types.

سندووقێکی ناونراوە بۆ . لە بە var دروستی دەکەیت ( جۆرەکە دەدۆزێتەوە) یان بە ناوی جۆرێکی وەک int، double، String یان bool. بە هەر ڕێگەیەک بێت سندووقەکە جۆرێکی جێگیری هەیە: دەتوانێت دواتر نوێ وەربگرێت، بەڵام تەنها لە هەمان جۆر. ناوەکان بە lowerCamelCase دەنووسرێن: studentCount، isOpen. بیرۆکە گشتییەکە لە گۆڕاوەکان و جۆرەکانی دراوەدایە.

Creating and changing variablesدروستکردن و گۆڕینی گۆڕاوەکانvariables.dartDARTType in a terminalلە تێرمیناڵدا بینووسە
void main() {
  var city = 'Erbil'; // Dart infers String
  int students = 30; // you write the type yourself
  double price = 2.5;
  bool isOpen = true;
  print('$city $students $price $isOpen');

  city = 'Duhok'; // a var can get a new value of the same type
  students = students + 1;
  print('$city $students');
}
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 2

var: the type String comes from the value.

var: جۆری String لە دێت.

Lineدێڕی 3-5

The type is written first, then the name.

سەرەتا جۆرەکە دەنووسرێت، پاشان ناوەکە.

Lineدێڕی 6

$city puts a variable's value inside a string.

$city دەخاتە ناو .

Lineدێڕی 8-9

New values of the same types are fine.

نوێ لە هەمان جۆر دروستن.

Four labelled boxes: int age holds 19; String city holds 'Erbil', with the note that city = 'Duhok' is fine later because the type is the same; bool isOpen holds true; int? score is drawn dashed and holds null, with the note that only a type with ? may be empty. Under them, a locked final box name holds 'Shilan' (set once, while running) and a locked const box daysInWeek holds 7 (known before running).چوار سندووقی ناونراو: int age 19 هەڵدەگرێت؛ String city 'Erbil' هەڵدەگرێت، لەگەڵ تێبینی ئەوەی city = 'Duhok' دواتر دروستە چونکە جۆرەکە هەمانە؛ bool isOpen true هەڵدەگرێت؛ int? score بە هێڵی پچڕپچڕ کێشراوە و null هەڵدەگرێت، لەگەڵ تێبینی ئەوەی تەنها جۆرێک کە ?ـی هەیە دەتوانێت بەتاڵ بێت. لە ژێریاندا سندووقێکی قوفڵدراوی final بە ناوی name کە 'Shilan' هەڵدەگرێت (یەک جار، لە کاتی کارکردندا) و سندووقێکی قوفڵدراوی const بە ناوی daysInWeek کە 7 هەڵدەگرێت (پێش کارکردن زانراوە).
Each variable is a box with a name and a type. Only a type with ? may be empty (null).هەر سندووقێکە بە ناو و جۆرێکەوە. تەنها جۆرێک کە ?ـی هەیە دەتوانێت بەتاڵ () بێت.CêIT
Quick checkپشکنینی خێراvar city = 'Erbil'; Which line is allowed afterwards?var city = 'Erbil'; دواتر کام دێڕ ڕێگەپێدراوە؟

Variablesگۆڕاوەکان

final and constfinal و const

Some values should never change. Dart has two keywords for them. final means set once: the value can be calculated while the program runs (like today's date), but after that it cannot be replaced. const means known before the program runs: a the compiler can work out by itself, such as 7 or 3.14159. Every const is also final. Use final or const whenever a value does not need to change — Flutter code uses const a lot, because constant widgets are built only once.

هەندێک نابێت هەرگیز بگۆڕێن. بۆ ئەمانە دوو دەدات. final واتە یەک جار دادەنرێت: دەتوانێت لە کاتی کارکردنی حیساب بکرێت (وەک بەرواری ئەمڕۆ)، بەڵام دوای ئەوە ناگۆڕدرێت. const واتە پێش کارکردنی زانراوە: کە خۆی دەتوانێت بیدۆزێتەوە، وەک 7 یان 3.14159. هەموو constـێک finalـیشە. هەر کاتێک پێویست نەبوو بگۆڕێت final یان const بەکاربهێنە — کۆدی زۆر const بەکار دەهێنێت، چونکە تەنها یەک جار دروست دەکرێن.

final and constfinal و constfinal_const.dartDARTType in a terminalلە تێرمیناڵدا بینووسە
void main() {
  final name = 'Shilan'; // set once
  final today = DateTime.now(); // known only when the program runs
  const daysInWeek = 7; // known before the program runs
  const pi = 3.14159;

  print('$name: a week has $daysInWeek days. Pi is about $pi.');
  print(today.year >= 2026);
}
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 2

final: set once.

final: یەک جار دادەنرێت.

Lineدێڕی 3

DateTime.now() is known only while running, so it can be final but not const.

DateTime.now() تەنها لە کاتی کارکردندا دەزانرێت، بۆیە دەتوانێت final بێت بەڵام const نا.

Lineدێڕی 4-5

const: known before the program runs.

const: پێش کارکردنی زانراوە.

Three mistakes the compiler stopsسێ هەڵە کە کۆمپایلەرەکە ڕایاندەگرێتfinal_error.dartDARTType in a terminalلە تێرمیناڵدا بینووسە
void main() {
  final name = 'Shilan';
  name = 'Hana';

  const daysInWeek = 7;
  daysInWeek = 8;

  const today = DateTime.now();
  print('$name $daysInWeek $today');
}
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3

A final variable cannot get a second value.

final ناتوانێت دووەم وەربگرێت.

Lineدێڕی 6

Neither can a const.

constـیش ناتوانێت.

Lineدێڕی 8

DateTime.now() is not known before running, so it cannot be const.

DateTime.now() پێش کارکردن نازانرێت، بۆیە ناتوانێت const بێت.

var, final and constvar، final و const
KeywordCan change?دەگۆڕێت؟Value known… کەی دەزانرێتExampleنموونە
varYes (same type)بەڵێ (هەمان جۆر)any timeهەر کاتێکvar score = 0;
finalNo, set onceنا، یەک جارwhile the program runsلە کاتی کارکردنی final today = DateTime.now();
constNoناbefore the program runsپێش کارکردنی const daysInWeek = 7;
Quick checkپشکنینی خێراWhich keyword fits ___ startTime = DateTime.now(); if startTime must never change?ئەگەر startTime نابێت هەرگیز بگۆڕێت، کام لە ___ startTime = DateTime.now();ـدا دەگونجێت؟

The Complete Dart & Flutter Developer Course | Full Tutorial For Beginners to AdvancedRivaan Ranawat · Englishئینگلیزی · 1.9M viewsبینین · 36K likesلایک · Partبەشی 49:02–1:00:24 (ofلە 20:47:34)

Live DartPad coding: var, final and const and their differences, then nullable types with ?, ?. and ?? in Dart 3.

کۆدنووسینی ڕاستەوخۆ لە DartPadـدا: var، final و const و جیاوازییان، پاشان ئەو جۆرانەی دەتوانن بن، بە ?، ?. و ?? ( ⁦3⁩).

Plays 49:02-1:00:24: var, final and const in DartPad, including why const cannot hold DateTime.now().

لە ⁦49:02⁩ تا ⁦1:00:24⁩ پەخش دەبێت: var، final و const لە DartPadـدا، لەگەڵ ئەوەی بۆچی const ناتوانێت DateTime.now() هەڵبگرێت.

Numbers: int and doubleژمارەکان: int و double

Dart has two number types. int holds (whole numbers such as 30 or -4); double holds numbers with a decimal point (, such as 2.5). Both belong to the general type num. The arithmetic operators are the usual ones, with one surprise: / always gives a double, even for 6 / 3 (the result is 2.0). If you want a whole-number result, use ~/. The remainder operator % () tells you what is left over.

دوو جۆر ژمارەی هەیە. int هەڵدەگرێت (ژمارەی بێ کەرتی وەک 30 یان -4)؛ double ژمارەی خاوەن خاڵی دەیی هەڵدەگرێت (، وەک 2.5). هەردووکیان سەر بە جۆری گشتیی numـن. هەمان ئەوانەی ئاسایین، لەگەڵ یەک شتی سەیر: / هەمیشە double دەدات، تەنانەت بۆ 6 / 3 (ئەنجامەکە 2.0ـە). ئەگەر ئەنجامێکی بێ کەرتت دەوێت، ~/ بەکاربهێنە. %، ، پێت دەڵێت چی دەمێنێتەوە.

The arithmetic operatorsکارپێکەرە ژمێرەییەکانnumbers.dartDARTType in a terminalلە تێرمیناڵدا بینووسە
void main() {
  int a = 7;
  int b = 2;
  print(a + b); // add
  print(a - b); // subtract
  print(a * b); // multiply
  print(a / b); // divide: always a double
  print(a ~/ b); // divide, keep only the whole number
  print(a % b); // remainder
}
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 7

7 / 2 is 3.5: a double.

7 / 2 دەکاتە 3.5: double.

Lineدێڕی 8

~/ divides and keeps only the whole part: 3.

~/ دابەش دەکات و تەنها بەشە تەواوەکە دەهێڵێتەوە: 3.

Lineدێڕی 9

7 % 2 is 1, because 7=3×2+17 = 3 \times 2 + 1.

7 % 2 دەکاتە 1، چونکە 7=3×2+17 = 3 \times 2 + 1.

Checked: negative division in Dartپشکنراو: دابەشکردنی سالب لە Dartـداnegative.dartDARTType in a terminalلە تێرمیناڵدا بینووسە
void main() {
  print(-7 ~/ 2); // cuts toward zero
  print(-7 % 2); // never negative when the divisor is positive
  print((-7).remainder(2)); // keeps the sign of -7
}

Python's operators are taught in Operators and Expressions; the ideas are the same.

لە کارپێکەرەکان و دەربڕینەکان فێر دەکرێن؛ بیرۆکەکان وەک یەکن.

Quick checkپشکنینی خێراWhat does print(10 / 4); show in Dart?print(10 / 4); لە چی نیشان دەدات؟

Numbers: int and doubleژمارەکان: int و double

Converting between typesگۆڕینی جۆر

Text that looks like a number is still text: '19' is a String. turns it into a number with int.parse() or double.parse(); toString() turns a number into text; toStringAsFixed(2) rounds to two decimal places for display. When the text might not be a number (for example something a user typed), use int.tryParse(): it returns null instead of crashing. See also Type conversion in Python.

دەقێک کە لە ژمارە دەچێت هێشتا دەقە: '19' Stringـە. بە int.parse() یان double.parse() دەیکات بە ژمارە؛ toString() ژمارە دەکات بە دەق؛ toStringAsFixed(2) بۆ پیشاندان تا دوو ژمارەی دوای خاڵ نزیکی دەکاتەوە. کاتێک لەوانەیە دەقەکە ژمارە نەبێت (بۆ نموونە شتێک کە نووسیویەتی)، int.tryParse() بەکاربهێنە: لە جیاتی ڕووخان null دەگەڕێنێتەوە. هەروەها سەیری گۆڕینی جۆر لە Pythonـدا بکە.

parse, toString and tryParseparse، toString و tryParseconversion.dartDARTType in a terminalلە تێرمیناڵدا بینووسە
void main() {
  var age = int.parse('19'); // text -> int
  var height = double.parse('1.75'); // text -> double
  String text = 42.toString(); // number -> text
  print(age + 1);
  print(height * 2);
  print(text.length); // "42" has 2 characters
  print(3.14159.toStringAsFixed(2)); // 2 decimal places
  print(int.tryParse('abc')); // not a number: null instead of a crash
}
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 2

int.parse('19') gives the int 19.

int.parse('19') ⁦19⁩ دەدات.

Lineدێڕی 4

42.toString() gives the text '42'.

42.toString() دەقی '42' دەدات.

Lineدێڕی 8

Rounded to 2 decimal places, as text.

تا دوو ژمارەی دوای خاڵ نزیک کراوەتەوە، وەک دەق.

Lineدێڕی 9

tryParse gives null for text that is not a number.

tryParse بۆ دەقێک کە ژمارە نییە null دەدات.

Quick checkپشکنینی خێراA user types abc where a number was expected. Which code does not crash? لە شوێنی ژمارەیەک abc دەنووسێت. کام کۆد ناڕووخێت؟

Learn The Dart Programming Language - Complete Free Course!John Elder · Englishئینگلیزی · 277K viewsبینین · 6.9K likesلایک · Partبەشی 51:45–56:10 (ofلە 1:21:11)

Clear Dart examples: list methods (add, insert, remove), maps of key-value pairs, and turning text into numbers with int.parse and double.parse.

نموونەی ڕوونی : (add، insert، remove)، Map بۆ و گۆڕینی بۆ ژمارە بە int.parse و double.parse.

Plays 51:45-56:10: int.parse, double.parse and toString to convert between text and numbers.

لە ⁦51:45⁩ تا ⁦56:10⁩ پەخش دەبێت: int.parse، double.parse و toString بۆ گۆڕین لە نێوان و ژمارەدا.

Stringsزنجیرەنووسەکان

A is text between quotes — single '…' or double "…"; both work the same. The most useful feature is : $name puts a variable's value into the text, and ${…} puts the result of any in it. You can also join strings with +, write several lines between triple quotes '''…''', and stop interpolation with a raw string r'…'. Kurdish text works like any other, because Dart strings are Unicode. Compare Python's f-strings in Input and Output.

دەقێکە لە نێوان — تاک '…' یان جووت "…"؛ هەردووکیان وەک یەک کار دەکەن. بەسوودترین تایبەتمەندی : $name دەخاتە ناو دەقەکەوە و ${…} ئەنجامی هەر دەخاتە ناوی. هەروەها دەتوانیت بە + پێکەوە بلکێنیت، لە نێوان سێ '''…'''ـدا چەند دێڕێک بنووسیت و بە خاو r'…' ڕابگریت. دەقی کوردی وەک هەر دەقێکی تر کار دەکات، چونکە Unicodeـن. بەراوردی بکە لەگەڵ ⁦f-string⁩ـەکانی لە نێوخستە و دەرخستە.

Working with stringsکارکردن لەگەڵ زنجیرەنووسەکانstrings.dartDARTType in a terminalلە تێرمیناڵدا بینووسە
void main() {
  var name = 'Dilan';
  var age = 20;
  print('Hello, $name!'); // $name puts the value inside
  print('Next year $name will be ${age + 1}.'); // ${...} for an expression
  print("It's easy with double quotes.");
  print('Tea' + ' and ' + 'bread'); // + joins strings
  var poem = '''
Line one
Line two''';
  print(poem);
  print(r'In a raw string, $name stays as it is.');
  print('سڵاو $name'); // Kurdish text works too
  print(name.toUpperCase());
  print(name.length);
}
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 4

$name → the value of name.

$name ← name.

Lineدێڕی 5

${age + 1} → the result of the expression.

${age + 1} ← ئەنجامی .

Lineدێڕی 6

Double quotes make an apostrophe easy.

جووت نووسینی ' ئاسان دەکات.

Lineدێڕی 8-10

Triple quotes keep the line breaks.

سێ دێڕە نوێکان دەپارێزێت.

Lineدێڕی 12

r'…': $name is printed as it is.

r'…': $name وەک خۆی چاپ دەکرێت.

Lineدێڕی 14-15

Strings have methods and properties, such as toUpperCase() and length.

و تایبەتمەندییان هەیە، وەک toUpperCase() و length.

Quick checkپشکنینی خێراvar n = 3; Which line prints n squared is 9?var n = 3; کام دێڕ n squared is 9 چاپ دەکات؟

Stringsزنجیرەنووسەکان

Booleansبوولیانەکان

A bool () has only two values, true and false. Comparisons give booleans. Dart is strict here: a condition must be a real bool. Some languages treat 0, an empty text or null as false (“truthy” and “falsy” values — see Python's truthiness); Dart does not, so you write the check yourself: count == 0, name.isEmpty, value == null.

bool () تەنها دوو هەیە، true و false. بەراوردکردنەکان دەدەن. لێرەدا توندە: دەبێت boolـێکی ڕاستەقینە بێت. هەندێک زمان 0، دەقێکی بەتاڵ یان null وەک false دادەنێن ( «truthy» و «falsy» — سەیری truthinessـی Python بکە)؛ وا ناکات، بۆیە پشکنینەکە خۆت دەنووسیت: count == 0، name.isEmpty، value == null.

Booleans from comparisonsبوولیانەکان لە بەراوردکردنەوەbool.dartDARTType in a terminalلە تێرمیناڵدا بینووسە
void main() {
  var count = 0;
  var noMessages = count == 0; // a comparison gives a bool
  print(noMessages);

  var name = '';
  if (name.isEmpty) {
    print('Please enter your name.');
  }
}
An int is not a conditionint مەرج نییەbool_error.dartDARTType in a terminalلە تێرمیناڵدا بینووسە
void main() {
  var count = 0;
  if (count) {
    print('You have messages.');
  }
}
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3

Dart refuses an int where a bool is needed. Write if (count > 0).

int لە شوێنێک کە boolـی پێویستە ڕەت دەکاتەوە. بنووسە if (count > 0).

Quick checkپشکنینی خێراvar name = ''; Which if is correct Dart?var name = ''; کام if دروستە؟

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

null means “no value”. In many languages any variable can secretly be null, and the program crashes the moment you use it — one of the most common bugs in apps. Dart's sound stops this before the program runs: a normal type (int, String) can never hold null. If a value may be missing, add a question mark to its type: int?, String?. Such a nullable variable starts as null, and Dart will not let you use it as if it were sure to have a value.

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

Two null mistakes, caught before runningدوو هەڵەی بێنرخ، پێش کارکردن گیرانnull_error.dartDARTType in a terminalلە تێرمیناڵدا بینووسە
void main() {
  int age = null;
  String? nickname;
  print(nickname.length);
  print(age);
}
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 2

int cannot hold null.

int ناتوانێت null هەڵبگرێت.

Lineدێڕی 3

String? may hold null; here it starts as null.

String? دەتوانێت null هەڵبگرێت؛ لێرەدا بە null دەست پێدەکات.

Lineدێڕی 4

Using .length on a String? is refused: it might be null. The message even suggests ?..

بەکارهێنانی .length لەسەر String? ڕەت دەکرێتەوە: لەوانەیە null بێت. پەیامەکە تەنانەت ?. پێشنیار دەکات.

Four frames. 1: a box String? nickname is empty (null). 2: the code print(nickname.length) gets a red mark and a stop sign: the compiler refuses it, so the app never starts with this bug. 3: in a language without null safety the same line passes the compiler, and the app crashes later on a user's phone. 4: the Dart fix print(nickname?.length ?? 0) runs and prints 0.
Four frames. 1: a box String? nickname is empty (null). 2: the code print(nickname.length) gets a red mark and a stop sign: the compiler refuses it, so the app never starts with this bug. 3: in a language without null safety the same line passes the compiler, and the app crashes later on a user's phone. 4: the Dart fix print(nickname?.length ?? 0) runs and prints 0.
Null safety stops a null before it can crash the app. null ڕادەگرێت پێش ئەوەی بڕووخێنێت.CêIT
Quick checkپشکنینی خێراWhich declaration does not compile?کام ڕاگەیاندن کۆمپایل ناکرێت؟

The Complete Dart & Flutter Developer Course | Full Tutorial For Beginners to AdvancedRivaan Ranawat · Englishئینگلیزی · 1.9M viewsبینین · 36K likesلایک · Partبەشی 1:00:24–1:12:00 (ofلە 20:47:34)

Live DartPad coding: var, final and const and their differences, then nullable types with ?, ?. and ?? in Dart 3.

کۆدنووسینی ڕاستەوخۆ لە DartPadـدا: var، final و const و جیاوازییان، پاشان ئەو جۆرانەی دەتوانن بن، بە ?، ?. و ?? ( ⁦3⁩).

Plays 1:00:24-1:12:00: nullable types (String?), the error when null goes into int, ?. and ??.

لە ⁦1:00:24⁩ تا ⁦1:12:00⁩ پەخش دەبێت: ئەو جۆرانەی دەتوانن بن (String?)، ئەو دروست دەبێت کاتێک دەخرێتە ناو int، پاشان ?. و ??.

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

Working with nullable valuesکارکردن لەگەڵ ئەو نرخانەی دەشێت null بن

Dart gives you short operators for nullable values:

چەند کورتت بۆ ئەو دەداتێ کە دەشێت null بن:

The null-aware operatorsئەو ئاگایان لە null هەیە
OperatorMeaningواتاExampleنموونە
??If the left side is null, use the right sideئەگەر لای چەپ null بوو، لای ڕاست بەکاربهێنەnickname ?? 'guest'
??=Assign only if the variable is nullتەنها ئەگەر null بوو دابنێnickname ??= 'Kawa';
?.Use a member only if not null; otherwise the result is nullتەنها ئەگەر null نەبوو بەکاری بهێنە؛ ئەگینا ئەنجامەکە nullـەnickname?.length
!“Trust me, it is not null” — crashes if it is«متمانەم پێ بکە، null نییە» — ئەگەر بوو دەڕووخێتnickname!.length

You can also simply check for null: inside if (score != null) { … } Dart knows that score has a value and lets you use it as an int. This is called type promotion.

هەروەها دەتوانیت بە سادەیی null بپشکنیت: لە ناو if (score != null) { … }ـدا دەزانێت کە score هەیە و ڕێگەت دەدات وەک int بەکاری بهێنیت. ئەمە پێی دەوترێت بەرزکردنەوەی جۆر.

??, ?., ??= and a null check??، ?.، ??= و پشکنینی nullnull_ok.dartDARTType in a terminalلە تێرمیناڵدا بینووسە
void main() {
  String? nickname; // may be null; it starts as null
  print(nickname);
  print(nickname ?? 'no nickname'); // ?? gives a default
  print(nickname?.length); // ?. stops at null: no crash

  nickname ??= 'Kawa'; // give it a value only if it is null
  print(nickname.length); // Dart now knows it is not null

  int? score = int.tryParse('85');
  if (score != null) {
    print(score + 5); // inside the check, score is an int
  }
}
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 4

?? gives a default instead of null.

?? دەدات لە جیاتی null.

Lineدێڕی 5

?. stops at null and gives null.

?. لە nullـدا دەوەستێت و null دەدات.

Lineدێڕی 7-8

After ??=, Dart knows nickname is not null, so .length is allowed.

دوای ??=، دەزانێت nickname null نییە، بۆیە .length ڕێگەپێدراوە.

Lineدێڕی 10-13

int.tryParse returns int?. Inside the if, score is a normal int.

int.tryParse int? دەگەڕێنێتەوە. لە ناو ifـدا score intـێکی ئاساییە.

The ! operator can still crashکارپێکەرەکە ! هێشتا دەتوانێت بڕووخێنێتbang_crash.dartDARTType in a terminalلە تێرمیناڵدا بینووسە
void main() {
  String? city; // nobody gave it a value
  print('Before');
  print(city!.length); // "trust me, it is not null" - but it is
  print('After');
}
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 4

! switches the check off for this one use. The value is null, so the program stops here and After is never printed.

! پشکنینەکە بۆ ئەم یەک بەکارهێنانە دەکوژێنێتەوە. nullـە، بۆیە لێرەدا دەوەستێت و After هەرگیز چاپ ناکرێت.

Quick checkپشکنینی خێراString? city; What does print(city?.length ?? 0); print?String? city; print(city?.length ?? 0); چی چاپ دەکات؟

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

late variablesگۆڕاوەکانی late

Sometimes a variable cannot get its value where it is declared, but you know it will be set before anyone reads it. Mark it late. Dart then trusts you and checks only at runtime: reading a late variable before it has a value throws a LateInitializationError. In Flutter you will meet late for values that are prepared in initState() (see the lifecycle of a State object).

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

A late variable that is set in timeگۆڕاوێکی late کە لە کاتی خۆیدا دادەنرێتlate.dartDARTType in a terminalلە تێرمیناڵدا بینووسە
late String greeting; // a value comes later

void main() {
  greeting = 'Good morning';
  print(greeting);
}
…and one that is read too early…و یەکێک کە زوو دەخوێنرێتەوەlate_crash.dartDARTType in a terminalلە تێرمیناڵدا بینووسە
late String message;

void main() {
  print('Start');
  print(message); // read before it was set
}
Quick checkپشکنینی خێراWhen does Dart check a late variable? کەی late دەپشکنێت؟

More operatorsکارپێکەرەکانی زیاتر

Besides arithmetic, you will use these every day: ++ and -- add or take away 1; +=, -=, *= change a variable using its own value; (==, !=, >, <, >=, <=) give a bool; combine conditions — && (and), || (or), ! (not); the condition ? a : b chooses one of two values; and is tests a type. The ideas are explained for every language in Operators and Expressions and Logical Operators.

جگە لە ، ئەم هەموو ڕۆژێک بەکار دەهێنیت: ++ و -- 1 زیاد یان کەم دەکەن؛ +=، -=، *= بە خۆی دەگۆڕن؛ (==، !=، >، <، >=، <=) bool دەدەن؛ پێکەوە دەبەستن — && (و)، || (یان)، ! (نا)؛ condition ? a : b یەکێک لە دوو هەڵدەبژێرێت؛ و is جۆرێک دەپشکنێت. بیرۆکەکان بۆ هەموو زمانێک لە کارپێکەرەکان و دەربڕینەکان و کارپێکەرە لۆجیکییەکان ڕوون کراونەتەوە.

Everyday operatorsکارپێکەرەکان ڕۆژانەoperators.dartDARTType in a terminalلە تێرمیناڵدا بینووسە
void main() {
  var score = 10;
  score++; // score = score + 1
  score += 5; // score = score + 5
  score -= 2;
  print(score);

  print(score == 14);
  print(score != 14);
  print(score > 10 && score < 20); // and
  print(score < 0 || score > 100); // or
  print(!(score > 10)); // not

  var result = score >= 50 ? 'pass' : 'fail'; // condition ? a : b
  print(result);
  print(score is int); // type test
}
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3-5

10 → 11 → 16 → 14.

⁦10⁩ دەبێت بە ⁦11⁩، پاشان ⁦16⁩، پاشان ⁦14⁩.

Lineدێڕی 8-9

== asks “equal?”, != asks “not equal?”.

== دەپرسێت «یەکسانە؟»، != دەپرسێت «یەکسان نییە؟».

Lineدێڕی 10-12

&& needs both sides true; || needs one; ! turns true into false.

&& پێویستی بە ڕاستبوونی هەردوو لایە؛ || پێویستی بە یەکیانە؛ ! true دەکات بە false.

Lineدێڕی 14

Ternary: score >= 50 is false, so the result is 'fail'.

: score >= 50 falseـە، بۆیە ئەنجامەکە 'fail'ـە.

Lineدێڕی 16

is checks the type.

is جۆرەکە دەپشکنێت.

Quick checkپشکنینی خێراvar x = 5; x += 3; x++; What is x now?var x = 5; x += 3; x++; ئێستا x چەندە؟

More operatorsکارپێکەرەکانی زیاتر

The course example: even or oddنموونەی وانەکە: جووت یان تاک

The course's first Dart program decides whether a number is even or odd. The idea: a number is even when dividing it by 2 leaves no remainder, so number % 2 == 0. The flowchart under the code draws the same decision; flowchart shapes are explained in Flowchart symbols.

یەکەم وانەکە بڕیار دەدات ژمارەیەک جووتە یان تاک. بیرۆکەکە: ژمارەیەک جووتە کاتێک دابەشکردنی بەسەر 2دا هیچ نامێنێت، کەواتە number % 2 == 0. ئەو لە ژێر کۆدەکەدایە هەمان بڕیار دەکێشێت؛ شێوەکانی لە هێماکانی هێڵکاریی ڕەوت ڕوون کراونەتەوە.

Even or odd (from the course)جووت یان تاک (لە وانەکەوە)even_odd.dartDARTType in a terminalلە تێرمیناڵدا بینووسە
void main() {
  var number = 12;
  if (number % 2 == 0) {
    print("Number is Even.");
  } else {
    print("Number is Odd.");
  }
}
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 2

The course called this variable num; we use number (see the note below).

وانەکە ناوی ئەم نابوو num؛ ئێمە number بەکار دەهێنین (سەیری تێبینییەکەی خوارەوە بکە).

Lineدێڕی 3

% gives the remainder; == compares it with 0.

% دەدات؛ == بەراوردی دەکات لەگەڵ 0.

Flowchart: Start, set number to 12, decision 'number % 2 == 0?'. The yes branch prints 'Number is Even.', the no branch prints 'Number is Odd.'; both lead to End.هێڵکاریی ڕەوت: دەستپێک، number بکە بە 12، بڕیاری 'number % 2 == 0؟'. لقی بەڵێ 'Number is Even.' چاپ دەکات، لقی نەخێر 'Number is Odd.' چاپ دەکات؛ هەردووکیان دەچنە کۆتایی.
The even/odd program as a flowchart. جووت/تاک وەک .CêIT
Quick checkپشکنینی خێراFor number = 15, what does the program print?بۆ number = 15، چی چاپ دەکات؟

if, else if and elseif، ⁦else if⁩ و else

Choosing and repeating are two of the three building blocks of every algorithm; this screen and the next ones show how Dart writes them. An runs a only when its is true. Add else if for more conditions and else for “everything else”. Dart checks them from the top and runs only the first block whose condition is true. The condition goes in parentheses and must be a bool; the blocks go in braces. (Python uses elif and a colon for the same thing — see Making Decisions.)

هەڵبژاردن و دووبارەکردنەوە دوو لە سێ بەردی بناغەی هەموو ؛ ئەم شاشەیە و شاشەکانی دواتر نیشان دەدەن چۆن دەیاننووسێت. تەنها کاتێک جێبەجێ دەکات کە ڕاست بێت. else if بۆ زیاتر و else بۆ «هەموو شتەکانی تر» زیاد بکە. لە سەرەوە دەیانپشکنێت و تەنها یەکەم جێبەجێ دەکات کە ڕاستە. لە ناو کەوانەدا دەنووسرێت و دەبێت bool بێت؛ لە ناو کەوانەی لوولیدان. ( بۆ هەمان کار elif و دوو خاڵ بەکار دەهێنێت — سەیری بڕیاردان بکە.)

Choosing a message from a markهەڵبژاردنی پەیامێک بەپێی نمرەif.dartDARTType in a terminalلە تێرمیناڵدا بینووسە
void main() {
  var mark = 72;
  if (mark >= 90) {
    print('Excellent');
  } else if (mark >= 70) {
    print('Very good');
  } else if (mark >= 50) {
    print('Pass');
  } else {
    print('Try again');
  }
}
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3

72 >= 90 is false…

⁦72 >= 90 false⁩ـە…

Lineدێڕی 5

…72 >= 70 is true, so this block runs and the rest are skipped.

…⁦72 >= 70 true⁩ـە، بۆیە ئەم کار دەکات و ئەوانی تر تێدەپەڕێنرێن.

Quick checkپشکنینی خێراWith mark = 95, how many print lines run in this program?بە mark = 95، چەند دێڕی print لەم کار دەکات؟

switchڕستەی switch

A compares one value with several cases. In Dart 3 a case does not fall through into the next one, so no break is needed; empty cases placed together share one body; and default (or _) catches everything else. Dart 3 also has a switch expression, which produces a value: each case is pattern => result, separated by commas.

یەک لەگەڵ چەند حاڵەتێک بەراورد دەکات. لە 3دا حاڵەتێک ناچێتە ناو حاڵەتی دواتر، بۆیە پێویستی بە break نییە؛ حاڵەتە بەتاڵەکان کە پێکەوە دانراون یەک ناوەڕۆک هاوبەش دەکەن؛ و default (یان _) هەموو شتەکانی تر دەگرێت. 3 ⁦switch expression⁩ـیشی هەیە کە دروست دەکات: هەر حاڵەتێک pattern => resultـە و بە فاریزە جیا دەکرێنەوە.

A switch statement and a switch expressionڕستەی switch و ⁦switch expression⁩switch.dartDARTType in a terminalلە تێرمیناڵدا بینووسە
void main() {
  var day = 'Friday';
  switch (day) {
    case 'Friday':
    case 'Saturday':
      print('Weekend');
    case 'Thursday':
      print('Almost the weekend');
    default:
      print('A working day');
  }

  var mark = 85;
  var grade = switch (mark) {
    >= 90 => 'A',
    >= 80 => 'B',
    >= 70 => 'C',
    >= 50 => 'D',
    _ => 'F',
  };
  print(grade);
}
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 4-6

Two cases share one body. No break is needed.

دوو حاڵەت یەک ناوەڕۆک هاوبەش دەکەن. پێویست بە break ناکات.

Lineدێڕی 9

default runs when no case matches.

default کاتێک هیچ حاڵەتێک نەگونجا کار دەکات.

Lineدێڕی 14-20

The switch expression gives a value to grade. >= 90 is a relational pattern; _ matches everything else. The first matching case wins.

⁦switch expression⁩ دەدات بە grade. >= 90 patternـێکی بەراوردکردنە؛ _ هەموو شتەکانی تر دەگرێت. یەکەم حاڵەتی گونجاو دەباتەوە.

Quick checkپشکنینی خێراIn a Dart 3 switch statement, what happens after a non-empty case finishes?لە ڕستەی switchـی 3دا، دوای تەواوبوونی حاڵەتێکی نابەتاڵ چی ڕوو دەدات؟

switchڕستەی switch

Dart 3 patterns, brieflypattern لە Dart 3دا، بە کورتی

The case part is a pattern: a shape the value is matched against. Beyond plain values, three kinds are useful from the start: a || b matches either value; relational patterns such as > 40 compare; and a guard when … adds an extra condition. Python 3.10 has a similar match statement (see it here).

بەشی case patternـێکە: شێوەیەک کە لەگەڵیدا بەراورد دەکرێت. جگە لە سادە، سێ جۆریان لە سەرەتاوە بەسوودن: a || b هەریەک لە دوو دەگرێت؛ patternـی بەراوردکردن وەک > 40 بەراورد دەکەن؛ و پاسەوانێک when … زیادە دادەنێت. ⁦3.10⁩ ڕستەی matchـی هاوشێوەی هەیە (لێرە ببینە).

Logical-or, relational patterns and a guard||، patternـی بەراوردکردن و پاسەوانswitch_patterns.dartDARTType in a terminalلە تێرمیناڵدا بینووسە
void main() {
  for (var month in [1, 4, 7, 11]) {
    var season = switch (month) {
      12 || 1 || 2 => 'winter',
      3 || 4 || 5 => 'spring',
      6 || 7 || 8 => 'summer',
      _ => 'autumn',
    };
    print('Month $month: $season');
  }

  var temperature = 41;
  switch (temperature) {
    case > 40 when temperature < 50:
      print('Very hot: stay inside at noon.');
    case > 25:
      print('Warm');
    default:
      print('Cool');
  }
}
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 4-7

12 || 1 || 2 matches any of the three months.

12 || 1 || 2 هەریەک لە سێ مانگەکە دەگرێت.

Lineدێڕی 14

case > 40 when temperature < 50: — the pattern must match and the guard must be true.

case > 40 when temperature < 50: — دەبێت patternـەکە بگونجێت و پاسەوانەکەش ڕاست بێت.

Quick checkپشکنینی خێراWhich switch-expression case matches the months 6, 7 and 8?کام حاڵەتی ⁦switch expression⁩ مانگەکانی 6، 7 و 8 دەگرێت؟

Loops: for, for-in, while, do-whileخولەکان: for، ⁦for-in⁩، while، ⁦do-while⁩

A repeats a block. Dart has four kinds. The classic has three parts — start, condition, step — and is best for counting. for-in walks through every item of a list. The repeats while a condition is true, checking it before each round. The checks after each round, so its body always runs at least once — Python has no such loop (see why). The ideas are taught step by step in The for Loop and The while Loop.

دووبارە دەکاتەوە. چوار جۆری هەیە. کلاسیک سێ بەشی هەیە — دەستپێک، ، هەنگاو — و بۆ ژماردن باشترینە. ⁦for-in⁩ بەسەر هەموو دەڕوات. تا ڕاست بێت دووبارە دەکاتەوە و پێش هەر دەیپشکنێت. دوای هەر دەپشکنێت، بۆیە ناوەڕۆکەکەی هەمیشە لانیکەم یەک جار کار دەکات — وای نییە (بۆچی). بیرۆکەکان هەنگاو بە هەنگاو لە خولی for و خولی while فێر دەکرێن.

The four loopsچوار خولەکەloops.dartDARTType in a terminalلە تێرمیناڵدا بینووسە
void main() {
  for (var i = 0; i < 5; i++) {
    print('i = $i');
  }

  var cities = ['Erbil', 'Duhok', 'Halabja'];
  for (final city in cities) {
    print(city);
  }

  var glasses = 3;
  while (glasses > 0) {
    print('Glasses of tea left: $glasses');
    glasses--;
  }

  var tries = 0;
  do {
    tries++;
    print('Try $tries');
  } while (tries < 2);
}
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 2

Start i = 0; repeat while i < 5; after each round i++.

دەستپێک i = 0؛ تا i < 5 دووبارە بکەرەوە؛ دوای هەر i++.

Lineدێڕی 7-9

for-in: city takes each item in turn. final because it is not changed inside.

⁦for-in⁩: city بە نۆبە هەر وەردەگرێت. finalـە چونکە لە ناوەوە ناگۆڕدرێت.

Lineدێڕی 12-15

while: checked before each round; glasses-- moves towards the end.

while: پێش هەر دەپشکنرێت؛ glasses-- بەرەو کۆتایی دەبات.

Lineدێڕی 18-21

do-while: the body runs first, then the condition is checked.

⁦do-while⁩: سەرەتا ناوەڕۆکەکە کار دەکات، پاشان دەپشکنرێت.

Quick checkپشکنینی خێراWhich loop always runs its body at least once?کام هەمیشە لانیکەم یەک جار ناوەڕۆکەکەی جێبەجێ دەکات؟

Loops: for, for-in, while, do-whileخولەکان: for، ⁦for-in⁩، while، ⁦do-while⁩

break and continuebreak و continue

Inside a loop, a skips the rest of this round and goes on with the next one; a leaves the loop completely. (The same in Python.)

لە ناو ، پاشماوەی ئەم تێدەپەڕێنێت و بەردەوام دەبێت لەگەڵ دواتر؛ بە تەواوی لە دەردەچێت. (هەمان شت لە Pythonـدا.)

Skip 3, stop at 63 تێبپەڕێنە، لە 6 بوەستەbreak_continue.dartDARTType in a terminalلە تێرمیناڵدا بینووسە
void main() {
  for (var n = 1; n <= 10; n++) {
    if (n == 3) continue; // skip 3
    if (n == 6) break; // stop at 6
    print(n);
  }
}
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3

continue: 3 is not printed, but the loop goes on.

continue: 3 چاپ ناکرێت، بەڵام بەردەوام دەبێت.

Lineدێڕی 4

break: at 6 the loop ends, so 6–10 are never printed.

break: لە 6دا کۆتایی دێت، بۆیە ⁦6–10⁩ هەرگیز چاپ ناکرێن.

Quick checkپشکنینی خێراWhat does break do inside a for loop?break لە ناو چی دەکات؟

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

Mistakes beginners make in Dartئەو هەڵانەی سەرەتاکاران لە دەیکەن
MistakeهەڵەFixچاککردنەوە
if (x = 5)= assigns, == compares: if (x == 5). Dart refuses the first, because an assignment is not a bool.= دادەنێت، == بەراورد دەکات: if (x == 5). یەکەمیان ڕەت دەکاتەوە، چونکە bool نییە.
A missing ;;ـی لەبیرکراوEvery statement ends with a semicolon; the compiler shows the line.هەموو بە فاریزەخاڵ کۆتایی دێت؛ دێڕەکە نیشان دەدات.
int total = null;Use int? total; if it may be empty, or give it a real value: int total = 0;.ئەگەر لەوانەیە بەتاڵ بێت int? total; بەکاربهێنە، یان ڕاستەقینەی پێ بدە: int total = 0;.
nickname!.length! crashes when the value is null. Prefer nickname?.length ?? 0 or an if check.! کاتێک null بێت دەڕووخێنێت. nickname?.length ?? 0 یان پشکنینی if باشترە.
if (count) { … }A condition must be a bool: if (count > 0). دەبێت bool بێت: if (count > 0).
int half = 7 / 2;/ gives a double. Use 7 ~/ 2 for an int, or double half = 7 / 2;./ double دەدات. بۆ int 7 ~/ 2 بەکاربهێنە، یان double half = 7 / 2;.
'Total: ' + 5You cannot add an int to a String. Write 'Total: $total' or 'Total: ' + total.toString().ناتوانیت int بخەیتە سەر String. بنووسە 'Total: $total' یان 'Total: ' + total.toString().
'$n * n'Inside a string, an expression needs braces: '${n * n}'.لە ناو ، پێویستی بە کەوانەی لوولی هەیە: '${n * n}'.
Expecting fall-through in switchچاوەڕوانکردنی چوونە خوارەوە لە switchـداDart 3 cases end by themselves; put empty cases together to share a body.حاڵەتەکانی 3 خۆیان کۆتایی دێن؛ حاڵەتە بەتاڵەکان پێکەوە دابنێ بۆ هاوبەشکردنی ناوەڕۆک.
A while loop that never ends کە هەرگیز کۆتایی نایەتMake sure something inside the loop moves the condition towards false (glasses--).دڵنیا بە شتێک لە ناو بەرەو false دەبات (glasses--).

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

Exerciseڕاهێنان1. Temperature١. پلەی گەرمی

Write a program with const celsius = 30; that calculates the temperature in Fahrenheit (F=C×9/5+32F = C \times 9 / 5 + 32) and prints 30 °C = 86 °F. Should fahrenheit be var, final or const?

بنووسە بە const celsius = 30; کە پلەی گەرمی بە فەهرەنهایت (F=C×9/5+32F = C \times 9 / 5 + 32) حیساب بکات و 30 °C = 86 °F چاپ بکات. ئایا fahrenheit دەبێت var، final یان const بێت؟

Show answerوەڵامەکە پیشان بدە
temperature.dartDARTType in a terminalلە تێرمیناڵدا بینووسە
void main() {
  const celsius = 30;
  final fahrenheit = celsius * 9 / 5 + 32;
  print('$celsius °C = $fahrenheit °F');
  print('$celsius °C = ${fahrenheit.toStringAsFixed(0)} °F');
}

final (or even const, because celsius is a constant) — the value never changes. / gives a double, so the first line shows 86.0; toStringAsFixed(0) shows 86.

final (یان تەنانەت const، چونکە celsius ) — هەرگیز ناگۆڕێت. / double دەدات، بۆیە دێڕی یەکەم 86.0 نیشان دەدات؛ toStringAsFixed(0) 86 نیشان دەدات.

Exerciseڕاهێنان2. Change the course program٢. بەرنامەکەی وانەکە بگۆڕە

Change the even/odd program to test 7. Then add a second check that says whether the number can be divided by 3, and if not, what remains.

جووت/تاک بگۆڕە بۆ ئەوەی 7 تاقی بکاتەوە. پاشان پشکنینێکی دووەم زیاد بکە کە بڵێت ئایا ژمارەکە بەسەر 3دا دابەش دەبێت و ئەگەر نا، چی دەمێنێتەوە.

Show answerوەڵامەکە پیشان بدە
even_odd.dartDARTType in a terminalلە تێرمیناڵدا بینووسە
void main() {
  var number = 7;
  if (number % 2 == 0) {
    print("Number is Even.");
  } else {
    print("Number is Odd.");
  }
  if (number % 3 == 0) {
    print('$number can be divided by 3.');
  } else {
    print('$number leaves ${number % 3} when divided by 3.');
  }
}
Exerciseڕاهێنان3. A city that may be missing٣. شارێک کە لەوانەیە نەبێت

Declare String? city;. Print the length of the city name, or 0 if there is none — in one line, without !. Then give city the value 'Sulaymaniyah' and print its length again.

String? city; ڕابگەیەنە. درێژیی ناوی شارەکە چاپ بکە، یان 0 ئەگەر نەبوو — لە یەک دێڕدا، بەبێ !. پاشان 'Sulaymaniyah' بدە بە city و دووبارە درێژییەکەی چاپ بکە.

Show answerوەڵامەکە پیشان بدە
null.dartDARTType in a terminalلە تێرمیناڵدا بینووسە
void main() {
  String? city; // the user has not chosen a city yet
  print(city?.length ?? 0);
  city = 'Sulaymaniyah';
  print(city.length);
}

After the assignment Dart knows city is not null, so city.length needs no ?..

دوای دانانی ، دەزانێت city null نییە، بۆیە city.length پێویستی بە ?. نییە.

Exerciseڕاهێنان4. Grades with a switch expression٤. پلەکان بە ⁦switch expression⁩

Turn the if … else if mark example into a switch expression and test it with 95, 64 and 49.

نموونەی نمرەی if … else if بگۆڕە بۆ ⁦switch expression⁩ و بە ⁦95⁩، ⁦64⁩ و ⁦49⁩ تاقی بکەرەوە.

Hintئاماژە

Use relational patterns such as >= 70 and _ for the rest.

patternـی بەراوردکردنی وەک >= 70 و _ بۆ ئەوانی تر بەکاربهێنە.

Show answerوەڵامەکە پیشان بدە
grade.dartDARTType in a terminalلە تێرمیناڵدا بینووسە
void main() {
  for (final mark in [95, 64, 49]) {
    var grade = switch (mark) {
      >= 90 && <= 100 => 'Excellent',
      >= 70 => 'Very good',
      >= 50 => 'Pass',
      _ => 'Try again',
    };
    print('$mark: $grade');
  }
}
Exerciseڕاهێنان5. Two loops٥. دوو خول

Print the multiplication table of 7 (from 7 x 1 to 7 x 10) with a for loop. Then add up the numbers from 1 to 100 with a while loop.

خشتەی لێکدانی 7 (لە 7 x 1 تا 7 x 10) بە چاپ بکە. پاشان ژمارەکانی 1 تا ⁦100⁩ بە کۆ بکەرەوە.

Show answerوەڵامەکە پیشان بدە
loops.dartDARTType in a terminalلە تێرمیناڵدا بینووسە
void main() {
  for (var i = 1; i <= 10; i++) {
    print('7 x $i = ${7 * i}');
  }

  var sum = 0;
  var n = 1;
  while (n <= 100) {
    sum += n;
    n++;
  }
  print('1 + 2 + ... + 100 = $sum');
}
Exerciseڕاهێنان6. Find the three bugs٦. سێ باگەکە بدۆزەرەوە

This program does not compile. Find the three mistakes and fix them.

ئەم کۆمپایل ناکرێت. سێ هەڵەکە بدۆزەرەوە و چاکیان بکەرەوە.

DART
void main() {
  int count = null;
  if (count) {
    print('Total: ' + count);
  }
}
Show answerوەڵامەکە پیشان بدە
bugs.dartDARTType in a terminalلە تێرمیناڵدا بینووسە
void main() {
  int count = null;
  if (count) {
    print('Total: ' + count);
  }
}
bugs_fixed.dartDARTType in a terminalلە تێرمیناڵدا بینووسە
void main() {
  int count = 0; // a real starting value
  if (count > 0) {
    // a real bool condition
    print('Total: $count'); // interpolation turns the int into text
  } else {
    print('Nothing yet.');
  }
}

Summaryپوختە

  • A program starts in main(); statements end with ;; comments are //, /* */ and ///.
  • var infers the type; final is set once; const is known before running.
  • int, double, String, bool. / gives a double, ~/ an int, % the remainder. Convert with parse, tryParse, toString.
  • Strings: $name and ${expression}. Conditions must be real bools.
  • Null safety: only Type? may be null; use ??, ?., ??= or an if check; ! and late move the check to runtime.
  • if / else if / else; switch with no fall-through, switch expressions and patterns; for, for-in, while, do-while, break, continue.
  • لە main()ـەوە دەست پێدەکات؛ بە ; کۆتایی دێن؛ //، /* */ و ///ـن.
  • var جۆرەکە دەدۆزێتەوە؛ final یەک جار دادەنرێت؛ const پێش کارکردن زانراوە.
  • int، double، String، bool. / double دەدات، ~/ int، % پاشماوە. بە parse، tryParse، toString بیگۆڕە.
  • : $name و ${expression}. دەبێت boolـی ڕاستەقینە بن.
  • : تەنها Type? دەتوانێت null بێت؛ ??، ?.، ??= یان پشکنینی if بەکاربهێنە؛ ! و late پشکنینەکە دەگوازنەوە بۆ .
  • if / else if / else؛ switch بەبێ چوونە خوارەوە، ⁦switch expression⁩ و pattern؛ for، ⁦for-in⁩، while، do-while، break، continue.
Review questionsپرسیارەکانی پێداچوونەوە
What is the difference between final and const?جیاوازیی نێوان final و const چییە؟

Both cannot change. final may get its value while the program runs; const must be known before.

هیچیان ناگۆڕێن. final دەتوانێت لە کاتی کارکردندا وەربگرێت؛ const دەبێت پێشتر زانراو بێت.

What does a ?? b give?a ?? b چی دەدات؟

a if it is not null, otherwise b.

a ئەگەر null نەبێت، ئەگینا b.

Why does if (count) not compile in Dart?بۆچی if (count) لە Dartـدا کۆمپایل ناکرێت؟

A condition must be a bool; Dart has no truthy values. Write if (count > 0).

دەبێت bool بێت؛ truthyـی نییە. بنووسە if (count > 0).

Videoڤیدیۆ

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

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

📱 FULL Flutter Beginner Course • Programming Basics / Widgets / Navigation / User Input / UIMitch Koko · Englishئینگلیزی · 1.6M viewsبینین · 46K likesلایک · Partبەشی 3:31–19:21 (ofلە 2:23:25)

Mitch Koko's calm beginner course in Dart and Flutter: variables, operators, if/else, switch, loops, functions, collections, a first screen and a counter.

کۆرسە ئارامەکەی ⁦Mitch Koko⁩ بۆ سەرەتاییەکان لە و : ، ، if/else، switch، ، ، List/Set/Map، یەکەم شاشە و .

Plays 3:31-19:21: variables, math, comparison and logical operators, if/else, switch, for and while loops.

لە ⁦3:31⁩ تا ⁦19:21⁩ پەخش دەبێت: ؛ ، و ؛ if/else و switch؛ و .

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

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

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

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

Dart Functions and Collectionsکردارەکان و کۆکراوەکانی 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 ن.