-3

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;
    }
  }

enter image description here`

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
geovane
  • 1
  • 1
  • We don't do code review here; please try [codereview.se]. Make sure to read their how-to-ask guidelines before posting. – Karl Knechtel Aug 30 '23 at 02:01

0 Answers0