How can I improve this code semantics, I don't like doing this concatenation.
I'm having a little difficulty with the semantics of the code for dart, map [ ] these things.
. user.name
'${Path.AWS_IMG}/${post[index]['userInfo']['image']}'
post[index]['description']
cubit
class PostCubit extends Cubit<PostState> {
PostRepository postRepository;
PostCubit({required this.postRepository}) : super(PostState.initial());
Future getPosts() async {
this.emit(_Loading());
final PostList posts = await this.postRepository.getPosts();
this.emit(PostState.loaded(posts));
return posts;
}
}
Repo
Future getPosts() async {
try {
final response = await http
.get(Uri.parse(url + Path.LIST_POSTS), headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
'x-access-token': await secureStorage.read(Keys.X_ACCESS_TOKEN)
});
if (response.statusCode == 200) {
final listPosts = jsonDecode(response.body);
final postListEntity = PostList.fromJson({'postList': listPosts});
return postListEntity;
} else {
return response.statusCode;
}
} catch (e) {
return e;
}
}