What is printed?
add() adds one element to the list, making length 4.
Work with collections of data
Passing the Quiz & Exercises is mandatory to earn FX and proceed. If you fail, try again to gain the required FX, then the Proceed button will become available.
You can read this lesson publicly. Sign in to unlock exercises, quiz, and FX progress tracking.
Having trouble? AI is here to help
Ask context-aware questions about this lesson. Free plan: 5 questions/day. Upgrade to Premium for higher daily limits.
Use the AI button at the bottom of the screen
Lists are ordered collections of items, similar to arrays in other programming languages. They are one of the most commonly used data structures in Dart and Flutter.
1// Creating lists2var fruits = ['apple', 'banana', 'orange'];3List<String> vegetables = ['carrot', 'broccoli'];45// Accessing elements6print(fruits[0]); // apple7print(fruits.first); // apple8print(fruits.last); // orange910// Modifying11fruits.add('mango');12fruits.remove('banana');13fruits.insert(1, 'grape');1415// List properties16print(fruits.length); // 417print(fruits.isEmpty); // false
1var numbers = [1, 2, 3, 4, 5];23// map - transform each element4var doubled = numbers.map((n) => n * 2).toList();5// [2, 4, 6, 8, 10]67// where - filter elements8var evens = numbers.where((n) => n % 2 == 0).toList();9// [2, 4]1011// any / every - check conditions12numbers.any((n) => n > 3); // true13numbers.every((n) => n > 0); // true1415// Spread operator16var more = [0, ...numbers, 6]; // [0, 1, 2, 3, 4, 5, 6]
Maps store data as key-value pairs, similar to dictionaries in Python or objects in JavaScript. They are useful for representing structured data like user profiles or API responses.
1// Creating maps2var user = {3'name': 'John',4'age': 25,5'email': 'john@example.com'6};78Map<String, dynamic> product = {9'id': 1,10'title': 'Phone',11'price': 999.9912};1314// Accessing values15print(user['name']); // John1617// Adding/updating18user['role'] = 'admin'; // Add new19user['age'] = 26; // Update2021// Checking keys22user.containsKey('name'); // true23user.keys; // (name, age, email, role)24user.values; // (John, 26, john@example.com, admin)
JSON from APIs becomes `Map<String, dynamic>`. You will use maps constantly when working with data.
Use the right structure for the job:
In production apps, raw map usage should be short-lived. Convert map data into typed model classes quickly to reduce runtime errors and improve autocomplete support.
Work with collections of data. Dart is the language behind Flutter, and clear Dart code makes your Flutter UI easier to maintain.
Build confidence with basics first; speed comes later.
Prefer readable names, explicit intent, and async/await over deeply nested callbacks.
When Dart basics are weak, state bugs, null crashes, and async confusion increase quickly.
add() adds one element to the list, making length 4.
map() transforms each element. n * 2 doubles each number.
Use square brackets with the key to access map values.
Spread (...) unpacks all elements of a list into another list.
Something seems incorrect, unclear, or missing? Let us know.
FlutterCraft editorial lessons are reviewed by experienced Flutter developers and updated to stay aligned with modern Flutter and Dart best practices.
Reference docs: Flutter Documentation, Dart Language Tour, and official package documentation where relevant.
Sign in to continue with exercises and quiz for this lesson.
Sign In to Continue