You’ll start with simple fundamentals like variables, functions, and null safety, then work your way up to classes, collections, async programming with futures and streams, and practical patterns you’ll use in every Flutter project. Every problem is written in plain, simple language so you can try it yourself first, then check the solution and truly understand the why behind the code.
Why is hands-on practice so important? Because app development is built on problem-solving muscle memory. Every challenge you solve sharpens your logic, makes common patterns feel automatic, and builds the kind of deep, confident ability that tutorials alone can’t give you. Whether you’re just starting your Flutter journey or preparing for a dart-focused interview, these exercises will help you feel ready, capable, and genuinely proud of your progress. Pick a problem, start coding, and experience that amazing “I’m really getting this!” moment. Your Dart mastery starts today.
Also try it: 100 Java practice problems with solutions
1. Write a Dart program that prints “Hello, World!” to the console.
dart
void main() {
print('Hello, World!');
}
2. Declare two integer variables, assign them values, and print their sum.
dart
void main() {
int a = 10;
int b = 20;
print('Sum: ${a + b}');
}
3. Write a function that returns the factorial of a number using recursion.
dart
int factorial(int n) {
if (n <= 1) return 1;
return n * factorial(n - 1);
}
void main() {
print(factorial(5)); // 120
}
4. Write a program that prints the Fibonacci series up to n terms (n=10).
dart
void main() {
int n = 10;
int a = 0, b = 1;
for (int i = 0; i < n; i++) {
print(a);
int next = a + b;
a = b;
b = next;
}
}
5. Write a program to check if a given number is even or odd.
dart
void main() {
int num = 7;
if (num % 2 == 0) {
print('$num is even');
} else {
print('$num is odd');
}
}
6. Create a list of integers and print each element using a for loop.
dart
void main() {
List<int> numbers = [1, 2, 3, 4, 5];
for (int n in numbers) {
print(n);
}
}
7. Write a function that takes a list of numbers and returns the largest.
dart
int findLargest(List<int> nums) {
int max = nums[0];
for (int n in nums) {
if (n > max) max = n;
}
return max;
}
void main() {
print(findLargest([3, 7, 1, 9, 4]));
}
8. Write a program to reverse a string.
dart
void main() {
String str = "Hello";
String reversed = str.split('').reversed.join();
print(reversed); // olleH
}
9. Check if a string is a palindrome.
dart
bool isPalindrome(String s) {
String reversed = s.split('').reversed.join();
return s == reversed;
}
void main() {
print(isPalindrome('radar')); // true
}
10. Count the number of vowels in a string.
dart
int countVowels(String s) {
int count = 0;
for (int i = 0; i < s.length; i++) {
if ('aeiouAEIOU'.contains(s[i])) count++;
}
return count;
}
void main() {
print(countVowels('Hello World')); // 3
}
11. Write a function that returns the sum of all elements in a list using a loop.
dart
int sumList(List<int> nums) {
int sum = 0;
for (int n in nums) sum += n;
return sum;
}
void main() {
print(sumList([2, 4, 6, 8])); // 20
}
12. Write a program to find the second largest number in a list.
dart
int secondLargest(List<int> nums) {
List<int> sorted = List.from(nums)..sort();
return sorted[sorted.length - 2];
}
void main() {
print(secondLargest([10, 20, 4, 45, 99])); // 45
}
13. Create a map with names as keys and ages as values, then print all key‑value pairs.
dart
void main() {
Map<String, int> ages = {'Alice': 25, 'Bob': 30};
ages.forEach((name, age) => print('$name: $age'));
}
14. Write a function that returns the number of words in a sentence.
dart
int wordCount(String sentence) {
return sentence.trim().split(RegExp(r'\s+')).length;
}
void main() {
print(wordCount('The quick brown fox')); // 4
}
15. Use a for loop to print numbers from 1 to 10 in reverse order.
dart
void main() {
for (int i = 10; i >= 1; i--) {
print(i);
}
}
16. Write a program that removes duplicate elements from a list.
dart
void main() {
List<int> nums = [1, 2, 2, 3, 4, 4, 5];
List<int> unique = nums.toSet().toList();
print(unique); // [1,2,3,4,5]
}
17. Sort a list of strings alphabetically.
dart
void main() {
List<String> fruits = ['banana', 'apple', 'cherry'];
fruits.sort();
print(fruits); // [apple, banana, cherry]
}
18. Write a program that uses a while loop to print numbers from 5 down to 1.
dart
void main() {
int i = 5;
while (i >= 1) {
print(i);
i--;
}
}
19. Create a class Rectangle with fields width and height, and a method to compute area.
dart
class Rectangle {
double width, height;
Rectangle(this.width, this.height);
double area() => width * height;
}
void main() {
Rectangle r = Rectangle(5, 3);
print('Area: ${r.area()}');
}
20. Write a program that demonstrates inheritance: base class Animal and derived class Dog.
dart
class Animal {
void sound() => print('Animal makes sound');
}
class Dog extends Animal {
@override
void sound() => print('Dog barks');
}
void main() {
Dog d = Dog();
d.sound();
}
21. Define an abstract class Shape with a method area(), and implement it in Circle.
dart
import 'dart:math';
abstract class Shape {
double area();
}
class Circle implements Shape {
double radius;
Circle(this.radius);
@override
double area() => pi * radius * radius;
}
void main() {
Circle c = Circle(5);
print('Area: ${c.area()}');
}
22. Use a try‑catch block to handle division by zero.
dart
void main() {
try {
int result = 10 ~/ 0;
} catch (e) {
print('Cannot divide by zero!');
}
}
23. Write a function that uses a lambda expression to square a number.
dart
void main() {
var square = (int x) => x * x;
print(square(5)); // 25
}
24. Create a list of numbers and use map to square each element.
dart
void main() {
List<int> nums = [1, 2, 3, 4];
List<int> squares = nums.map((n) => n * n).toList();
print(squares); // [1,4,9,16]
}
25. Use where to filter a list for even numbers.
dart
void main() {
List<int> nums = [1, 2, 3, 4, 5, 6];
List<int> evens = nums.where((n) => n % 2 == 0).toList();
print(evens); // [2,4,6]
}
26. Write a function that merges two maps (sum values for common keys).
dart
Map<String, int> mergeMaps(Map<String, int> a, Map<String, int> b) {
Map<String, int> result = Map.from(a);
b.forEach((key, value) {
result.update(key, (v) => v + value, ifAbsent: () => value);
});
return result;
}
void main() {
var m1 = {'a': 1, 'b': 2};
var m2 = {'b': 3, 'c': 4};
print(mergeMaps(m1, m2)); // {a:1, b:5, c:4}
}
27. Use a switch statement to print the name of a month given its number.
dart
void main() {
int month = 3;
switch (month) {
case 1: print('January'); break;
case 2: print('February'); break;
case 3: print('March'); break;
default: print('Invalid');
}
}
28. Write a program that reads a string from the user (simulate with variable) and prints its length.
dart
import 'dart:io';
void main() {
print('Enter a string:');
String? line = stdin.readLineSync();
print('Length: ${line?.length ?? 0}');
}
29. Use a do‑while loop to print numbers from 1 to 5.
dart
void main() {
int i = 1;
do {
print(i);
i++;
} while (i <= 5);
}
30. Write a program that finds all prime numbers between 1 and 50.
dart
bool isPrime(int n) {
if (n < 2) return false;
for (int i = 2; i <= n ~/ i; i++) {
if (n % i == 0) return false;
}
return true;
}
void main() {
for (int i = 2; i <= 50; i++) {
if (isPrime(i)) print(i);
}
}
31. Create a list of 10 random integers between 1 and 100 and print the average.
dart
import 'dart:math';
void main() {
Random r = Random();
List<int> nums = List.generate(10, (_) => r.nextInt(100) + 1);
double avg = nums.reduce((a, b) => a + b) / nums.length;
print('Average: $avg');
}
32. Write a program to rotate a list to the left by k positions (k=2).
dart
List<int> rotateLeft(List<int> list, int k) {
k = k % list.length;
return [...list.sublist(k), ...list.sublist(0, k)];
}
void main() {
print(rotateLeft([1,2,3,4,5], 2)); // [3,4,5,1,2]
}
33. Write a function that checks if two strings are anagrams.
dart
bool areAnagrams(String s1, String s2) {
var list1 = s1.split('')..sort();
var list2 = s2.split('')..sort();
return list1.join() == list2.join();
}
void main() {
print(areAnagrams('listen', 'silent')); // true
}
34. Use a Future to delay printing a message by 2 seconds.
dart
Future<void> delayedPrint() async {
await Future.delayed(Duration(seconds: 2));
print('Hello after delay');
}
void main() async {
await delayedPrint();
}
35. Write a program that uses async* to generate a stream of Fibonacci numbers.
dart
Stream<int> fibonacciStream(int count) async* {
int a = 0, b = 1;
for (int i = 0; i < count; i++) {
yield a;
int next = a + b;
a = b;
b = next;
}
}
void main() async {
await for (int n in fibonacciStream(10)) {
print(n);
}
}
36. Write a function that returns the greatest common divisor (GCD) of two numbers.
dart
int gcd(int a, int b) {
while (b != 0) {
int t = b;
b = a % b;
a = t;
}
return a;
}
void main() {
print(gcd(48, 18)); // 6
}
37. Write a program that converts a binary string to an integer.
dart
void main() {
String binary = '1010';
int decimal = int.parse(binary, radix: 2);
print(decimal); // 10
}
38. Write a program that uses a record (tuple) to return two values from a function.
dart
(int, int) swap(int a, int b) {
return (b, a);
}
void main() {
var (x, y) = swap(5, 10);
print('x=$x, y=$y'); // x=10, y=5
}
39. Write a program that uses extension to add a isEven property to integers.
dart
extension on int {
bool get isEven => this % 2 == 0;
}
void main() {
print(4.isEven); // true
}
40. Write a generic function that swaps two elements in a list.
dart
void swapElements<T>(List<T> list, int i, int j) {
T temp = list[i];
list[i] = list[j];
list[j] = temp;
}
void main() {
List<int> nums = [1, 2, 3];
swapElements(nums, 0, 2);
print(nums); // [3,2,1]
}
41. Create a Person class with name and age, and override toString().
dart
class Person {
String name;
int age;
Person(this.name, this.age);
@override
String toString() => '$name ($age)';
}
void main() {
print(Person('Alice', 30));
}
42. Use a constructor with initializer list to validate age.
dart
class Person {
String name;
int age;
Person(this.name, this.age) : assert(age >= 0, 'Age cannot be negative');
}
void main() {
Person p = Person('Bob', 25);
print(p.name);
}
43. Write a program that uses factory constructor to return a cached instance.
dart
class Singleton {
static final Singleton _instance = Singleton._internal();
factory Singleton() => _instance;
Singleton._internal();
}
void main() {
var s1 = Singleton();
var s2 = Singleton();
print(identical(s1, s2)); // true
}
44. Use late keyword to initialize a variable after declaration.
dart
class Example {
late String message;
void setMessage(String m) => message = m;
}
void main() {
Example e = Example();
e.setMessage('Hello');
print(e.message);
}
45. Write a program that uses const constructor to create compile‑time constants.
dart
class Point {
final int x, y;
const Point(this.x, this.y);
}
void main() {
const p1 = Point(1, 2);
const p2 = Point(1, 2);
print(identical(p1, p2)); // true (same instance)
}
46. Use enums to represent days of the week and print a day.
dart
enum Day { monday, tuesday, wednesday, thursday, friday, saturday, sunday }
void main() {
Day today = Day.friday;
print(today); // Day.friday
}
Also try it: 100 kotlin practice problems with solutions
47. Write a program that throws a custom exception.
dart
class NegativeNumberException implements Exception {}
void checkPositive(int n) {
if (n < 0) throw NegativeNumberException();
}
void main() {
try {
checkPositive(-5);
} catch (e) {
print('Caught exception: $e');
}
}
48. Use List.generate to create a list of 5 zeros.
dart
void main() {
List<int> zeros = List.generate(5, (index) => 0);
print(zeros); // [0,0,0,0,0]
}
49. Write a program that uses reduce to find the product of all list elements.
dart
void main() {
List<int> nums = [2, 3, 4];
int product = nums.reduce((a, b) => a * b);
print(product); // 24
}
50. Use fold to concatenate a list of strings with a separator.
dart
void main() {
List<String> words = ['apple', 'banana', 'cherry'];
String result = words.fold('', (prev, word) => prev.isEmpty ? word : '$prev, $word');
print(result); // apple, banana, cherry
}
51. Write a program that reads a JSON string (Map) and parses it using dart:convert.
dart
import 'dart:convert';
void main() {
String jsonStr = '{"name":"John","age":30}';
Map<String, dynamic> json = jsonDecode(jsonStr);
print(json['name']); // John
}
52. Use DateTime to print the current date and time.
dart
void main() {
DateTime now = DateTime.now();
print(now);
}
53. Calculate the number of days between two dates.
dart
void main() {
DateTime start = DateTime(2024, 1, 1);
DateTime end = DateTime(2024, 12, 31);
int days = end.difference(start).inDays;
print(days); // 365
}
54. Write a program that uses Stream.periodic to emit numbers every second for 5 seconds.
dart
import 'dart:async';
void main() {
Stream.periodic(Duration(seconds: 1), (count) => count)
.take(5)
.listen((num) => print(num));
}
55. Write a program that creates a future that completes with an error after delay.
dart
Future<void> failAfterDelay() async {
await Future.delayed(Duration(seconds: 1));
throw Exception('Something went wrong');
}
void main() async {
try {
await failAfterDelay();
} catch (e) {
print('Caught: $e');
}
}
56. Use StreamController to create a simple broadcast stream.
dart
import 'dart:async';
void main() {
StreamController<int> controller = StreamController.broadcast();
controller.stream.listen((x) => print('Listener1: $x'));
controller.stream.listen((x) => print('Listener2: $x'));
controller.add(42);
controller.close();
}
57. Write a program that uses Future.wait to run two futures in parallel.
dart
Future<String> fetchUser() async => 'Alice';
Future<int> fetchScore() async => 95;
void main() async {
var results = await Future.wait([fetchUser(), fetchScore()]);
print(results); // [Alice, 95]
}
58. Create a data class style class using freezed (simulate with plain class that overrides equality).
dart
class Point {
final int x, y;
Point(this.x, this.y);
@override
bool operator ==(Object other) =>
other is Point && x == other.x && y == other.y;
@override
int get hashCode => Object.hash(x, y);
}
void main() {
print(Point(1,2) == Point(1,2)); // true
}
59. Write a program that uses RegExp to validate an email address.
dart
bool isValidEmail(String email) {
RegExp regex = RegExp(r'^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$');
return regex.hasMatch(email);
}
void main() {
print(isValidEmail('test@example.com')); // true
}
60. Use StringBuffer to efficiently build a large string.
dart
void main() {
var sb = StringBuffer();
for (int i = 0; i < 5; i++) {
sb.write('$i ');
}
print(sb.toString()); // 0 1 2 3 4
}
61. Write a program that uses sync* to generate a range of numbers lazily.
dart
Iterable<int> range(int start, int end) sync* {
for (int i = start; i <= end; i++) {
yield i;
}
}
void main() {
print(range(1, 5).toList()); // [1,2,3,4,5]
}
62. Write a program that uses unawaited to ignore a future (import dart:async).
dart
import 'dart:async';
void main() {
Future.delayed(Duration(seconds: 1)).then((_) => print('Done'));
unawaited(Future.delayed(Duration(seconds: 2))); // ignore
}
63. Use Stream.fromIterable to create a stream from a list.
dart
import 'dart:async';
void main() {
Stream<int> stream = Stream.fromIterable([1,2,3]);
stream.listen(print);
}
64. Write a program that uses Future.sync to execute code synchronously.
dart
void main() {
Future.sync(() => print('This runs immediately'));
print('Then this');
}
65. Use [].addAll to merge two lists.
dart
void main() {
List<int> a = [1,2];
List<int> b = [3,4];
a.addAll(b);
print(a); // [1,2,3,4]
}
66. Create a Map from a list of pairs using Map.fromIterables.
dart
void main() {
List<String> keys = ['a', 'b'];
List<int> values = [1,2];
Map<String, int> map = Map.fromIterables(keys, values);
print(map); // {a:1, b:2}
}
67. Write a program that uses String.join() to create a comma‑separated string.
dart
void main() {
List<String> fruits = ['apple', 'banana', 'cherry'];
String result = fruits.join(', ');
print(result);
}
68. Use int.parse with onError fallback.
dart
void main() {
int value = int.parse('abc', onError: (source) => -1);
print(value); // -1
}
69. Write a program that uses double.tryParse to safely parse a string.
dart
void main() {
double? d = double.tryParse('3.14');
print(d); // 3.14
}
70. Use Uri.parse to split a URL into components.
dart
void main() {
var uri = Uri.parse('https://example.com/path?q=hello');
print(uri.scheme); // https
print(uri.host); // example.com
print(uri.path); // /path
print(uri.queryParameters['q']); // hello
}
71. Write a program that uses Set to find the intersection of two sets.
dart
void main() {
Set<int> set1 = {1,2,3};
Set<int> set2 = {3,4,5};
Set<int> intersection = set1.intersection(set2);
print(intersection); // {3}
}
72. Use Set.difference to find elements in first set not in second.
dart
void main() {
Set<int> set1 = {1,2,3};
Set<int> set2 = {3,4,5};
Set<int> diff = set1.difference(set2);
print(diff); // {1,2}
}
73. Write a program that uses Queue from dart:collection.
dart
import 'dart:collection';
void main() {
Queue<int> q = Queue();
q.addAll([1,2,3]);
print(q.removeFirst()); // 1
}
74. Use HashMap with custom equality (not common, but show).
dart
import 'dart:collection';
void main() {
var map = HashMap<int, String>();
map[1] = 'one';
print(map[1]); // one
}
75. Write a program that uses dart:io to write a file and read it back.
dart
import 'dart:io';
void main() async {
File file = File('test.txt');
await file.writeAsString('Hello Dart');
String content = await file.readAsString();
print(content); // Hello Dart
}
76. Use stdin to read a line asynchronously.
dart
import 'dart:io';
void main() async {
print('Enter your name:');
String? name = await stdin.first;
print('Hello, $name');
}
77. Write a program that uses Process.run to execute a system command (e.g., ls).
dart
import 'dart:io';
void main() async {
var result = await Process.run('ls', ['-la']);
print(result.stdout);
}
78. Use HttpServer to create a simple HTTP server (listen on port 8080).
dart
import 'dart:io';
void main() async {
var server = await HttpServer.bind(InternetAddress.anyIPv4, 8080);
await for (HttpRequest request in server) {
request.response.write('Hello');
await request.response.close();
}
}
79. Write a program that uses dart:math to compute the hypotenuse using sqrt.
dart
import 'dart:math';
void main() {
double a = 3, b = 4;
double c = sqrt(pow(a,2) + pow(b,2));
print(c); // 5.0
}
80. Use Point class from dart:math to represent a 2D point and compute distance.
dart
import 'dart:math';
void main() {
var p1 = Point(0,0);
var p2 = Point(3,4);
print(p1.distanceTo(p2)); // 5.0
}
81. Write a program that uses num type to handle both int and double.
dart
void main() {
num x = 10;
num y = 3.14;
print(x + y); // 13.14
}
Also try it: 100 Swift practice problems with solutions
82. Use identical to compare two objects for identity.
dart
void main() {
var a = [1];
var b = a;
var c = [1];
print(identical(a, b)); // true
print(identical(a, c)); // false
}
83. Write a program that uses mixin to add logging behavior to a class.
dart
mixin Logger {
void log(String msg) => print('LOG: $msg');
}
class Example with Logger {}
void main() {
Example e = Example();
e.log('Hello'); // LOG: Hello
}
84. Use typedef to create a function type alias.
dart
typedef IntOperation = int Function(int a, int b);
int add(int a, int b) => a + b;
void main() {
IntOperation op = add;
print(op(3, 5)); // 8
}
85. Write a program that uses isolate to run a computation in a separate isolate (simple).
dart
import 'dart:isolate';
void heavyComputation(SendPort port) {
port.send(42);
}
void main() async {
ReceivePort receivePort = ReceivePort();
await Isolate.spawn(heavyComputation, receivePort.sendPort);
int result = await receivePort.first;
print(result); // 42
}
86. Use Future.delayed with Duration.zero to schedule microtask.
dart
void main() {
Future.delayed(Duration.zero, () => print('Microtask-like'));
print('Immediate');
}
87. Use scheduleMicrotask to run a task after the current event loop.
dart
void main() {
scheduleMicrotask(() => print('Microtask'));
print('Main');
}
88. Write a program that uses Stopwatch to measure execution time.
dart
void main() {
Stopwatch stopwatch = Stopwatch()..start();
for (int i = 0; i < 1000000; i++) {}
stopwatch.stop();
print('Elapsed: ${stopwatch.elapsedMilliseconds} ms');
}
89. Use runZoned to capture unhandled errors.
dart
import 'dart:async';
void main() {
runZoned(() {
Future.error('Oops!');
}, onError: (error, stack) {
print('Caught: $error');
});
}
90. Write a program that uses Conditional imports (simulate with comments).
dart
// import 'web.dart' if (dart.library.html) 'html.dart';
void main() {
print('Conditional import concept');
}
91. Use @override annotation correctly in a subclass.
dart
class Parent {
void greet() => print('Hello');
}
class Child extends Parent {
@override
void greet() => print('Hi');
}
void main() {
Child().greet(); // Hi
}
92. Write a program that uses async and await with a StreamSubscription.
dart
import 'dart:async';
void main() async {
Stream<int> stream = Stream.periodic(Duration(seconds: 1), (i) => i).take(3);
await for (int value in stream) {
print(value);
}
}
93. Use Stream.firstWhere to find the first element meeting a condition.
dart
import 'dart:async';
void main() async {
Stream<int> stream = Stream.fromIterable([5, 10, 15]);
int result = await stream.firstWhere((x) => x > 7);
print(result); // 10
}
94. Write a program that uses Future.orElse (not directly; use catchError).
dart
Future<int> fetch() => Future.error('fail');
void main() {
fetch().catchError((e) => -1).then(print); // -1
}
95. Use Completer to create a future that can be completed manually.
dart
import 'dart:async';
void main() {
Completer<String> completer = Completer();
Future<String> future = completer.future;
completer.complete('Done');
future.then(print); // Done
}
96. Write a program that uses unawaited with Future in a non‑async function.
dart
import 'dart:async';
void main() {
unawaited(Future.delayed(Duration(seconds: 1), () => print('Delayed')));
print('Immediate');
}
97. Use Stream.empty to create an empty stream.
dart
import 'dart:async';
void main() {
Stream.empty().listen(print, onDone: () => print('Done')); // Done
}
98. Write a program that uses Stream.fromFutures to convert a list of futures.
dart
import 'dart:async';
void main() {
Stream<int> stream = Stream.fromFutures([Future.value(1), Future.value(2)]);
stream.listen(print); // 1,2
}
99. Use Timer to run a task after 1 second.
dart
import 'dart:async';
void main() {
Timer(Duration(seconds: 1), () => print('Delayed'));
}
100. Write a program that demonstrates the use of dart:developer for logging (simple).
dart
import 'dart:developer';
void main() {
log('This is a developer log message', name: 'MyApp');
print('Check your console');
}
Final Thought
And here you stand — 100 Dart problems completed, one thoughtful step at a time. You didn’t just skim code; you wrote it, debugged it, and quietly grew with every line. From simple variables to async streams, you’ve turned uncertainty into quiet capability.
Now, pause for a moment. Let these questions sit with you lightly:
- How did it feel when a problem finally clicked, and that flutter of “I did it!” rose in your chest?
- Do you remember the first problem that made you doubt yourself — and the quiet pride when you solved it anyway?
- If the you from a month ago could see you now, what would they say?
- What dream app will this hard‑earned confidence help you start tomorrow?
Growth like this isn’t loud — it’s the gentle kind that stays. Bookmark this page, return when doubt creeps back, and keep writing the code that brings your ideas to life. You’re already a Dart developer — and you’re only just beginning.