fetchPhotos method Null safety

Future<PhotoPaging> fetchPhotos(
  1. {required String userId}
)

Retrieve an instagram account's PUBLIC feed images recognized by his userId

Implementation

Future<PhotoPaging> fetchPhotos({
  //required String sessionKey,
  required String userId,
  //int? page,
}) async {
  const limit = 16;
  String url =
      '$_igScrapperEndpoint/userpost/$userId/$limit/%7Bend_cursor%7D';

  var response = await http.get(Uri.parse(url), headers: {
    'X-RapidAPI-Key': Env.apiKey,
    'X-RapidAPI-Host': 'instagram-scraper-data.p.rapidapi.com'
  });

  Map<String, dynamic> body = {};
  if (response.statusCode == 200) {
    body = json.decode(response.body);
  }

  List<String> urls = [];
  final edges = body['data']['edges'];
  for (var map in edges) {
    urls.add(map['node']['display_url']);
  }
  Map body2 = {
    'data': urls,
  };
  return PhotoPaging.fromJson(body2);
}