Ƙirƙirar da Nuna bayanai tare ListView da Flutter

A cikin Flutter, zaku iya ƙirƙira da nuna bayanai ta amfani da ListView. ListView Widget ne wanda ke ba ka damar ƙirƙirar jerin gungurawa mai ƙunshe da abubuwa kamar su ListTile Widgets na al'ada.

Anan ga jagora kan yadda ake ƙirƙira da nuna bayanai a cikin ListView:

Ƙirƙiri Jerin Bayanai

Da farko, kuna buƙatar ƙirƙirar jerin bayanan da kuke son nunawa a cikin ListView. Wannan jeri na iya zama jerin kirtani, abubuwa, ko kowane irin bayanan da kuke son nunawa.

Misali:

List<String> dataList = [  
  'Item 1',  
  'Item 2',  
  'Item 3',  
  'Item 4',  
  'Item 5',  
];  

Ƙirƙiri ListView kuma Nuna Bayanai

Na gaba, zaku iya ƙirƙira ListView da nuna bayanan ta amfani da ListView ginin ginin .builder. Wannan yana ba ku damar gina lissafin bisa ga adadin abubuwan da ke cikin jerin bayanai.

Misali:

ListView.builder(  
  itemCount: dataList.length,  
  itemBuilder:(BuildContext context, int index) {  
    return ListTile(  
      title: Text(dataList[index]),  
   );  
  },  
)  

A cikin misalin da ke sama, muna ƙirƙiri ListView mai ƙirga abu azaman adadin abubuwa a cikin lissafin bayanai. Kowane abu za a nuna shi a cikin mai ListTile tare da madaidaicin take.

Yin amfani ListView da List Custom

Bayan amfani da ListView.builder, Hakanan zaka iya amfani da ListView don nuna jerin abubuwan da aka saba ta hanyar samar da widgets na al'ada a cikin ListView.

Misali:

ListView(  
  children: dataList.map((item) => ListTile(title: Text(item))).toList(),  
)  

A cikin misalin da ke sama, muna amfani da hanyar taswira don musanya kowane abu a cikin lissafin bayanai zuwa ListTile maƙasudin take.

 

Ƙarshe:

ListView Widget ne mai ƙarfi Flutter wanda ke ba ka damar ƙirƙira da nuna jerin bayanai cikin sauƙi. Ta amfani da ListView, zaku iya nuna jerin abubuwa kamar yadda ake so kuma ku samar da ingantaccen ƙwarewar mai amfani a cikin app ɗin ku.