I've been trying to debug this issue for a couple hours now, but not sure what's going wrong and would really appreciate some help.
Context:
I hit the following error when trying to fetch / authenticate a user.
_AssertionError ('package:nylo_support/networking/models/default_response.dart': Failed assertion: line 11 pos 12: 'decoders.containsKey(type)': Your config/decoders.dart file does not contain a decoder for the following class: User in modelDecoders)
in fact, the decoders
is returning an empty map (list), which is why it can't find the 'User' key. But my modelDecoders is definitely defined. See below for the relevant code.
Future<User?> logIn(String email, String password) async {
return await network<User>(
request: (request) => request
.post("/api/v1/auth", data: {"email": email, "password": password}),
);
}
And the modelDecoders does in fact contain the User:
final Map<Type, dynamic> modelDecoders = {
List<User>: (data) =>
List.from(data).map((json) => User.fromJson(json)).toList(),
User: (data) => User.fromJson(data),
List<Product>: (data) =>
List.from(data).map((json) => Product.fromJson(json)).toList(),
Product: (data) => Product.fromJson(data),
List<Vote>: (data) =>
List.from(data).map((json) => Vote.fromJson(json)).toList(),
Vote: (data) => Vote.fromJson(data),
};
The User model is also correct:
import 'package:nylo_framework/nylo_framework.dart';
class User extends Model {
String? id;
String? frlId;
String? username;
String? gender;
String? email;
String? token;
String? sessionId;
User({
required this.id,
this.username,
this.gender,
this.frlId,
required this.email,
required this.token,
this.sessionId,
});
User.fromJson(dynamic data) {
id = data['id'];
frlId = data['frl_id'];
username = data['username'];
gender = data['gender'];
email = data['email'];
token = data['token'];
sessionId = data['session_id'];
}
@override
Map<String, dynamic> toJson() => {
"id": id,
"frl_id": frlId,
"email": email,
"token": token,
"username": username,
"gender": gender,
"session_id": sessionId,
};
}
So I am really clueless why this error is happening. Would really appreciate some assistance, been banging my head on this one for a while now.