FlutterFlutter · Chapterبەش 8 · Lectureوانە 8.2

Buttonsدوگمەکان

What a button is and how onPressed enables or disables it; the course's button kinds and today's names (FlatButton, RaisedButton and OutlineButton were removed); Material 3's FilledButton, ElevatedButton, OutlinedButton, TextButton, IconButton, FAB and SegmentedButton; InkWell and button states; styling with styleFrom, ButtonStyle, WidgetStateProperty and themes; DropdownMenu and PopupMenuButton.

چییە و onPressed چۆن چالاک یان ناچالاکی دەکات؛ جۆرەکانی لە وانەکەدا و ناوەکانیان ئەمڕۆ (FlatButton، RaisedButton و OutlineButton لابران)؛ FilledButton، ElevatedButton، OutlinedButton، TextButton، IconButton، FAB و SegmentedButtonـی ⁦Material 3⁩؛ InkWell و دۆخەکانی ؛ شێوازدان بە styleFrom، ButtonStyle، WidgetStateProperty و ؛ DropdownMenu و PopupMenuButton.

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

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

  • Explain what a button is, and enable or disable one with onPressed.
  • Replace FlatButton, RaisedButton and OutlineButton with today's buttons.
  • Choose between FilledButton, ElevatedButton, OutlinedButton, TextButton, IconButton and FAB by importance.
  • Style buttons with styleFrom, ButtonStyle + WidgetStateProperty and themes.
  • Use SegmentedButton, DropdownMenu and PopupMenuButton with state.
  • ڕوون بکەیتەوە چییە و بە onPressed یەکێک چالاک یان ناچالاک بکەیت.
  • FlatButton، RaisedButton و OutlineButton بە ئەمڕۆ بگۆڕیت.
  • بە گوێرەی گرنگی لە نێوان FilledButton، ElevatedButton، OutlinedButton، TextButton، IconButton و FABـدا هەڵبژێریت.
  • شێواز بدەیت بە بە styleFrom، ⁦ButtonStyle + WidgetStateProperty⁩ و .
  • SegmentedButton، DropdownMenu و PopupMenuButton لەگەڵ بەکار بهێنیت.

What a button isدوگمە چییە

The course defines a button as the graphical control element that lets a user trigger an event: take an action, make a choice, search for something and more. Buttons can sit anywhere in a screen — in dialogs, forms, cards and toolbars.

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

Every Flutter button has two important parts: a child (what the button shows, usually a Text or an Icon) and onPressed, a callback — a function that Flutter calls when the user taps. Give onPressed a function and the button is enabled; give it null and the button is disabled: grey, and it ignores taps.

هەموو Flutter دوو بەشی گرنگی هەیە: child (ئەوەی پیشانی دەدات، زۆربەی جار Text یان Icon) و onPressed، کە — کە Flutter کاتێک بەکارهێنەر دەستی لێ دەدات بانگی دەکات. بدە بە onPressed و چالاکە؛ nullـی بدەیتێ ناچالاکە: خۆڵەمێشییە و گوێ بە دەستلێدان نادات.

The bell on the tea-house counterزەنگی سەر مێزی چایخانە

A button is like the small bell on the counter of a tea house. Its look tells you press me; pressing it makes something happen somewhere else (the tea maker comes). When the tea house closes, the owner covers the bell: it is still there, but pressing it does nothing — that is a disabled button.

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

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

A real bell rings the same way every time. A button's onPressed can run any code: save a form, open a page, add to a basket.

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

Quick checkپشکنینی خێراWhat does ElevatedButton(onPressed: null, child: Text('Save')) show?ElevatedButton(onPressed: null, child: Text('Save')) چی پیشان دەدات؟

The course's button kinds, and their names todayجۆرەکانی دوگمە لە وانەکەدا و ناوەکانیان ئەمڕۆ

The course lists eight kinds of button: Flat, Raised, Floating, Drop Down, Icon, Inkwell, Outline and PopupMenu. Its picture comes from an older Flutter. Three of those classes no longer exist, and Material 3 added new ones. This table maps every course name to today's widget:

وانەکە هەشت جۆری دەژمێرێت: Flat، Raised، Floating، ⁦Drop Down⁩، Icon، Inkwell، Outline و PopupMenu. وێنەکەی لە Flutterـێکی کۆنترەوەیە. سێ لەوانە ئیتر بوونیان نییە و ⁦Material 3⁩ هی نوێی زیاد کردووە. ئەم خشتەیە هەر ناوێکی وانەکە دەبەستێتەوە بە ئەمڕۆ:

A table of eight rows. Left, the course's names; right, today's widget and a small drawing of it. FlatButton (crossed out) → TextButton (a blue 'Login' word); RaisedButton (crossed out) → ElevatedButton (a light pill 'Press here' with a shadow); OutlineButton (crossed out) → OutlinedButton (an outlined pill 'Compare'); Floating Button → FloatingActionButton (a rounded square with +); Drop Down Button → DropdownMenu (a field 'Erbil' with an arrow); Icon Button → IconButton (a camera icon in a circle); Inkwell Button → InkWell (a card 'Kurdish tea' with a ripple); PopupMenu Button → PopupMenuButton (three dots and a small menu Edit, Share). A last green row: new in Material 3, FilledButton and SegmentedButton.خشتەیەکی هەشت ڕیزی. چەپ، ناوەکانی وانەکە؛ ڕاست، ویجێتی ئەمڕۆ و وێنەیەکی بچووکی. FlatButton (هێڵی بەسەردا هاتووە) ← TextButton (وشەی شینی 'Login')؛ RaisedButton (هێڵی بەسەردا هاتووە) ← ElevatedButton (کەپسوولێکی کاڵی 'Press here' بە سێبەرەوە)؛ OutlineButton (هێڵی بەسەردا هاتووە) ← OutlinedButton (کەپسوولێکی هێڵدار 'Compare')؛ Floating Button ← FloatingActionButton (چوارگۆشەیەکی گۆشەخڕ بە +)؛ Drop Down Button ← DropdownMenu (خانەیەکی 'Erbil' بە تیرێکەوە)؛ Icon Button ← IconButton (ئایکۆنی کامێرا لە بازنەیەکدا)؛ Inkwell Button ← InkWell (کارتێکی 'Kurdish tea' بە شەپۆلێکەوە)؛ PopupMenu Button ← PopupMenuButton (سێ خاڵ و مێنیوێکی بچووکی Edit، Share). ڕیزێکی سەوزی کۆتایی: نوێ لە Material 3ـدا، FilledButton و SegmentedButton.
Crossed-out names were removed from Flutter; use the name on the right.ئەو ناوانەی هێڵیان بەسەردا هاتووە لە Flutter لابراون؛ ناوەکەی ڕاست بەکار بهێنە.CêIT
CourseوانەکەTodayئەمڕۆUse it forبۆ چی
FlatButtonTextButtonA quiet action: More details, Cancel.کردەوەیەکی کپ: ⁦More details⁩، Cancel.
RaisedButtonElevatedButtonA button that must stand out from a busy background. کە دەبێت لە پاشبنەمایەکی قەرەباڵغ جیا ببێتەوە.
OutlineButtonOutlinedButtonA medium action next to a main one.کردەوەیەکی ناوەند لە تەنیشت کردەوەیەکی سەرەکییەوە.
Floating ButtonFloatingActionButtonThe screen's most important action.گرنگترین کردەوەی شاشەکە.
Drop Down ButtonDropdownMenuChoosing one value from a list (DropdownButton still works).هەڵبژاردنی یەک بەها لە چەند بژاردەیەک (DropdownButtonیش هێشتا کار دەکات).
Icon ButtonIconButtonAn action shown only as an icon.کردەوەیەک کە تەنها وەک پیشان دەدرێت.
Inkwell ButtonInkWellNot a button class: makes any widget tappable with a ripple. نییە: هەر بە شەپۆلەوە دەکات بە دەستلێدراو.
PopupMenu ButtonPopupMenuButtonA ⋮ button that opens a small menu of actions. ⋮ کە بچووکی کردەوەکان دەکاتەوە.
Quick checkپشکنینی خێراWhich of the course's eight button kinds is not a button class in today's Flutter?کام لە هەشت جۆرەکەی لە وانەکەدا لە Flutterـی ئەمڕۆدا نییە؟

The course's button kinds, and their names todayجۆرەکانی دوگمە لە وانەکەدا و ناوەکانیان ئەمڕۆ

FlatButton and RaisedButton are goneFlatButton و RaisedButton نەماون

Quick checkپشکنینی خێراAn old tutorial uses RaisedButton(color: Colors.green, …). What do you write today?فێرکارییەکی کۆن RaisedButton(color: Colors.green, …) بەکار دەهێنێت. ئەمڕۆ چی دەنووسیت؟

Material 3 buttons: from strong to quietدوگمەکانی ⁦Material 3⁩: لە بەهێزەوە بۆ کپ

Material 3 has five common buttons. They do the same job — run onPressed — but they look more or less important. Choose by importance, not by taste: the strongest for the one action you want most users to take, the quietest for small extras.

⁦Material 3⁩ پێنج باوی هەیە. هەمان کار دەکەن — onPressed ڕادەکەن — بەڵام کەمتر یان زیاتر گرنگ دەردەکەون. بە گوێرەی گرنگی هەڵیانبژێرە، نەک بە گوێرەی چێژ: بەهێزترینیان بۆ ئەو یەک کردەوەیەی دەتەوێت زۆربەی بەکارهێنەران بیکەن، کپترینیان بۆ شتی زیادەی بچووک.

Five Material 3 buttons from top to bottom, with an arrow down the right side meaning 'less important'. FilledButton 'Buy now' (solid teal): the one main action. FilledButton.tonal 'Add to basket' (light teal): important, but second. ElevatedButton 'Save for later' (light, with a shadow): needs to stand out from a picture. OutlinedButton 'Compare' (an outline): a side action. TextButton 'More details' (only text): the least important. Note: use one filled button per screen.پێنج دوگمەی Material 3 لە سەرەوە بۆ خوارەوە، تیرێک بە لای ڕاستدا بە واتای 'کەمتر گرنگ'. FilledButton 'Buy now' (شینی سەوزباوی پڕ): یەک کردەوەی سەرەکی. FilledButton.tonal 'Add to basket' (شینی سەوزباوی کاڵ): گرنگ، بەڵام دووەم. ElevatedButton 'Save for later' (کاڵ، بە سێبەرەوە): پێویستە لە وێنەیەک جیا ببێتەوە. OutlinedButton 'Compare' (هێڵی دەرەوە): کردەوەیەکی لاوەکی. TextButton 'More details' (تەنها دەق): کەمترین گرنگی. تێبینی: لە هەر شاشەیەکدا یەک دوگمەی filled بەکار بهێنە.
From most to least important: Filled, tonal, Elevated, Outlined, Text.لە گرنگترینەوە بۆ کەمترین گرنگی: Filled، tonal، Elevated، Outlined، Text.CêIT
The five buttons and a disabled oneپێنج دوگمەکە و یەکێکی ناچالاکDARTRuns on a phone (or an emulator)لەسەر مۆبایل کار دەکات
import 'package:flutter/material.dart';

class ButtonGallery extends StatelessWidget {
  const ButtonGallery({super.key});

  void _buy() => debugPrint('Buy pressed');

  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        FilledButton(onPressed: _buy, child: const Text('Buy now')),
        FilledButton.tonal(onPressed: _buy, child: const Text('Add to basket')),
        ElevatedButton(onPressed: _buy, child: const Text('Save for later')),
        OutlinedButton(onPressed: _buy, child: const Text('Compare')),
        TextButton(onPressed: _buy, child: const Text('More details')),
        // onPressed: null -> the button is disabled (greyed out, no ripple)
        const FilledButton(onPressed: null, child: Text('Sold out')),
      ],
    );
  }
}
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 6

One callback for all buttons. Pass the function's name — no ().

یەک بۆ هەموو . ناوی بدە — بەبێ ().

Lineدێڕی 13

The strongest button: solid primary colour.

بەهێزترین : ڕەنگی سەرەکیی پڕ.

Lineدێڕی 19

null → disabled. It can even be const.

null ← ناچالاک. تەنانەت دەتوانێت const بێت.

Quick checkپشکنینی خێراA checkout screen has Pay now and Back to basket. Which pair fits Material 3?شاشەیەکی پارەدان ⁦Pay now⁩ و ⁦Back to basket⁩ـی هەیە. کام جووت لەگەڵ ⁦Material 3⁩ دەگونجێت؟

Material 3 buttons: from strong to quietدوگمەکانی ⁦Material 3⁩: لە بەهێزەوە بۆ کپ

Buttons with an iconدوگمە لەگەڵ ئایکۆن

Most button classes have an .icon constructor that puts an icon before a label. In a right-to-left app the icon moves to the right side of the label automatically.

زۆربەی .iconـیان هەیە کە iconـێک دەخاتە پێش labelـێکەوە. لە خۆکارانە دەچێتە لای ڕاستی .

Icon and label togetherئایکۆن و لەیبڵ پێکەوەDARTRuns on a phone (or an emulator)لەسەر مۆبایل کار دەکات
import 'package:flutter/material.dart';

class IconLabelButtons extends StatelessWidget {
  const IconLabelButtons({super.key});

  @override
  Widget build(BuildContext context) {
    return Wrap(
      spacing: 8,
      children: [
        FilledButton.icon(
          onPressed: () {},
          icon: const Icon(Icons.shopping_cart),
          label: const Text('Order'),
        ),
        OutlinedButton.icon(
          onPressed: () {},
          icon: const Icon(Icons.share),
          label: const Text('Share'),
        ),
        TextButton.icon(
          onPressed: () {},
          icon: const Icon(Icons.call),
          label: const Text('Call the shop'),
        ),
      ],
    );
  }
}
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 8

Wrap puts the buttons in a row and moves them to a new line when there is no room.

Wrap لە ڕیزێکدا دادەنێت و کاتێک شوێن نییە دەیانباتە دێڕێکی نوێ.

Lineدێڕی 13-14

icon: and label: instead of child:.

icon: و label: لە جیاتی child:.

Quick checkپشکنینی خێراWhich constructor gives a button with a cart icon and the word Order?کام بە سەبەتە و وشەی Order دەدات؟

IconButton: an icon you can tapIconButton: ئایکۆنێک کە دەستی لێ دەدرێت

IconButton is a round tap area around an Icon. Material 3 adds styled versions — IconButton.filled, .filledTonal and .outlined — and toggle buttons: with isSelected and selectedIcon, the same button shows a different icon when it is on. Because there is no text, always give a tooltip: it appears on a long press and screen readers read it aloud.

IconButton ناوچەیەکی خڕی دەستلێدانە بە دەوری Iconـێکدا. ⁦Material 3⁩ وەشانی شێوازداری زیاد کردووە — IconButton.filled، .filledTonal و .outlined — و هەڵکردن و کوژاندنەوە: بە isSelected و selectedIcon، هەمان کاتێک داگیرساوە جیاواز پیشان دەدات. چونکە دەقی نییە، هەمیشە tooltipـێک بدە: بە پەنجەڕاگرتنی درێژ دەردەکەوێت و بە دەنگی بەرز دەیخوێننەوە.

A favourite toggle and three styled icon buttonsدوگمەیەکی دڵخواز و سێ IconButtonـی شێوازدارDARTRuns on a phone (or an emulator)لەسەر مۆبایل کار دەکات
import 'package:flutter/material.dart';

class FavouriteButton extends StatefulWidget {
  const FavouriteButton({super.key});

  @override
  State<FavouriteButton> createState() => _FavouriteButtonState();
}

class _FavouriteButtonState extends State<FavouriteButton> {
  bool _liked = false;

  @override
  Widget build(BuildContext context) {
    return Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        IconButton(
          tooltip: 'Favourite',
          isSelected: _liked,
          icon: const Icon(Icons.favorite_border),
          selectedIcon: const Icon(Icons.favorite, color: Colors.red),
          onPressed: () => setState(() => _liked = !_liked),
        ),
        IconButton.filled(
          tooltip: 'Search',
          onPressed: () {},
          icon: const Icon(Icons.search),
        ),
        IconButton.filledTonal(
          tooltip: 'Share',
          onPressed: () {},
          icon: const Icon(Icons.share),
        ),
        IconButton.outlined(
          tooltip: 'Delete',
          onPressed: () {},
          icon: const Icon(Icons.delete_outline),
        ),
      ],
    );
  }
}
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 11

The on/off state lives in a State object.

هەڵکراو/کوژاوە لە دەژی.

Lineدێڕی 20-22

Off: an empty heart. On: a red, filled heart.

کوژاوە: دڵێکی بەتاڵ. هەڵکراو: دڵێکی سووری پڕ.

Lineدێڕی 23

Each tap flips the value and rebuilds.

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

Quick checkپشکنینی خێراWhy should every IconButton have a tooltip?بۆچی دەبێت هەموو IconButtonـێک tooltipـی هەبێت؟

FloatingActionButtonدوگمەی فڕیو: FloatingActionButton

The course's Floating Button is the FloatingActionButton (FAB): one button for the screen's most important action, floating above the content in the Scaffold's floatingActionButton slot. FloatingActionButton.extended adds a text label, and .small / .large change the size. Where it sits and how it looks is taught in floatingActionButton and Where the floating button sits.

⁦Floating Button⁩ـی وانەکە FloatingActionButtonـە ⁦(FAB)⁩: یەک بۆ گرنگترین کردەوەی شاشەکە کە لە شوێنی floatingActionButtonـی Scaffoldـدا لە سەرووی ناوەڕۆکەوە دەفڕێت. FloatingActionButton.extended دەق زیاد دەکات و .small / .large قەبارەکە دەگۆڕن. شوێن و شێوەکەی لە floatingActionButton و دوگمەی کردەوەی سەرەکی لە کوێ دادەنیشێتدا فێر دەکرێت.

An extended FABFABـی درێژکراوەDARTRuns on a phone (or an emulator)لەسەر مۆبایل کار دەکات
import 'package:flutter/material.dart';

class OrdersPage extends StatelessWidget {
  const OrdersPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Orders')),
      body: const Center(child: Text('No orders yet')),
      floatingActionButton: FloatingActionButton.extended(
        onPressed: () {},
        icon: const Icon(Icons.add),
        label: const Text('New order'),
      ),
    );
  }
}
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 11

Icon + label in one wide floating button.

+ لە یەک فڕیوی پاندا.

Quick checkپشکنینی خێراHow many floating action buttons should a screen usually have?شاشەیەک زۆربەی جار دەبێت چەند هەبێت؟

A button's states: normal, pressed, disabledدۆخەکانی دوگمە: ئاسایی، داگیراو، ناچالاک

A button changes its look to tell the user what is happening. Flutter calls these states: enabled (normal), hovered (a mouse is over it), focused (selected with the keyboard), pressed (a finger is on it — the ripple spreads from the touch point) and disabled (grey, no ripple, no onPressed).

شێوەی خۆی دەگۆڕێت بۆ ئەوەی بە بەکارهێنەر بڵێت چی ڕوو دەدات. Flutter ئەمانە ناو دەنێت دۆخ: enabled (ئاسایی)، hovered ( لەسەریەتی)، focused (بە هەڵبژێردراوە)، pressed (پەنجەیەک لەسەریەتی — شەپۆلەکە لە خاڵی دەستلێدانەوە بڵاو دەبێتەوە) و disabled (خۆڵەمێشی، بێ شەپۆل، بێ onPressed).

Four frames of one big teal button 'Add a glass', with its onPressed line under it and 'Glasses of tea' below. 1, enabled: onPressed: _addGlass. 2, pressed: a finger touches the button and a small light circle (the ripple) starts under it. 3, the light ripple has spread over the whole button. 4, disabled: the button is grey and says 'The tray is full', the line says onPressed: null, and the count is 5.
Four frames of one big teal button 'Add a glass', with its onPressed line under it and 'Glasses of tea' below. 1, enabled: onPressed: _addGlass. 2, pressed: a finger touches the button and a small light circle (the ripple) starts under it. 3, the light ripple has spread over the whole button. 4, disabled: the button is grey and says 'The tray is full', the line says onPressed: null, and the count is 5.
enabled → pressed (ripple) → disabled.چالاک ← داگیراو (شەپۆل) ← ناچالاک.CêIT
A button that disables itselfدوگمەیەک کە خۆی ناچالاک دەکاتDARTRuns on a phone (or an emulator)لەسەر مۆبایل کار دەکات
import 'package:flutter/material.dart';

