Want to Contribute to us or want to have 15k+ Audience read your Article ? Or Just want to make a strong Backlink?

Dart/Flutter Liste Methodlar─▒ ­čĺź ­čîî ÔťĘ



Liste Methodlar─▒ ÔťĘ

add methodology
Parametre olarak verilen eleman─▒ listenin sonuna ekler.

├ľrnek uygulama:

ultimate numbers = <int>[1, 2, 3];
numbers.add(4);
print(numbers); // [1, 2, 3, 4]
Enter fullscreen mode

Exit fullscreen mode

addAll methodology
Parametre olarak verilen listeyi listenin sonuna ekler.

├ľrnek uygulama:

ultimate numbers = <int>[1, 2, 3];
numbers.addAll([4, 5, 6]);
print(numbers); // [1, 2, 3, 4, 5, 6]
Enter fullscreen mode

Exit fullscreen mode

any methodology

Verilen ko┼čulu listedeki her eleman i├žin dener. E─čer bir eleman ko┼čulu sa─člarsa geriye true d├Ând├╝r├╝r. Hi├žbir eleman ko┼čulu sa─člamaz ise geriye false d├Âner.

├ľrnek uygulama:

ultimate numbers = <int>[1, 2, 3, 5, 6, 7];
var outcome = numbers.any((component) => component >= 5); // true;
outcome = numbers.any((component) => component >= 10); // false;
Enter fullscreen mode

Exit fullscreen mode

asMap methodology
Bir listenin key ve worth de─čerlerine eri┼čmeyi sa─člar.

├ľrnek uygulama:

var phrases = <String>['fee', 'fi', 'fo', 'fum'];
var map = phrases.asMap(); 
print(map);// {0: price, 1: fi, 2: fo, 3: fum}
map.keys.toList(); 
print(map.keys.toList());// [0, 1, 2, 3]
print(map.values.toList());// [fee, fi, fo, fum]

Enter fullscreen mode

Exit fullscreen mode

forged methodology
Bu listenin bir g├Âr├╝n├╝m├╝n├╝ R ├Ârnekler listesi olarak d├Ând├╝r├╝r.

  var foo = [1, 2.3]; 
  print(foo.runtimeType); // JSArray<num>
  var baz = foo.forged<num>();
  print(baz.runtimeType); // CastList<num, num>
  print(baz == foo); // false
Enter fullscreen mode

Exit fullscreen mode

clear methodology
Bir listedeki t├╝m elemanlar─▒ siler.

ultimate numbers = <int>[1, 2, 3];
numbers.clear();
print(numbers.size); // 0
print(numbers); // []
Enter fullscreen mode

Exit fullscreen mode

comprises methodology
Listenin parametre olarak verilen de─čeri i├žerip i├žermedi─čini kontrol eder.

ultimate gasPlanets = <int, String>{1: 'Jupiter', 2: 'Saturn'};
ultimate containsOne = gasPlanets.keys.comprises(1); // true
ultimate containsFive = gasPlanets.keys.comprises(5); // false
ultimate containsJupiter = gasPlanets.values.comprises('Jupiter'); // true
ultimate containsMercury = gasPlanets.values.comprises('Mercury'); // false
Enter fullscreen mode

Exit fullscreen mode

elementAt methodology
Parametre olarak verilen indexdeki eleman─▒ d├Ând├╝r├╝r. ─░ndex negatif olmamal─▒ ve listenin eleman say─▒s─▒ndan k├╝├ž├╝k olmal─▒d─▒r.
─░ndex 0 ilk eleman─▒ temsil eder.

├ľrnek uygulama:

ultimate numbers = <int>[1, 2, 3, 5, 6, 7];
ultimate elementAt = numbers.elementAt(4); // 6
Enter fullscreen mode

Exit fullscreen mode

each methodology

Listedeki her eleman i├žin verilen ko┼čulun sa─član─▒p sa─članmad─▒─č─▒n─▒ kontrol eder. Listedeki t├╝m elemanlar ko┼čulu sa─čl─▒yor ise true sa─člam─▒yor ise geriye false d├Âner.

├ľrnek uygulama:

ultimate planetsByMass = <double, String>{0.06: 'Mercury', 0.81: 'Venus',
  0.11: 'Mars'};
// Checks whether or not all keys are smaller than 1.
ultimate each = planetsByMass.keys.each((key) => key < 1.0); // true
Enter fullscreen mode

Exit fullscreen mode

broaden methodology
Bir iterable(yinelenebilir) ├Â─čenin her ├Â─česini s─▒f─▒r veya daha fazla ├Â─čeye geni┼čletir.

├ľrnek uygulama:

Iterable<int> depend(int n) sync* {
  for (var i = 1; i <= n; i++) {
    yield i;
   }
 }

