Created
April 15, 2021 18:32
-
-
Save M001T/dfd02e83bd25ac8622c130766f0174c7 to your computer and use it in GitHub Desktop.
Usamos o modelo MVC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:convert'; | |
import 'package:facil_alimentos/api/services_api/cache_management.dart'; | |
import 'package:facil_alimentos/models/anuncios_model.dart'; | |
import 'package:http/http.dart' as http; | |
class GetAnunciosApi { | |
int qtdPatronizedPref = 0; | |
int qtdPatronized = 0; | |
int qtdNotPatronized = 0; | |
int qtdLastPosts = 0; | |
Future<List<AnuncioModel>> getMyAnuncios(String userId) async { | |
List<AnuncioModel> anuncios = []; | |
var url = | |
'xxxxxxxxxxxxxxxxxxxxxxxxxx'; | |
var header = { | |
"Content-type": "application/json", | |
"key": "xxxxxxxxxxxxxxxx", | |
"token": "xxxxxxxxxxxxxxxxxxxxxxxxxxx" | |
}; | |
Map params = { | |
"user_id": int.parse(userId), | |
}; | |
var _body = json.encode(params); | |
try { | |
var response = await http.post(url, headers: header, body: _body); | |
final data = json.decode(response.body); | |
if (data['status'] == '400') { | |
return anuncios; | |
} | |
for (Map map in data['data']) { | |
AnuncioModel anuncio = AnuncioModel.fromJson(map); | |
anuncios.add(anuncio); | |
} | |
return anuncios; | |
} catch (e) { | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment