Beginning FlutterFire

Aug 30 2022 · Dart 2.16, Flutter 3.0, Visual Studio Code 1.69

Part 3: Read & Write Data with the Cloud Firestore

10. Create the Model Class

Episode complete

Play next episode

About this episode
Leave a rating/review
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 09. Add Data in a Firestore Collection Next episode: 11. Insert & Retrieve Data from Firestore

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've reached locked video content where the transcript will be shown as obfuscated text.

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.description,, this.beginTime, this.endTime, 
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 ?? ‘’