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

Take your career further with a raywenderlich.com Pro subscription. 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.

Create the Model Class Pro

This video was last updated on Aug 30 2022

Create a model class for the activities that you will save into a Firestore collection, and later retrieve from it.

Contributors

Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.

You can unlock the rest of this video course, and our entire catalogue of books and videos, with a raywenderlich.com Professional subscription.

A rather common approach when dealing with databases, or web services, is creating classes that mirror the data you want to read and write: these classes are generally called models. Now you will create a model for the activities that you will save into a Firestore collection, and later retrieve from it.

class Activity {} 
String? id; 
late String description; 
late String day; 
late String beginTime; 
late String endTime; 
String? imagePath; 
Activity(this.id, this.description, this.day, this.beginTime, this.endTime, 
      this.imagePath); 
Activity.fromMap(Map<String, dynamic> map, String id) { 
  id = id; 
  description = map['description'].toString(); 
  day = map['day'].toString(); 
  beginTime = map['beginTime'].toString(); 
  endTime = map['endTime'].toString(); 
  imagePath = map['imagePath']?.toString(); 
} 
Map<String, dynamic> toMap() { 
    return <String, dynamic>{ 
      'id': id ?? '', 
      'description': description, 
      'day': day, 
      'beginTime': beginTime, 
      'endTime': endTime, 
      'imagePath': imagePath ?? ‘’ 
    }; 
  } 

Reviews

Comments