var numbers = [1, 3, 0, 2];
print(numbers.broaden(depend)); // (1, 1, 2, 3, 1, 2)
Enter fullscreen mode

Exit fullscreen mode

firstWhere methodology

Liste elemanlar─▒ aras─▒nda ko┼čulu sa─člayan ilk eleman─▒ d├Ând├╝r├╝r.

ultimate numbers = <int>[1, 2, 3, 5, 6, 7];
var outcome = numbers.firstWhere((component) => component < 5); // 1
outcome = numbers.firstWhere((component) => component > 5); // 6
outcome =
    numbers.firstWhere((component) => component > 10, orElse: () => -1); // -1
Enter fullscreen mode

Exit fullscreen mode

Hi├žbir ├Â─če testi kar┼č─▒lamazsa, orElse fonksiyonunun sonucu d├Ând├╝r├╝l├╝r. orElse atlan─▒rsa, varsay─▒lan olarak bir StateError atar.

fold methodology

Listenin her bir ├Â─česini mevcut bir de─čerle yinelemeli olarak birle┼čtirerek listeyi tek bir de─čere indirger

Ba┼člang─▒├ž ÔÇőÔÇőde─čeri olarak initialValue ├Â─česini kullan─▒r, ard─▒ndan ├Â─čeler aras─▒nda yinelenir ve mix(birle┼čtirme) fonksiyonunu kullanarak de─čeri her ├Â─čeyle ┼ču ┼čekilde g├╝nceller:

var worth = initialValue;
for (E component on this) {
  worth = mix(worth, component);
}
return worth;
Enter fullscreen mode

Exit fullscreen mode

├ľrnek uygulama:

ultimate numbers = <double>[10, 2, 5, 0.5];
const initialValue = 100.0;
ultimate outcome = numbers.fold<double>(
    initialValue, (previousValue, component) => previousValue + component);
print(outcome); // 117.5
Enter fullscreen mode

Exit fullscreen mode

followedBy methodology
Bir listeyle parametre olarak verilmi┼č olan listenin birle┼čtirilmi┼č halini d├Ând├╝r├╝r.

├ľrnek uygulama:

var planets = <String>['Earth', 'Jupiter'];
var up to date = planets.followedBy(['Mars', 'Venus']);
print(up to date); // (Earth, Jupiter, Mars, Venus)
Enter fullscreen mode

Exit fullscreen mode

forEach methodology

ultimate numbers = <int>[1, 2, 6, 7];
numbers.forEach(print);
// 1
// 2
// 6
// 7
Enter fullscreen mode

Exit fullscreen mode

be part of methodology

Her ├Â─čeyi bir string’e d├Ân├╝┼čt├╝r├╝r ve bu string’leri birle┼čtirir.

├ľrnek uygulama:

ultimate planetsByMass = <double, String>{0.06: 'Mercury', 0.81: 'Venus',
  0.11: 'Mars'};
ultimate joinedNames = planetsByMass.values.be part of('-'); // Mercury-Venus-Mars
Enter fullscreen mode

Exit fullscreen mode

lastWhere methodology

Verilen ko┼čulu sa─člayan listenin son eleman─▒n─▒ verir.

├ľrnek uygulama:

ultimate numbers = <int>[1, 2, 3, 5, 6, 7];
var outcome = numbers.lastWhere((component) => component < 5); // 3
outcome = numbers.lastWhere((component) => component > 5); // 7
outcome = numbers.lastWhere((component) => component > 10,
    orElse: () => -1); // -1
Enter fullscreen mode

Exit fullscreen mode

Hi├žbir ├Â─če testi kar┼č─▒lamazsa, orElse i┼člevinin ├ža─čr─▒lmas─▒n─▒n sonucu d├Ând├╝r├╝l├╝r. orElse atlan─▒rsa, varsay─▒lan olarak bir StateError atar.

map methodology

├ľrnek uygulama:

var merchandise = jsonDecode('''
[
  {"name": "Screwdriver", "price": 42.00},
  {"name": "Wingnut", "price": 0.50}
]
''');
var values = merchandise.map((product) => product['price'] as double);
var totalPrice = values.fold(0.0, (a, b) => a + b); // 42.5.
Enter fullscreen mode

Exit fullscreen mode

assets:
https://api.flutter.dev/flutter/dart-core/Iterable-class.html#instance-methods
https://api.dart.dev/stable/2.16.1/dart-core/dart-core-library.html
https://www.codegrepper.com/code-examples/dart/cast+variable+flutter

Add a Comment

Your email address will not be published. Required fields are marked *

Want to Contribute to us or want to have 15k+ Audience read your Article ? Or Just want to make a strong Backlink?