💻 Programming

Dart

Google's programming language used for Flutter development

📖 Detailed Explanation

Dart is an object-oriented programming language announced by Google in 2011. It was originally created to replace JavaScript in web development, but with the arrival of the Flutter framework in 2017 it became the core language for cross-platform mobile app development.

Dart supports both AOT (Ahead-of-Time) compilation and JIT (Just-in-Time) compilation. During development, JIT compilation enables the Hot Reload feature so you can see code changes immediately, and at deployment, AOT compilation achieves native-level performance.

Dart's key features are a strong type system, null safety, async/await asynchronous programming, and a rich standard library. In particular, sound null safety, introduced in Dart 2.12, prevents null reference errors at compile time and greatly reduces runtime crashes.

In practice, Dart is mainly used with Flutter to develop iOS, Android, web, and desktop apps from a single codebase. Global companies such as BMW, Alibaba, and Google Pay build apps with Flutter/Dart, and as of 2025 Flutter is one of the most popular cross-platform frameworks.

💻 Code Example

// 1. 기본 문법과 null safety
void main() {
  // null safety - ? 없이 선언하면 null 불가
  String name = 'KAITRUST';
  String? nickname; // nullable 타입

  print('이름: $name');
  print('별명 길이: ${nickname?.length ?? 0}'); // null-aware 연산자
}

// 2. 클래스와 named parameters
class User {
  final String id;
  final String name;
  final int age;

  // named parameters with required
  User({
    required this.id,
    required this.name,
    this.age = 0,
  });

  // factory constructor
  factory User.fromJson(Map<String, dynamic> json) {
    return User(
      id: json['id'] as String,
      name: json['name'] as String,
      age: json['age'] as int? ?? 0,
    );
  }

  @override
  String toString() => 'User(id: $id, name: $name, age: $age)';
}

// 3. 비동기 프로그래밍 (async/await)
Future<List<User>> fetchUsers() async {
  try {
    // 네트워크 요청 시뮬레이션
    await Future.delayed(Duration(seconds: 1));

    final jsonList = [
      {'id': '1', 'name': '홍길동', 'age': 25},
      {'id': '2', 'name': '김철수', 'age': 30},
    ];

    return jsonList.map((json) => User.fromJson(json)).toList();
  } catch (e) {
    print('에러 발생: $e');
    rethrow;
  }
}

// 4. 컬렉션과 함수형 프로그래밍
void processData() {
  final numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

  final result = numbers
      .where((n) => n % 2 == 0)     // 짝수 필터링
      .map((n) => n * n)            // 제곱
      .reduce((a, b) => a + b);     // 합계

  print('짝수 제곱의 합: $result'); // 220
}

🗣️ Say It Like This in Practice

💬 In a Meeting
"We plan to build this project with Flutter. Thanks to Dart's hot reload, UI development is fast, and since one codebase supports both iOS and Android, we can cut development resources by more than 50%."
💬 In an Interview
"Dart's null safety catches null reference errors at compile time. Nullable types are marked with ?, and required parameters are declared with the required keyword. This fundamentally prevents runtime NullPointerExceptions."
💬 In a code review
"This variable can never be null, so declare it as String instead of String?. Unnecessary nullable types force a null check every time, which makes the code more complicated. Consider the late keyword too."

Take a mock interview on this topic → WIA SOOM AI Interview · Start for free

⚠️ Common Mistakes & Cautions

❌
Don't overuse the ! operator

Force-unwrapping with the `!` operator throws away the benefits of null safety. Where possible, handle it safely with `?.` or `??`, and use `!` only when you are truly sure it is not null.

❌
Be careful with async work in setState()

In Flutter, putting `await` inside `setState()` can cause a state update to occur after the widget has been disposed. Check `mounted`, or call `setState()` after the asynchronous work.

✅
Use const constructors

For immutable objects, using a `const` constructor creates the object at compile time, improving memory efficiency and performance. This is especially important for Flutter widgets.

🔗 Related Terms

📚 Learn More