Advertisement
Guest User

Api service

a guest
Jan 25th, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 0.66 KB | None | 0 0
  1. class ApiService {
  2.   final String baseUrl = "http://192.168.100.94:5000";
  3.   Client client = Client();
  4.  
  5.   Future<List<Vendor>> getVendors() async {
  6.    
  7.     final response = await client.get("$baseUrl/api/vendor");
  8.     if (response.statusCode == 200) {
  9.       return vendorFromJson(response.body);
  10.     } else {
  11.       return null;
  12.     }
  13.   }
  14.  
  15.   Future<bool> createVendor(Vendor data) async {
  16.     final response = await client.post(
  17.       "$baseUrl/api/vendor",
  18.       headers: {"content-type": "application/json"},
  19.       body: vendorToJson(data),
  20.     );
  21.     if (response.statusCode == 201) {
  22.       return true;
  23.     } else {
  24.       return false;
  25.     }
  26.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement