🔒 Closed [dart] implicit_dynamic_method when fetching json from net

Status
Not open for further replies.

Katipunero-

Honorary Poster
Sometimes, you'll run into some linter errors like implicit_dynamic_method.
You can fix it by temporary adding dynamic to Response<T> if you really don't know what will be the
data type of incoming request from server.
Code:
 Future<List<Card>> fetchCustomerCards(int userID) async {
    try {
      final _uri = Uri.parse('/users/$userID/cards');
      final response = await dioClient.get<dynamic>(
        _uri.path,
      );
      if (response.data != null) {
        final responseList = response.data! as List;
        final cards = responseList
            .map(
              (dynamic e) => Card.fromJson(e as JsonMap),
            )
            .toList();
        return cards;
      }
      return [];
    } on DioError catch (e) {
      print(e);
      if (e.response?.statusCode == 300) {
        throw CustomFailure.fromJson(e.response!.data as JsonMap);
      }
      throw CustomFailure.fromJson(e.response!.data as JsonMap);
    } catch (e) {
      print(e);
      throw const CustomFailure();
    }
  }
 
Status
Not open for further replies.

About this Thread

  • 1
    Replies
  • 382
    Views
  • 2
    Participants
Last reply from:
dev-ace

Trending Topics

Online now

Members online
1,214
Guests online
1,412
Total visitors
2,626

Forum statistics

Threads
2,273,458
Posts
28,949,640
Members
1,235,752
Latest member
hojerry7
Back
Top