网络文章-v1
This commit is contained in:
23
lib/net_article/api/article_api.dart
Normal file
23
lib/net_article/api/article_api.dart
Normal file
@@ -0,0 +1,23 @@
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
import '../model/article.dart';
|
||||
|
||||
class ArticleApi{
|
||||
|
||||
static const String kBaseUrl = 'https://www.wanandroid.com';
|
||||
|
||||
final Dio _client = Dio(BaseOptions(baseUrl: kBaseUrl));
|
||||
|
||||
Future<List<Article>> loadArticles(int page) async {
|
||||
String path = '/article/list/$page/json';
|
||||
var rep = await _client.get(path);
|
||||
if (rep.statusCode == 200) {
|
||||
if(rep.data!=null){
|
||||
var data = rep.data['data']['datas'] as List;
|
||||
return data.map(Article.formMap).toList();
|
||||
}
|
||||
}
|
||||
return [];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user