Fahimtar Widgets a ciki Flutter

A cikin Flutter, Widgets su ne ainihin tubalan ginin don gina mahaɗin mai amfani na app. Kowane ra'ayi a cikin Flutter Widget ne. Akwai manyan nau'ikan guda biyu Widgets a cikin Flutter:

Stateless Widgets

Stateless Widgets su ne widgets wadanda ba su da wata jiha kuma ba sa canzawa bayan an halicce su. Lokacin da yanayin app ɗin ya canza, Stateless Widgets sake zana tare da sabbin ƙima amma kar a riƙe kowace jiha.

Stateful Widgets

Stateful Widgets suna widgets da jihar kuma suna iya canzawa yayin lokacin aiki. Lokacin da jihar ta canza, Stateful Widgets sake zana ta atomatik don nuna sabbin canje-canje.

Flutter yana ba da nau'ikan ginannun nau'ikan Widgets irin su Text, Image, RaisedButton, Container da ƙari masu yawa don gina haɗin mai amfani. Bugu da ƙari, zaku iya ƙirƙirar al'ada Widgets don dacewa da takamaiman buƙatun app.

Amfani Widgets da in Flutter

Don amfani Widgets a cikin Flutter, kawai kuna ƙirƙira Widgets da shirya su a cikin bishiyar Widget ɗin app. Flutter yana amfani da tsarin bishiyar widget don gina haɗin mai amfani. Kowane Widget zai iya ƙunsar yaro Widgets, yana samar da tsari mai matsayi.

Misali, don ƙirƙirar ƙa'ida mai sauƙi tare da maɓalli da wasu rubutu, zaku iya amfani da Widgets kamar haka:

import 'package:flutter/material.dart';  
  
void main() {  
  runApp(MyApp());  
}  
  
class MyApp extends StatelessWidget {  
  @override  
  Widget build(BuildContext context) {  
    return MaterialApp(  
      home: Scaffold(  
        appBar: AppBar(  
          title: Text('Flutter Widgets'),  
       ),  
        body: Center(  
          child: Column(  
            mainAxisAlignment: MainAxisAlignment.center,  
            children: [  
              RaisedButton(  
                onPressed:() {  
                  // Xử lý khi nút được nhấn  
                },  
                child: Text('Nhấn vào đây'),  
             ),  
              Text('Chào mừng đến với Flutter Widgets'),  
            ],  
         ),  
       ),  
     ),  
   );  
  }  
}  

A cikin misalin da ke sama, muna amfani da ginawa mai sauƙi. Kuna iya canza tsarin bishiyar Widget don ƙirƙirar ƙarin hadaddun mu'amalar mai amfani don app ɗinku. MaterialApp, Scaffold, Column, RaisedButton, Text Widgets interface Widgets

 

Kammalawa

Widgets su ne tushen tsarin mai amfani a cikin Flutter. Ta amfani da ginanniyar ciki Widgets da ƙirƙirar al'ada Widgets, zaku iya gina ƙa'idodi daban-daban da jan hankali a cikin Flutter.