Thuta Learning
ရှာဖွေရန်
BasicProgrammingbeginner

Collections (Maps)

စိတ်လျှော့ပါ။ ဒီခန်းကို စာအုပ်လိုမဟုတ်ဘဲ စကားပြောသလိုပဲ၊ နားလည်လွယ်အောင် ရှင်းပါမယ်။

Map သည် key-value pairs သိမ်းရန်သုံးပါတယ်။ User profile, product data, API response, settings data တွေကို model မလုပ်ခင် အခြေခံနားလည်ဖို့အရေးကြီးပါတယ်။

dart
void main() {
  Map<String, dynamic> user = {
    'name': 'Sai',
    'role': 'Developer',
    'points': 120,
    'isActive': true,
  };

  print(user['name']);
  print(user['points']);

  user['points'] = 150;
  print('Updated points: ${user['points']}');
}

String key နဲ့ value ကိုသိမ်းထားတာပါ။ dynamic သုံးထားလို့ value က String, int, bool စသဖြင့် မတူနိုင်ပါတယ်။ User data တွေမှာ field type မတူတာများတဲ့အတွက် ဒီပုံစံကိုတွေ့ရတတ်ပါတယ်။

You should see
Sai 120 Updated points: 150

ဒီနေရာမှာ လူအများမှားတတ်တယ်

  • မရှိတဲ့ key ကိုခေါ်ရင် null ပြန်ရနိုင်ပါတယ်။ အရေးကြီးတဲ့ data ဆိုရင် key ရှိ/မရှိ စစ်ပြီးမှသုံးပါ။
Collections (Maps) | Thuta Learning