Github API Consumption - Dart / Flutter

Github API consumption - Dart / Flutter

This project aimed to understand how API consumption works with the HTTP dependency of Dart / Flutter.

class  UserRepository {
   var url =  'https://api.github.com/users' ;

  Future < List < UserModel >>  getAllUsers () async {
     var response =  await http. get (url);
    var jsonResponse = convert. jsonDecode (response.body);
    List < UserModel > users = [];

    for ( var json in jsonResponse) {
      users. add ( UserModel . fromJson (json));
    }

    return users;
  }

  Future < UserModel >  getUserByName ( String name) async {
     var response =  await http. get (url +  '/ $ name ' );
    var jsonResponse = convert. jsonDecode (response.body);

    UserModel user =  UserModel . fromJson (jsonResponse);

    return user;
  }
}

The result was this:

Alt Text

Download Details:

Author: Vafernandes

Source Code: https://github.com/Vafernandes/Consumo_API_GIthub_Flutter

#flutter #dart #mobile-apps

Github API Consumption - Dart / Flutter
38.00 GEEK