'Flutter SQFlite convert Class toJson()
I am building a SQFlite database for my app but I have a problem with the creation of my DB. Converting my class toJson() the code throws me the following errors:
Database file:
Future<Entries> create(Entries entries) async {
final db = await instance.database;
final id = await db.insert(tableFavs, entries.toJson());
}
Error (at entries.toJson()): A value of type 'Set' can't be returned from the method 'toJson' because it has a return type of 'Map<dynamic, dynamic>'.
Here is my class:
import 'package:flutter/material.dart';
const String tableFavs = 'favorites';
class EntryFields {
static late String id = '_id';
static late String name = '_name';
static late String navigation = '_navigation';
}
class Entries {
final int id;
final String name;
final Widget navigation;
Entries({
required this.id,
required this.name,
required this.navigation,
});
Map<Object> toJson() => {
EntryFields.id = id,
EntryFields.name = name,
EntryFields.navigation = navigation,
};
}
Does anyone knows how to fix this?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