class TeaCounter extends StatefulWidget {
  const TeaCounter({super.key});

  @override
  State<TeaCounter> createState() => _TeaCounterState();
}

class _TeaCounterState extends State<TeaCounter> {
  static const int maxGlasses = 5;
  int _glasses = 0;

  void _addGlass() {
    setState(() => _glasses++);
  }

  @override
  Widget build(BuildContext context) {
    final bool full = _glasses >= maxGlasses;
    return Column(
      mainAxisSize: MainAxisSize.min,
      children: [
        Text('Glasses of tea: $_glasses', style: const TextStyle(fontSize: 22)),
        const SizedBox(height: 12),
        FilledButton(
          // A function -> enabled. null -> disabled.
          onPressed: full ? null : _addGlass,
          child: Text(full ? 'The tray is full' : 'Add a glass'),
        ),
      ],
    );
  }
}
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 20

Decide from the state whether the button may be used.

لە بڕیار بدە ئایا دەتوانرێت بەکار بهێنرێت.

Lineدێڕی 28

A function → enabled; null → disabled. Flutter draws the grey look for you.

← چالاک؛ null ← ناچالاک. Flutter خۆی شێوە خۆڵەمێشییەکە دەکێشێت.

Lineدێڕی 29

Tell the user why the button is off.

بە بەکارهێنەر بڵێ بۆچی کوژاوەتەوە.

Quick checkپشکنینی خێراWhat does the ripple tell the user?شەپۆلەکە چی بە بەکارهێنەر دەڵێت؟

A button's states: normal, pressed, disabledدۆخەکانی دوگمە: ئاسایی، داگیراو، ناچالاک

InkWell: make anything tappableInkWell: هەر شتێک بکە بە دەستلێدراو

The course's Inkwell Button is not a button class. InkWell wraps any widget — a card, a row, a picture — and gives it onTap, onLongPress and the Material ripple. The ripple is drawn on the nearest Material widget above it (a Card, a Scaffold or Material itself). An InkWell must have one: without it, Flutter stops with the error No Material widget found.

⁦Inkwell Button⁩ـی وانەکە نییە. InkWell هەر — کارتێک، ڕیزێک، وێنەیەک — لە خۆ دەگرێت و onTap، onLongPress و شەپۆلی Material دەداتێ. شەپۆلەکە لەسەر نزیکترین Material لە سەرووییەوە دەکێشرێت (Card، Scaffold یان خودی Material). InkWell دەبێت یەکێکی هەبێت: بەبێ ئەو، Flutter بە ⁦No Material widget found⁩ دەوەستێت.

A tappable cardکارتێکی دەستلێدراوDARTRuns on a phone (or an emulator)لەسەر مۆبایل کار دەکات
import 'package:flutter/material.dart';

class TappableCard extends StatelessWidget {
  const TappableCard({super.key});

  @override
  Widget build(BuildContext context) {
    return Card(
      // Card is a Material, so InkWell can draw its ripple on it.
      clipBehavior: Clip.antiAlias,
      child: InkWell(
        onTap: () => debugPrint('Card tapped'),
        onLongPress: () => debugPrint('Card long-pressed'),
        child: const Padding(
          padding: EdgeInsets.all(16),
          child: Row(
            children: [
              Icon(Icons.local_cafe),
              SizedBox(width: 12),
              Text('Kurdish tea  ·  500 IQD'),
            ],
          ),
        ),
      ),
    );
  }
}
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 10

Keeps the ripple inside the card's round corners.

شەپۆلەکە لە ناو گۆشە خڕەکانی کارتەکەدا دەهێڵێتەوە.

Lineدێڕی 12-13

A tap and a long press can do different things.

دەستلێدان و پەنجەڕاگرتنی درێژ دەتوانن کاری جیاواز بکەن.

Quick checkپشکنینی خێراInside a Scaffold, you put an InkWell inside a Container with a background colour. Taps work, but no ripple appears. Why?لە ناو Scaffoldـێکدا، InkWellـێک دەخەیتە ناو Containerـێکی ڕەنگدارەوە. دەستلێدان کار دەکات، بەڵام هیچ شەپۆلێک دەرناکەوێت. بۆچی؟

Styling a button: styleFromشێوازدان بە دوگمە: styleFrom

The course lists the standard features of buttons: they can be themed (shape, colour, animation, behaviour), the icons and text inside them can be styled, and a button can be composed of different child widgets — its child can be any widget, such as a Row with an icon and two texts.

وانەکە تایبەتمەندییە ستانداردەکانی دەژمێرێت: دەتوانرێت پێ بدرێت (شێوە، ڕەنگ، جووڵە، ڕەفتار)، و دەقی ناویان دەتوانرێت شێوازیان پێ بدرێت و دەتوانێت لە منداڵی جیاواز پێک بێت — childـەکەی دەتوانێت هەر بێت، وەک Rowـێک بە و دوو دەقەوە.

Today all of a button's looks live in one ButtonStyle given to style:. The easy way to make one is the button's static styleFrom method. Here are the course's FlatButton and RaisedButton rewritten: color becomes backgroundColor, textColor becomes foregroundColor (it colours the text, the icon and the ripple), and the text size moves into textStyle.

ئەمڕۆ هەموو شێوەکانی لە یەک ButtonStyleـدان کە دەدرێت بە style:. ڕێگە ئاسانەکە بۆ دروستکردنی، styleFromـی . ئەمە FlatButton و RaisedButtonـی وانەکەیە بە نووسینەوەی نوێ: color دەبێت بە backgroundColor، textColor دەبێت بە foregroundColor (دەق، و شەپۆلەکە ڕەنگ دەکات) و قەبارەی دەق دەچێتە ناو textStyleـەوە.

The course's two buttons, todayدوو دوگمەکەی وانەکە، ئەمڕۆDARTRuns on a phone (or an emulator)لەسەر مۆبایل کار دەکات
import 'package:flutter/material.dart';

class CourseButtonsToday extends StatelessWidget {
  const CourseButtonsToday({super.key});

  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisSize: MainAxisSize.min,
      children: [
        // The course's FlatButton, today: a TextButton
        TextButton(
          style: TextButton.styleFrom(
            backgroundColor: Colors.blueAccent,
            foregroundColor: Colors.white,
            textStyle: const TextStyle(fontSize: 20),
          ),
          onPressed: () {},
          child: const Text('Login'),
        ),
        const SizedBox(height: 12),
        // The course's RaisedButton, today: an ElevatedButton
        ElevatedButton(
          style: ElevatedButton.styleFrom(
            backgroundColor: Colors.green,
            foregroundColor: Colors.white,
            padding: const EdgeInsets.all(8),
            textStyle: const TextStyle(fontSize: 20),
          ),
          onPressed: () {},
          child: const Text('Press Here'),
        ),
      ],
    );
  }
}
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 12-14

