flutterentity-frameworkflutter-dependencies

flutter Error: The argument type 'Object Function()' can't be assigned to the parameter type 'Map<String, dynamic>'


I tried to create a model in the flutter material app for players. I created a class called 'player' and implement it. I edit gradle files for connecting with firebase. I gain some errors in my code. So please help me to solve this error.

Error

Error: The argument type 'Object Function()' can't be assigned to the parameter type 'Map<String, dynamic>'.
 - 'Object' is from 'dart:core'.
 - 'Map' is from 'dart:core'.
      : this.fromMap(snapshot.data, documentReference: snapshot.reference);
                              ^


FAILURE: Build failed with an exception.

* Where:
Script 'C:\src\flutter\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 1035

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'C:\src\flutter\flutter\bin\flutter.bat'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 11m 3s
Exception: Gradle task assembleDebug failed with exit code 1

This is the model class. Here I add some attributes of players.

Model Class

import 'package:cloud_firestore/cloud_firestore.dart';

class player {
  String bio;
  String name;
  String city;
  String age;
  String role;
  String runs;
  String avg;
  String wiki;

  DocumentReference documentReference;

  player(
      {this.bio,
      this.name,
      this.city,
      this.age,
      this.role,
      this.runs,
      this.avg,
      this.wiki});
  player.fromMap(Map<String, dynamic> map, {this.documentReference}) {
    bio = map["bio"];
    name = map["name"];
    city = map["city"];
    age = map["age"];
    role = map["role"];
    runs = map["runs"];
    avg = map["avg"];
    wiki = map["wiki"];
  }
  player.fromSnapshot(DocumentSnapshot snapshot)
      : this.fromMap(snapshot.data, documentReference: snapshot.reference);

  toJson() {
    return {
      'bio': bio,
      'name': name,
      'city': city,
      'age': age,
      'role': role,
      'runs': runs,
      'avg': avg,
      'wiki': wiki
    };
  }
}


Solution

  • Use snapshot.data() instead of snapshot.data. It's mentioned in the migration guide.

    BREAKING: Getting a snapshots' data via the data getter is now done via the data() method.