fetchUsers method
Implementation
Future<Either<String, List<UserItemModel>>> fetchUsers() async {
try {
final response = await http.get(Uri.parse(baseUrl));
if (response.statusCode == 200) {
final List<dynamic> data = jsonDecode(response.body);
final users = data
.map((e) => UserItemModel.fromJson(Map<String, dynamic>.from(e)))
.toList();
return Right(users);
} else {
return Left('Error en listar usuarios: ${response.statusCode}');
}
} catch (e) {
return Left('Exception: $e');
}
}