FlatButton → TextButton; color → backgroundColor.

FlatButton ← TextButton؛ color ← backgroundColor.

Lineدێڕی 15

textColor → foregroundColor.

textColor ← foregroundColor.

Lineدێڕی 23-27

RaisedButton → ElevatedButton; padding moves into the style.

RaisedButton ← ElevatedButton؛ padding دەچێتە ناو شێوازەکەوە.

Lineدێڕی 31

child comes last (a lint rule), and the Text can be const.

child لە کۆتاییدا دێت (یاسایەکی lint) و Textـەکە دەتوانێت const بێت.

More styleFrom propertiesتایبەتمەندییەکانی زیاتری styleFromDARTRuns on a phone (or an emulator)لەسەر مۆبایل کار دەکات
import 'package:flutter/material.dart';

class PayButton extends StatelessWidget {
  const PayButton({super.key});

  @override
  Widget build(BuildContext context) {
    return ElevatedButton(
      style: ElevatedButton.styleFrom(
        backgroundColor: Colors.teal,
        foregroundColor: Colors.white, // text, icon and ripple colour
        disabledBackgroundColor: Colors.grey.shade300,
        minimumSize: const Size.fromHeight(56), // full width, 56 high
        padding: const EdgeInsets.symmetric(horizontal: 24),
        shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
        elevation: 4,
        textStyle: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
      ),
      onPressed: () {},
      child: const Text('Pay 12,000 IQD'),
    );
  }
}
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 12

The colour when onPressed is null.

ڕەنگەکە کاتێک onPressed nullـە.

Lineدێڕی 13

As wide as possible, 56 pixels high — a typical Pay button.

هێندەی دەکرێت پان، ٥٦ بەرز — ئاسایی Pay.

Lineدێڕی 15

Rounded rectangle instead of the default pill.

لاکێشەیەکی گۆشەخڕ لە جیاتی کەپسوولە بنەڕەتییەکە.

Lineدێڕی 16

The shadow's height.

بەرزیی سێبەرەکە.

Quick checkپشکنینی خێراWhich styleFrom property sets the colour of a button's text and icon?کام styleFrom ڕەنگی دەق و دیاری دەکات؟

بنەماکانی فلاتەر: فێرکاری بۆ ئاستی دەستپێک (1.5 کاتژمێر) | Flutter Fundamentals: Beginner (1.5-Hour)Flutter Kurd Code · Kurdish (Sorani)کوردی (سۆرانی) · 5.3K viewsبینین · 183 likesلایک · Partبەشی 45:16–50:20 (ofلە 1:30:00)

A Kurdish beginner course: what Flutter is, making an Android emulator, creating and running a project in VS Code, Hello World and hot reload.

کۆرسێکی کوردی بۆ سەرەتاییەکان: چییە، دروستکردنی Android، دروستکردن و کارپێکردنی پرۆژەیەک لە ⁦VS Code⁩ـدا، ⁦Hello World⁩ و .

Watch 45:16–50:20 (Kurdish): an ElevatedButton is added and styled with ElevatedButton.styleFrom (backgroundColor, foregroundColor, shape).

لە ⁦45:16⁩ تا ⁦50:20⁩ سەیر بکە (بە کوردی): ElevatedButtonـێک زیاد دەکرێت و بە ElevatedButton.styleFrom شێوەی پێ دەدرێت (backgroundColor، foregroundColor، shape).

Styling a button: styleFromشێوازدان بە دوگمە: styleFrom

Different looks for different states: WidgetStatePropertyشێوەی جیاواز بۆ دۆخی جیاواز: WidgetStateProperty

styleFrom gives one value for the normal state and picks sensible values for the others. For full control, build a ButtonStyle yourself. Its properties are WidgetStateProperty values: either one value for every state (WidgetStatePropertyAll(…)), or a function that receives the button's current set of states and returns a value (WidgetStateProperty.resolveWith). Return null to keep the default.

styleFrom بەهایەک بۆ دۆخی ئاسایی دەدات و بۆ دۆخەکانی تر بەهای گونجاو هەڵدەبژێرێت. بۆ کۆنترۆڵی تەواو، خۆت ButtonStyleـێک دروست بکە. ئەو بەهای WidgetStatePropertyن: یان یەک بەها بۆ هەموو دۆخێک (WidgetStatePropertyAll(…))، یان کە دۆخەکانی ئێستای وەردەگرێت و بەهایەک دەگەڕێنێتەوە (WidgetStateProperty.resolveWith). null بگەڕێنەوە بۆ هێشتنەوەی بنەڕەتییەکە.

Orange, darker when pressed, grey when disabledپرتەقاڵی، تۆختر کاتێک داگیراوە، خۆڵەمێشی کاتێک ناچالاکەDARTRuns on a phone (or an emulator)لەسەر مۆبایل کار دەکات
import 'package:flutter/material.dart';

class StateColourButton extends StatelessWidget {
  const StateColourButton({super.key, required this.onPressed});

  final VoidCallback? onPressed;

  @override
  Widget build(BuildContext context) {
    return FilledButton(
      style: ButtonStyle(
        backgroundColor: WidgetStateProperty.resolveWith<Color?>((states) {
          if (states.contains(WidgetState.disabled)) return Colors.grey;
          if (states.contains(WidgetState.pressed)) return Colors.deepOrange;
          return Colors.orange; // the normal state
        }),
        foregroundColor: const WidgetStatePropertyAll(Colors.white),
        padding: const WidgetStatePropertyAll(EdgeInsets.all(16)),
      ),
      onPressed: onPressed,
      child: const Text('Send order'),
    );
  }
}
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 12

states is a Set such as {WidgetState.pressed} or {WidgetState.disabled}.

states وەک {WidgetState.pressed} یان {WidgetState.disabled}.

Lineدێڕی 13

Check disabled first: a disabled button is never pressed.

سەرەتا disabled بپشکنە: ناچالاک هەرگیز داناگیرێت.

Lineدێڕی 17

One value for every state.

یەک بەها بۆ هەموو دۆخێک.

Quick checkپشکنینی خێراWhat should a resolveWith function return for a state you do not want to change? resolveWith بۆ دۆخێک کە ناتەوێت بیگۆڕیت دەبێت چی بگەڕێنێتەوە؟

Styling a button: styleFromشێوازدان بە دوگمە: styleFrom

One style for every button: themesیەک شێواز بۆ هەموو دوگمەیەک: تێمەکان

The course says themes can be applied to buttons: shapes, colour, animation and behaviour. Instead of styling each button, put one style in the app's theme: ThemeData has elevatedButtonTheme, filledButtonTheme, outlinedButtonTheme, textButtonTheme and more. A button's own style still wins over the theme for the properties it sets.

