forked from zhujian1989/flutter_study
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d54a705
commit 1b6e236
Showing
14 changed files
with
562 additions
and
461 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import 'dart:async'; | ||
import 'dart:convert'; | ||
import 'dart:io'; | ||
|
||
import 'package:flutter_study/common/constant.dart'; | ||
import 'package:flutter_study/model/ai_model.dart'; | ||
import 'package:flutter_study/mvp/repository/ai_repository.dart'; | ||
|
||
class AIRepositoryImpl implements AIRepository { | ||
@override | ||
Future<List<AIModel>> fetch(String type, int pageNum, int pageSize) { | ||
return _getData(type, pageNum, pageSize); | ||
} | ||
} | ||
|
||
Future<List<AIModel>> _getData(String type, int pageNum, int pageSize) async { | ||
var httpClient = new HttpClient(); | ||
var url = Constant.baseUrl + '$type/$pageSize/$pageNum'; | ||
|
||
print(url); | ||
|
||
List aiModels; | ||
|
||
try { | ||
var request = await httpClient.getUrl(Uri.parse(url)); | ||
var response = await request.close(); | ||
if (response.statusCode == HttpStatus.OK) { | ||
var json = await response.transform(Utf8Decoder()).join(); | ||
aiModels = jsonDecode(json)['results']; | ||
|
||
} else { | ||
//todo | ||
} | ||
} catch (exception) { | ||
//todo | ||
} | ||
|
||
return aiModels.map((model) { | ||
return new AIModel.fromJson(model); | ||
}).toList(); | ||
} | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import 'dart:async'; | ||
import 'package:flutter_study/model/fl_model.dart'; | ||
import 'dart:convert'; | ||
import 'dart:io'; | ||
import 'package:flutter_study/common/constant.dart'; | ||
import 'package:flutter_study/mvp/repository/fl_repository.dart'; | ||
//分类数据: http://gank.io/api/data/数据类型/请求个数/第几页 | ||
//数据类型: 福利 | Android | iOS | 休息视频 | 拓展资源 | 前端 | all | ||
//请求个数: 数字,大于0 | ||
//第几页:数字,大于0 | ||
//@param rows | ||
//@param pageNum | ||
//@return | ||
|
||
|
||
class FLRepositoryImpl implements FLRepository { | ||
@override | ||
Future<List<FLModel>> fetch(int pageNum,int pageSize) { | ||
return _getData(pageNum,pageSize); | ||
} | ||
} | ||
|
||
Future<List<FLModel>> _getData(int pageNum,int pageSize) async { | ||
var httpClient = new HttpClient(); | ||
var url = Constant.baseUrl + '福利/$pageSize/$pageNum'; | ||
|
||
print(url); | ||
|
||
List flModels; | ||
try { | ||
var request = await httpClient.getUrl(Uri.parse(url)); | ||
var response = await request.close(); | ||
if (response.statusCode == HttpStatus.OK) { | ||
var json = await response.transform(Utf8Decoder()).join(); | ||
flModels = jsonDecode(json)['results']; | ||
} else { | ||
//todo | ||
} | ||
} catch (exception) { | ||
//todo | ||
} | ||
|
||
return flModels.map((model) { | ||
return new FLModel.fromJson(model); | ||
}).toList(); | ||
} | ||
|
||
|
||
|
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
Oops, something went wrong.