[Dart💠]Dart 3 Tips (always updating)

Dart

Switch function

You can write switch function like the following code.

Before Dart 3.0

    final String os;
    switch (device) {
      case Ritchman():
        device = 'Apple';
      case IDontCareAboutUX():
        device = 'Android';
      case WindowsBeliver():
        role = 'WindowsPhone';
    }

After Dart 3.0

final role = switch (device) {
      Ritchman() => 'Apple';
     IDontCareAboutUX() => 'Android';
      WindowsBeliver() => 'WindowsPhone';
    };

Union type

コメント

タイトルとURLをコピーしました