وانەکە دەڵێت دەکرێت بدرێت بە : شێوە، ڕەنگ، جووڵە و ڕەفتار. لە جیاتی شێوازدان بە هەر ، یەک شێواز بخە ناو : ThemeData elevatedButtonTheme، filledButtonTheme، outlinedButtonTheme، textButtonTheme و زیاتری هەیە. styleـی خودی هێشتا بۆ هەر کە خۆی دایدەنێت بەسەر زاڵە.

An app-wide ElevatedButton styleشێوازی ElevatedButton بۆ هەموو ئەپەکەDARTRuns on a phone (or an emulator)لەسەر مۆبایل کار دەکات
import 'package:flutter/material.dart';

void main() {
  runApp(
    MaterialApp(
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.teal),
        // Every ElevatedButton in the app gets this style.
        elevatedButtonTheme: ElevatedButtonThemeData(
          style: ElevatedButton.styleFrom(
            minimumSize: const Size(120, 48),
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(8),
            ),
          ),
        ),
      ),
      home: Scaffold(
        body: Center(
          child: ElevatedButton(onPressed: () {}, child: const Text('Themed')),
        ),
      ),
    ),
  );
}
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 7

All button colours come from the colour scheme (see Theming with Material 3).

هەموو ڕەنگەکانی لە colorSchemeـەوە دێن (سەیری تێم لە ⁦Material 3⁩ـدا بکە).

Lineدێڕی 11-13

Every ElevatedButton in the app: at least 120 × 48, corners of radius 8.

هەموو ElevatedButtonـێکی : لانیکەم ١٢٠ × ٤٨، گۆشە بە نیوەتیرەی ٨.

Quick checkپشکنینی خێراThe theme makes every ElevatedButton's corners radius 8, but one button has style: ElevatedButton.styleFrom(shape: StadiumBorder()). What shape does that one get? گۆشەی هەموو ElevatedButtonـێک دەکات بە نیوەتیرەی ٨، بەڵام یەک style: ElevatedButton.styleFrom(shape: StadiumBorder())ـی هەیە. ئەو یەکە چ شێوەیەک وەردەگرێت؟

SegmentedButton: choose one (or more) of a fewSegmentedButton: یەکێک (یان زیاتر) لە چەند دانەیەک هەڵبژێرە

A SegmentedButton is a row of 2–5 joined buttons for choosing between a few options: a size, a view, a sort order. It replaces the older ToggleButtons. Its selected value is a Set, because with multiSelectionEnabled: true several segments can be on. Like every input, the selection is state: keep it in a State and update it in onSelectionChanged.

SegmentedButton ڕیزێکە لە ٢–٥ پێکەوەلکاو بۆ هەڵبژاردن لە نێوان چەند بژاردەیەکدا: قەبارەیەک، شێوەی پیشاندانێک، ڕیزبەندییەک. جێگەی ToggleButtonsـی کۆنتر دەگرێتەوە. بەهای selectedـەکەی ، چونکە بە multiSelectionEnabled: true چەند بەشێک دەتوانن هەڵبژێردرابن. وەک هەموو ، هەڵبژاردنەکە : لە Stateـێکدا هەڵیبگرە و لە onSelectionChangedـدا نوێی بکەرەوە.

Choosing a glass sizeهەڵبژاردنی قەبارەی پەرداخDARTRuns on a phone (or an emulator)لەسەر مۆبایل کار دەکات
import 'package:flutter/material.dart';

enum GlassSize { small, medium, large }

class GlassSizePicker extends StatefulWidget {
  const GlassSizePicker({super.key});

  @override
  State<GlassSizePicker> createState() => _GlassSizePickerState();
}

class _GlassSizePickerState extends State<GlassSizePicker> {
  GlassSize _size = GlassSize.medium;

  @override
  Widget build(BuildContext context) {
    return SegmentedButton<GlassSize>(
      segments: const [
        ButtonSegment(value: GlassSize.small, label: Text('Small')),
        ButtonSegment(value: GlassSize.medium, label: Text('Medium')),
        ButtonSegment(
          value: GlassSize.large,
          label: Text('Large'),
          icon: Icon(Icons.local_cafe),
        ),
      ],
      selected: {_size}, // a Set, because several may be selected
      onSelectionChanged: (Set<GlassSize> newSelection) {
        setState(() => _size = newSelection.first);
      },
    );
  }
}
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3

An enum lists the possible values; the compiler knows there are exactly three.

enum بەها ئەگەرییەکان دەژمێرێت؛ دەزانێت ڕێک سێ دانەن.

Lineدێڕی 27

A set with one element: single selection.

بە یەک توخمەوە: هەڵبژاردنی تاک.

Lineدێڕی 28-29

Flutter gives the new set; store it and rebuild.

Flutter نوێ دەدات؛ هەڵیبگرە و دووبارە دروستی بکەرەوە.

Quick checkپشکنینی خێراWhy is selected a Set<GlassSize> and not a single GlassSize?بۆچی selected Set<GlassSize>ـە نەک تەنها یەک GlassSize؟

SegmentedButton (Widget of the Week)Flutter · Englishئینگلیزی · 79K viewsبینین · 2.7K likesلایک

Flutter's official short video on SegmentedButton: a row of segments, the selected Set, multi-select and styling.

ڤیدیۆ کورتە فەرمییەکەی دەربارەی SegmentedButton: چەند بەشێک لە تەنیشت یەکەوە، Setـی هەڵبژێردراوەکان، هەڵبژاردنی زیاتر لە یەک و شێوەدان.

The whole 1:27 official clip: segments (0:07), handling the selected Set (0:17) and styling (1:07).

هەموو کلیپە فەرمییەکە ⁦(1:27)⁩: بەشەکان ⁦(0:07)⁩، مامەڵەکردن لەگەڵ Setـی هەڵبژێردراوەکان ⁦(0:17)⁩ و شێوەدان ⁦(1:07)⁩.

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

