databasefluttergeneratorfloor

Flutter Floor Database. Failed to generate the floor database


I followed the floor documentation step by step. Entities, Dao, Converters and database have been created. Build_generator generated the model.g.dart files type but not the database.g.dart file.

I encounter two errors:

Could not generate `fromJson` code for `changeListener`.
To support the type `StreamController` you can:
* Use `JsonConverter`
https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonConverter-class.html
* Use `JsonKey` fields `fromJson` and `toJson`
https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/fromJson.html
https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/toJson.html
package:floor/src/database.dart:11:39
  ╷
11 │   late final StreamController<String> changeListener;

Error that I find weird because it asks me to create a converter for a listener of the FloorDatabase class...

And also:

There are no entities added to the database annotation. package:sirusmobile/database/database.dart:93:16 ╷ 93 │ abstract class AppDatabase extends FloorDatabase {

However, the entities are well informed.

part 'database.g.dart';

@JsonSerializable()
@Database(version: 2, entities: [
  AccesToken,
  Account,
  Chauffeur,
  Coordonnees,
  FilsDiscussion,
  LieuIntervention,
  Mission,
  Permanence,
  PositionGps,
  Secteur,
  Societe,
  Transmission,
  Vehicule,
  Delai,
  Destination,
  Motifs,
  Raison,
  Synchro
])
@TypeConverters([
  StringListConverter,
  ChauffeurConverter,
  DegresUrgenceConverter,
  DelaiConverter,
  DestinationConverter,
  EquipementConverter,
  FilsDiscussionConverter,
  MotifsAnnulationConverter,
  MotifsRefusConverter,
  MotifsSortieBlancheConverter,
  RaisonConverter,
  SocieteConverter,
  VehiculeConverter
])
abstract class AppDatabase extends FloorDatabase {
  AccesTokenDao get accesTokenDao;

  AccountDao get accountTokenDao;

  ChauffeurDao get chauffeurDao;

  CoordonneesDao get coordoneesDao;

  FilsDiscussionDao get filsDiscussionDao;

  LieuInterventionDao get lieuInterventionDao;

  MissionDao get missionDao;

  PermanenceDao get permanenceDao;

  PositionGpsDao get positionGps;

  SecteurDao get secteurDao;

  SocieteDao get societeDao;

  TransmissionDao get transmissionDao;

  VehiculeDao get vehiculeDao;

  DelaiDao get delaiDao;

  DestinationDao get destinationDao;

  MotifsDao get motifsDao;

  RaisonDao get raisonDao;

  SynchroDao get synchroDao;
}

I've been trying to solve this problem for too long. Could someone help me please? Thanks in advance.


Solution

  • I'm answering my question because I solved the problem. I did two things for this.

    Hope this can help some people.

    Good day !