Skip to content
← All Skills
🎯

Dart

ภาษาหลักสำหรับ Flutter — ใช้พัฒนา mobile apps ทั้ง fintech และ banking ที่มีผู้ใช้หลายล้านคน

What I Can Do

  • เขียน cross-platform mobile apps ด้วย Dart + Flutter
  • ใช้ null safety อย่างถูกต้องตั้งแต่ design phase
  • จัดการ async operations ด้วย Future, Stream, Isolate
  • เขียน unit tests และ widget tests
  • ใช้ code generation (build_runner, freezed, json_serializable)

Commands I Use Daily

bash
# analyze code หา issues
dart analyze

# format code ตาม standard
dart format .

# run Dart script
dart run bin/main.dart

# run tests
dart test

# get dependencies
dart pub get

# ดู outdated packages
dart pub outdated

# code generation
dart run build_runner build --delete-conflicting-outputs

Null Safety

Dart มี sound null safety — ทุก type เป็น non-nullable by default, ใช้ ? suffix ทำให้ nullable เช่น String? compiler บังคับ null check ก่อนใช้งาน ทำให้ไม่มี null reference errors ที่ runtime

Types & Variables

  • var — type inference
  • final — assign ได้ครั้งเดียว (runtime constant)
  • const — compile-time constant
  • late — lazy initialization สำหรับ non-nullable variables ที่ assign ทีหลัง

Functions

Dart functions เป็น first-class objects — assign ให้ variable ได้, ส่งเป็น parameter ได้ รองรับ named parameters {required String name}, optional positional parameters [int? age], default values

Classes & Objects

  • Constructor — default, named (ClassName.fromJson()), factory
  • Getters/Settersget / set keywords
  • Private — ใช้ _ prefix (library-level privacy)
  • Abstract classes — ใช้เป็น contract/interface
  • Inheritanceextends สำหรับ single inheritance

Mixins

Mixins ใช้ share behavior ข้าม class hierarchy โดยไม่ต้อง extend — with keyword, ใช้เมื่อต้องการ reuse code ที่ไม่เหมาะจะเป็น parent class เช่น class MyWidget extends StatelessWidget with ThemeMixin

Generics

Dart รองรับ generics สำหรับ type-safe collections และ classes — List<String>, Map<String, dynamic>, custom generic classes class Repository<T> ช่วยลด code duplication

Async / Await / Future

  • Future — represents async operation ที่จะ complete ในอนาคต
  • async / await — เขียน async code แบบ synchronous style
  • Future.wait() — รอหลาย futures พร้อมกัน
  • Error handling ด้วย try/catch หรือ .catchError()

Streams

Streams คือ sequence ของ async events — ใช้สำหรับ data ที่มาเรื่อยๆ เช่น WebSocket messages, sensor data, StreamBuilder ใน Flutter, async* / yield สำหรับสร้าง streams

Isolates

Isolates คือ Dart's concurrency model — แต่ละ isolate มี memory heap แยกกัน ไม่ share state ติดต่อกันผ่าน message passing ใช้สำหรับ heavy computation ที่ไม่อยากบล็อก UI thread

Extensions

Extension methods เพิ่ม functionality ให้ existing types โดยไม่ต้องแก้ source code — เช่น extension StringX on String { bool get isEmail => ... } ทำให้ 'test@mail.com'.isEmail ใช้ได้

Enums

Dart enums รองรับ methods, fields, constructors (enhanced enums ตั้งแต่ Dart 2.17) — ใช้แทน magic strings/numbers สำหรับ finite set of values

Collections

  • List — ordered collection ([])
  • Set — unordered unique elements ({})
  • Map — key-value pairs ({key: value})
  • Collection literals, spread operator ..., if/for in collections

Pattern Matching (Dart 3)

Dart 3 เพิ่ม pattern matching — switch expressions, destructuring, guard clauses, sealed classes ทำให้จัดการ complex data structures ได้ clean ขึ้น

Related Skills

  • Flutter — UI framework ที่ใช้ Dart
  • JavaScript — ภาษาที่มี syntax คล้ายกัน
  • TypeScript — type system concepts ที่คล้ายกัน