MistakeهەڵەWhat happensچی ڕوو دەداتFixچاککردن
onPressed: save() — calling the function.onPressed: save() — بانگکردنی .A compile error (This expression has a type of 'void' so its value can't be used): the brackets call save while the button is built and pass its result, not the function. (⁦This expression has a type of 'void' so its value can't be used⁩): کەوانەکان لە کاتی دروستکردنی save بانگ دەکەن و ئەنجامەکەی دەنێرن، نەک خودی .Pass it: onPressed: save or onPressed: () => save().بینێرە: onPressed: save یان onPressed: () => save().
onPressed: () {} to make a button look disabled.onPressed: () {} بۆ ئەوەی ناچالاک دەربکەوێت.It looks enabled and ripples, but nothing happens.چالاک دەردەکەوێت و شەپۆل دەدات، بەڵام هیچ ڕوو نادات.onPressed: null.onPressed: null.
FlatButton, RaisedButton, OutlineButton from old tutorials.FlatButton، RaisedButton، OutlineButton لە فێرکارییە کۆنەکانەوە.Compile error: the classes were removed.: لابراون.TextButton, ElevatedButton, OutlinedButton + styleFrom.TextButton، ElevatedButton، ⁦OutlinedButton +⁩ styleFrom.
color: or textColor: on a new button.color: یان textColor: لەسەر نوێ.Compile error: no such parameter.: ئەم نییە.styleFrom(backgroundColor:, foregroundColor:).styleFrom(backgroundColor:, foregroundColor:).
MaterialStateProperty / MaterialState.MaterialStateProperty / MaterialState.Deprecation warnings.ئاگادارکردنەوە کە ناوەکان .WidgetStateProperty / WidgetState (or dart fix --apply).WidgetStateProperty / WidgetState (یان dart fix --apply).
SegmentedButton or DropdownMenu without setState.SegmentedButton یان DropdownMenu بەبێ setState.The choice jumps back; the UI does not follow.هەڵبژاردنەکە دەگەڕێتەوە؛ شوێنی ناکەوێت.Keep the value in a State and update it with setState.بەهاکە لە Stateـێکدا هەڵبگرە و بە setState نوێی بکەرەوە.
An IconButton with no tooltip.IconButtonـێک بەبێ tooltip.Unclear icon; screen readers say just button. ناڕوون؛ تەنها دەڵێن button.Add tooltip: 'Search'.tooltip: 'Search' زیاد بکە.
Several filled buttons on one screen.چەند filled لە یەک شاشەدا.Nothing stands out.هیچ شتێک دیار نییە.One filled button; the others outlined or text.یەک filled؛ ئەوانی تر outlined یان text.

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

Exerciseڕاهێنان1. Repair the course's FlatButton١. FlatButtonـی وانەکە چاک بکەرەوە

Rewrite the course's FlatButton for today's Flutter: blue accent background, white text of size 20, the word Login.

FlatButtonـی وانەکە بۆ Flutterـی ئەمڕۆ بنووسەرەوە: پاشبنەمای blueAccent، دەقی سپی بە قەبارەی ٢٠، وشەی Login.

The course's codeکۆدی وانەکەDART
FlatButton(
  child: Text('Login', style: TextStyle(fontSize: 20.0),),
  color: Colors.blueAccent,
  textColor: Colors.white,
  onPressed: () {},
),
Hintئاماژە

color → backgroundColor, textColor → foregroundColor; the TextStyle goes into textStyle.

color ← backgroundColor، textColor ← foregroundColor؛ TextStyleـەکە دەچێتە ناو textStyle.

Show answerوەڵامەکە پیشان بدە
TextButtonدوگمەی TextButtonDART
TextButton(
  style: TextButton.styleFrom(
    backgroundColor: Colors.blueAccent,
    foregroundColor: Colors.white,
    textStyle: const TextStyle(fontSize: 20),
  ),
  onPressed: () {},
  child: const Text('Login'),
)
Exerciseڕاهێنان2. Repair the course's RaisedButton٢. RaisedButtonـی وانەکە چاک بکەرەوە

Rewrite the course's green RaisedButton Press Here (white text, size 20, padding 8).

RaisedButtonـی سەوزی ⁦Press Here⁩ـی وانەکە بنووسەرەوە (دەقی سپی، قەبارە ٢٠، ٨).

The course's codeکۆدی وانەکەDART
RaisedButton(
  child: Text("Press Here", style: TextStyle(fontSize: 20),),
  onPressed: (){},
  color: Colors.green,
  textColor: Colors.white,
  padding: EdgeInsets.all(8.0),
),
Show answerوەڵامەکە پیشان بدە
ElevatedButtonدوگمەی ElevatedButtonDART
ElevatedButton(
  style: ElevatedButton.styleFrom(
    backgroundColor: Colors.green,
    foregroundColor: Colors.white,
    padding: const EdgeInsets.all(8),
    textStyle: const TextStyle(fontSize: 20),
  ),
  onPressed: () {},
  child: const Text('Press Here'),
)
Exerciseڕاهێنان3. Plus and minus٣. کۆ و کەم

Build a counter with an outlined − icon button, the number, and a filled + icon button. The − button must be disabled at 0, so the number never becomes negative. Give both buttons tooltips.

دروست بکە بە IconButtonـی هێڵداری −، ژمارەکە و IconButtonـی پڕی +. − دەبێت لە 0دا ناچالاک بێت، بۆ ئەوەی ژمارەکە هەرگیز نەبێتە سالب. tooltip بدە بە هەردوو .

Show answerوەڵامەکە پیشان بدە
One possible answerوەڵامێکی گونجاوDARTRuns on a phone (or an emulator)لەسەر مۆبایل کار دەکات
import 'package:flutter/material.dart';

class GlassCounter extends StatefulWidget {
  const GlassCounter({super.key});

  @override
  State<GlassCounter> createState() => _GlassCounterState();
}

class _GlassCounterState extends State<GlassCounter> {
  int _count = 0;

  @override
  Widget build(BuildContext context) {
    return Row(
      mainAxisSize: MainAxisSize.min,
      children: [
        IconButton.outlined(
          tooltip: 'One less',
          icon: const Icon(Icons.remove),
          // disabled at 0: the count can never become negative
          onPressed: _count == 0 ? null : () => setState(() => _count--),
        ),
        Padding(
          padding: const EdgeInsets.symmetric(horizontal: 16),
          child: Text('$_count', style: const TextStyle(fontSize: 24)),
        ),
        IconButton.filled(
          tooltip: 'One more',
          icon: const Icon(Icons.add),
          onPressed: () => setState(() => _count++),
        ),
      ],
    );
  }
}
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 22

null at 0 → disabled: the rule is in the button itself.

null لە 0دا ← ناچالاک: یاساکە لە خودی .

Exerciseڕاهێنان4. An order row٤. ڕیزێکی داواکاری

Combine three kinds of buttons: a SegmentedButton for Small / Medium / Large, a DropdownMenu for the city, and a FilledButton Order that stays disabled until a city is chosen and then shows a snackbar such as medium tea to Erbil.

سێ جۆری تێکەڵ بکە: SegmentedButtonـێک بۆ ⁦Small / Medium / Large⁩، DropdownMenuـێک بۆ شار و FilledButtonـی Order کە تا شارێک هەڵنەبژێردرێت ناچالاک دەمێنێتەوە و پاشان پیشان دەدات وەک ⁦medium tea to Erbil⁩.

Show answerوەڵامەکە پیشان بدە
One possible answerوەڵامێکی گونجاوDARTRuns on a phone (or an emulator)لەسەر مۆبایل کار دەکات
import 'package:flutter/material.dart';

enum TeaSize { small, medium, large }

class OrderRow extends StatefulWidget {
  const OrderRow({super.key});

  @override
  State<OrderRow> createState() => _OrderRowState();
}

