Files
2nd/10_Wiki/Topics/Frontend/Dart.md
T
2026-05-10 22:08:15 +09:00

5.0 KiB

id, title, category, status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, verification_status, tags, raw_sources, last_reinforced, github_commit, tech_stack
id title category status canonical_id aliases duplicate_of source_trust_level confidence_score verification_status tags raw_sources last_reinforced github_commit tech_stack
wiki-2026-0508-dart Dart 10_Wiki/Topics verified self
Dart language
dart-lang
none A 0.9 applied
dart
flutter
language
aot
jit
2026-05-10 pending
language framework
dart flutter

Dart

매 한 줄

"매 client-optimized language — JIT(dev) + AOT(prod) dual compile, sound null safety, isolate concurrency". 매 Google 의 Flutter 전용으로 설계 (2011→2018 pivot). 매 Dart 3.3+ (2024-2026) 의 records, patterns, sealed class 의 modern type system 도입.

매 핵심

매 dual compilation

  • JIT (development): 매 hot reload < 1s — Flutter dev 의 핵심.
  • AOT (production): 매 native machine code — startup 빠름, deterministic perf.
  • dart2js / dart2wasm: 매 web target — Flutter Web 의 binary.

매 sound null safety (since 2.12)

  • String? (nullable) vs String (non-null) 의 compile-time 보장.
  • late keyword — 매 deferred init.
  • ! (bang) — 매 명시적 unwrap.

매 Dart 3 의 modern features

  • Records: (int, String) lightweight tuple.
  • Patterns: destructuring + switch expression.
  • Sealed classes: 매 exhaustive matching.
  • Class modifiers: final, interface, base, sealed.

매 isolate concurrency

  • 매 single-threaded event loop per isolate.
  • 매 message-passing (no shared memory).
  • Isolate.run() (Dart 2.19+) 의 simple offload.

💻 패턴

Null safety + late

class User {
  final String name;
  final String? nickname; // nullable
  late final int age;     // deferred init

  User(this.name, {this.nickname});

  void setAge(int a) => age = a;
}

final u = User('Yuna');
print(u.nickname?.toUpperCase() ?? 'NO NICK');

Records (Dart 3)

(double, double) toPolar(double x, double y) =>
  (sqrt(x * x + y * y), atan2(y, x));

final (r, theta) = toPolar(3, 4);
print('r=$r, θ=$theta');

// Named record
({String name, int age}) profile = (name: 'Yuna', age: 28);
print(profile.name);

Patterns + switch expression

sealed class Shape {}
class Circle extends Shape { final double r; Circle(this.r); }
class Square extends Shape { final double s; Square(this.s); }

double area(Shape sh) => switch (sh) {
  Circle(:final r) => 3.14159 * r * r,
  Square(:final s) => s * s,
};

Async/await + Future

Future<User> fetchUser(int id) async {
  final res = await http.get(Uri.parse('https://api/u/$id'));
  if (res.statusCode != 200) throw Exception('fail');
  return User.fromJson(jsonDecode(res.body));
}

// Stream — 매 multiple async value
Stream<int> count(int n) async* {
  for (var i = 0; i < n; i++) {
    await Future.delayed(const Duration(seconds: 1));
    yield i;
  }
}

Isolate (compute)

import 'dart:isolate';

Future<int> heavyCompute(List<int> data) =>
  Isolate.run(() => data.fold(0, (a, b) => a + b * b));

// 매 main isolate 의 block 없이 background work
final sum = await heavyCompute(List.generate(1_000_000, (i) => i));

Extension methods

extension StringX on String {
  String get capitalized => isEmpty ? this : '${this[0].toUpperCase()}${substring(1)}';
}

print('hello'.capitalized); // "Hello"

Mixin

mixin Loggable {
  void log(String msg) => print('[${runtimeType}] $msg');
}

class Service with Loggable {
  void doWork() => log('working...');
}

매 결정 기준

상황 Approach
매 Flutter mobile/desktop app Dart (의무)
매 CLI tool (cross-platform) Dart AOT compile
매 backend (Aqueduct/Shelf) 매 가능 — 매 ecosystem 작음
매 web (no Flutter) 매 비추천 — TS/JS 우세

기본값: 매 Flutter context 에서만 Dart 의 사용 — 매 standalone 은 Go/Rust/TS 의 권장.

🔗 Graph

🤖 LLM 활용

언제: 매 Flutter widget tree 작성, 매 isolate 기반 background work, 매 records/patterns 활용 의 modern Dart. 언제 X: 매 Flutter 외부 — 매 다른 ecosystem 에서 Dart 의 사용 의 의미 X.

안티패턴

  • 매 dynamic 의 남용: 매 type system 의 우회 — 매 sound null safety 의 무력화.
  • 매 sync await chain: 매 Future.wait 의 미사용 — 매 serialized 대기.
  • 매 isolate 와 closure: 매 capture-by-reference 의 함정 (sendable 만 가능).
  • 매 print debug: 매 debugPrint / logger 의 권장.

🧪 검증 / 중복

  • Verified (dart.dev language tour, Dart 3.3 release 2024, Flutter 3.27).
  • 신뢰도 A.

🕓 Changelog

날짜 변경
2026-05-08 Phase 1
2026-05-10 Manual cleanup — Dart 3 records/patterns/sealed 정리