Your Second Flutter App

Nov 30 2021 · Dart 2.13, Flutter 2.2.3, Visual Studio Code

Part 1: Parse Network Data

08. Parse Domains

Episode complete

Play next episode

Next
About this episode
Leave a rating/review
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 07. Challenge: Add More Properties Next episode: 09. Use Dependency Injection

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

Each course has a domain like iOS or Android, and some courses are for multiple domains. Domain parsing is a bit more involved than the other course properties, since each course can have multiple domains. In this episode, you’ll see how to parse the list of domains in the fromJson method.

enum Domain { all, ios, android, flutter, sss, unity, macos, archived, unknown }
extension DomainExtension on Domain {
  String get name {
    switch (this) {
      case Domain.ios:
        return Strings.ios;
      case Domain.android:
        return Strings.android;
      case Domain.unity:
        return Strings.unity;
      case Domain.sss:
        return Strings.sss;
      case Domain.flutter:
        return Strings.flutter;
      case Domain.macos:
        return Strings.macos;
      case Domain.archived:
        return Strings.archived;
      default:
        return Strings.unknown;
    }
  }
}
import '../strings.dart';
final List<Domain> domains;
import 'domain.dart';
this.domains,
domains = []
domains = [] {
  final domainData =
        json['relationships']['domains']['data'] as List<dynamic>;
}
if (domainData.length > 0) {
  for (var i = 0; i < domainData.length; i++) {
    final domain =
        Course.getDomain(json['relationships']['domains']['data'][i]['id'] as String);
    domains.add(domain);
  }
}
import '../constants.dart';
static Domain getDomain(String domainId) {
  switch (domainId) {
    case Constants.iosDomain:
      return Domain.ios;
    case Constants.androidDomain:
      return Domain.android;
    case Constants.unityDomain:
      return Domain.unity;
    case Constants.sssDomain:
      return Domain.sss;
    case Constants.flutterDomain:
      return Domain.flutter;
    case Constants.macosDomain:
      return Domain.macos;
    case Constants.archivedDomain:
      return Domain.archived;
    default:
      return Domain.unknown;
  }
}
String get domainsString {
  var result = '';
  for (var i = 0; i < domains.length - 1; i++) {
    result += domains[i].name + ', ';
  }
  result += domains.last.name;
  return result;
}
String toString() {
  return name + ': ' + domainsString;
}