class _OrderRowState extends State<OrderRow> {
  TeaSize _size = TeaSize.medium;
  String? _city; // null until the user chooses

  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisSize: MainAxisSize.min,
      children: [
        SegmentedButton<TeaSize>(
          segments: const [
            ButtonSegment(value: TeaSize.small, label: Text('Small')),
            ButtonSegment(value: TeaSize.medium, label: Text('Medium')),
            ButtonSegment(value: TeaSize.large, label: Text('Large')),
          ],
          selected: {_size},
          onSelectionChanged: (s) => setState(() => _size = s.first),
        ),
        const SizedBox(height: 16),
        DropdownMenu<String>(
          label: const Text('City'),
          dropdownMenuEntries: const [
            DropdownMenuEntry(value: 'Erbil', label: 'Erbil'),
            DropdownMenuEntry(value: 'Duhok', label: 'Duhok'),
            DropdownMenuEntry(value: 'Halabja', label: 'Halabja'),
          ],
          onSelected: (value) => setState(() => _city = value),
        ),
        const SizedBox(height: 16),
        FilledButton(
          // only possible once a city is chosen
          onPressed: _city == null
              ? null
              : () => ScaffoldMessenger.of(context).showSnackBar(
                    SnackBar(content: Text('${_size.name} tea to $_city')),
                  ),
          child: const Text('Order'),
        ),
      ],
    );
  }
}
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 14

Nullable: no city at the start.

Nullable: لە سەرەتادا هیچ شارێک نییە.

Lineدێڕی 43

The order button follows the state.

داواکاری شوێن دەکەوێت.

Lineدێڕی 46

.name gives an enum value's name: medium.

.name ناوی بەهایەکی enum دەدات: medium.

Exerciseڕاهێنان5. Find the bug٥. هەڵەکە بدۆزەرەوە

A student writes FilledButton(onPressed: addGlass(), child: Text('Add')), where addGlass is a void function. The app does not compile: the analyzer says This expression has a type of 'void' so its value can't be used. Explain the mistake and fix it.

قوتابییەک دەنووسێت FilledButton(onPressed: addGlass(), child: Text('Add'))، کە addGlass voidـە. کۆمپایل نابێت: analyzer دەڵێت ⁦This expression has a type of 'void' so its value can't be used⁩. هەڵەکە ڕوون بکەرەوە و چاکی بکە.

Hintئاماژە

Look at the brackets after addGlass. See Pass it, do not call it.

سەیری کەوانەکانی دوای addGlass بکە. سەیری بینێرە، بانگی مەکە بکە.

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

addGlass() with brackets calls the function while the button is being built and hands its result to onPressed. That result is void — nothing — but onPressed expects a function, so Dart refuses to compile. (If it did compile, the glass would be added on every build instead of on a tap.) Write onPressed: addGlass (the function itself, no brackets) or onPressed: () => addGlass().

addGlass() بە کەوانەوە لە کاتی دروستکردنی بانگ دەکات و ئەنجامەکەی دەدات بە onPressed. ئەو ئەنجامە voidـە — هیچ نییە — بەڵام onPressed چاوەڕێی دەکات، بۆیە Dart کۆمپایلی ناکات. (ئەگەر کۆمپایل ببوایە، لە هەموو buildـێکدا پەرداخێک زیاد دەکرا نەک بە دەستلێدان.) بنووسە onPressed: addGlass (خودی ، بێ کەوانە) یان onPressed: () => addGlass().

Quick checkپشکنینی خێراWhich widget replaces the old ToggleButtons in Material 3?کام لە ⁦Material 3⁩ـدا جێگەی ToggleButtonsـی کۆن دەگرێتەوە؟

Summaryپوختە

  • A button shows a child and runs its onPressed callback; onPressed: null disables it.
  • Removed: FlatButton, RaisedButton, OutlineButton → TextButton, ElevatedButton, OutlinedButton. New in Material 3: FilledButton (+ tonal), SegmentedButton, IconButton.filled/filledTonal/outlined.
  • Choose by importance: Filled > tonal > Elevated > Outlined > Text; one filled button per screen; one FAB for the main action.
  • Style with styleFrom (backgroundColor, foregroundColor, padding, minimumSize, shape, textStyle…), per state with ButtonStyle + WidgetStateProperty, app-wide with button themes.
  • InkWell makes any widget tappable with a ripple (needs a Material ancestor); DropdownMenu keeps a chosen value; PopupMenuButton offers actions.
  • childـێک پیشان دەدات و onPressedـەکەی ڕادەکات؛ onPressed: null ناچالاکی دەکات.
  • لابراو: FlatButton، RaisedButton، OutlineButton ← TextButton، ElevatedButton، OutlinedButton. نوێ لە ⁦Material 3⁩ـدا: ⁦FilledButton (+ tonal)⁩، SegmentedButton، ⁦IconButton.filled/filledTonal/outlined⁩.
  • بە گوێرەی گرنگی هەڵبژێرە: ⁦Filled > tonal > Elevated > Outlined > Text⁩؛ لە هەر شاشەیەکدا یەک filled؛ یەک FAB بۆ کردەوە سەرەکییەکە.
  • شێواز بدە بە styleFrom (backgroundColor، foregroundColor، padding، minimumSize، shape، textStyle…)، بۆ هەر دۆخێک بە ButtonStyle + WidgetStateProperty، بۆ هەموو بە .
  • InkWell هەر بە شەپۆلەوە دەکات بە دەستلێدراو (پێویستی بە Materialـێکی باوان هەیە)؛ DropdownMenu بەهایەکی هەڵبژێردراو هەڵدەگرێت؛ PopupMenuButton چەند کردەوەیەک پێشکەش دەکات.
Review questionsپرسیارەکانی پێداچوونەوە
What is the difference between onPressed: null and onPressed: () {}?جیاوازیی نێوان onPressed: null و onPressed: () {} چییە؟

null disables the button (grey, no ripple). An empty function keeps it enabled, so it looks clickable but does nothing.

null ناچالاک دەکات (خۆڵەمێشی، بێ شەپۆل). بەتاڵ چالاکی دەهێڵێتەوە، بۆیە وەک دەستلێدراو دەردەکەوێت بەڵام هیچ ناکات.

Which properties replace FlatButton's color and textColor?لە جیاتی color و textColorـی FlatButton چی دەنووسیت؟

backgroundColor and foregroundColor in TextButton.styleFrom(...).

backgroundColor و foregroundColor لە TextButton.styleFrom(...)ـدا.

When do you need WidgetStateProperty.resolveWith?کەی پێویستت بە WidgetStateProperty.resolveWith هەیە؟

When a property must change with the button's state, for example a different colour while pressed or disabled.

کاتێک دەبێت لەگەڵ دۆخی بگۆڕێت، بۆ نموونە ڕەنگێکی جیاواز کاتێک داگیراوە یان ناچالاکە.

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

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

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

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

Text Fields and Formsخانەکانی دەق و فۆرمەکان

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

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