how to declare list in dart code example

Example 1: declaring and initializing a list in dart

import 'dart:core';

void main() {

  //List of integers
  List<int> intArr = [1,2,3,4,5];
  print(intArr);
  
  //List of strings
  List<String> strArr = ['hello', 'world'];
  print(strArr);  
  
}

Example 2: get single element from list in dart

var firstList = [1,2,3,4,5,6]; print(firstList.firstWhere((i) => i < 4)); // 1  var sList = ['one', 'two', 'three', 'four']; print(sList.firstWhere((i) => i.length > 3)); // three

Tags:

Dart Example