fireship-io / flutter-firebase-quizapp-course

QuizApp Built with Flutter & Firebase
https://fireship.io/courses/flutter-firebase/
559 stars 244 forks source link

Upgrading firebase #21

Open jrheisler opened 3 years ago

jrheisler commented 3 years ago

Lots to do to upgrade to the latest firebase. This one has me stumped. The Collection method:

Stream<List> streamData() { return ref.snapshots().map((list) => list.documents.map((doc) => Global.modelsT as T) ); } gives: Expected a value of type 'Map<dynamic, dynamic>', but got one of type '() => Map<String, dynamic>'

jrheisler commented 3 years ago

As always, the second you give you, you find your problem. It's in the fromMap(data) end. Data is now a method, so it gets read:

name: data()['name'] ?? '',

T3Drones commented 3 years ago

Hello, so for this project specifically.....if you are trying to update to the current version of firebase it is important to place the parenthesis for data method in your Globals.dart

OLD


  // Data Models
  static final Map models = {
    Topic: (data) => Topic.fromMap(data),
    Quiz: (data) => Quiz.fromMap(data),
    Report: (data) => Report.fromMap(data)
  };

NEW


  // Data Models
  static final Map models = {
    Topic: (data) => Topic.fromMap(data()),
    Quiz: (data) => Quiz.fromMap(data()),
    Report: (data) => Report.fromMap(data())
  };