Commit 3f3158ca authored by jinzhu's avatar jinzhu

初步完成网络解析

parent 6e37fe57
import 'package:flutter/material.dart';
import 'package:gmalpha_flutter/model/message/replied_content.dart';
class Message {
final String userId;
final int userId;
final String name;
final String icon;
final String time;
final num time;
final String content;
final String id;
final int id;
// final String repliedContent;
final RepliedContent repliedContent;
......
import 'replied_content.dart';
class RepliedContent {
final String id;
final String type;
final String topicId;
final int id;
final int type;
final int topicId;
final String content;
final String contentType;
final int contentType;
RepliedContent({this.id, this.type, this.topicId, this.content, this.contentType});
......
......@@ -179,6 +179,11 @@ class DioUtil {
if (_dio != null) {
_dio.options = _options;
(_dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate = (client) {
client.findProxy = (url) {
return _isDebug ? 'PROXY $_proxy' : 'DIRECT';
};
};
if (_pem != null) {
// httpClientAdapter
(_dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate = (client) {
......@@ -190,11 +195,7 @@ class DioUtil {
}
return false;
};
client.findProxy = (url) {
return _isDebug ? 'PROXY $_proxy' : 'DIRECT';
};
};
}
if (_pKCSPath != null) {
(_dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate = (client) {
......@@ -213,11 +214,15 @@ class DioUtil {
/// [path] The url path.
/// [data] The request data
/// [options] The request options.
/// Map<String, dynamic> queryParameters,
/// <BaseResp<T> 返回 status code msg data .
Future<BaseResp<T>> request<T>(String method, String path,
{data, Options options, CancelToken cancelToken}) async {
{Map<String, dynamic> queryParameters, data, Options options, CancelToken cancelToken}) async {
// _dio.request(path, que)
// _dio.request(path, )
Response response = await _dio.request(path,
data: data,
queryParameters: queryParameters,
options: _checkOptions(method, options),
cancelToken: cancelToken);
_printHttpLog(response);
......@@ -233,10 +238,6 @@ class DioUtil {
response.statusCode == HttpStatus.created) {
try {
if (response.data is Map) {
// _status = (response.data[_statusKey] is int)
// ? response.data[_statusKey].toString()
// : response.data[_statusKey];
_code = (response.data[_codeKey] is String)
? int.tryParse(response.data[_codeKey])
: response.data[_codeKey];
......@@ -261,10 +262,8 @@ class DioUtil {
type: DioErrorType.RESPONSE,
));
}
} else {
_code = 1;
_msg = '请求失败';
}
}
return new Future.error(new DioError(
response: response,
message: "statusCode: $response.statusCode, service error",
......@@ -279,9 +278,11 @@ class DioUtil {
/// [options] The request options.
/// <BaseRespR<T> 返回 status code msg data Response.
Future<BaseRespR<T>> requestR<T>(String method, String path,
{data, Options options, CancelToken cancelToken}) async {
{Map<String, dynamic> queryParameters, data, Options options, CancelToken cancelToken}) async {
// _dio.request(path,queryParameters: )
Response response = await _dio.request(path,
data: data,
queryParameters: queryParameters,
options: _checkOptions(method, options),
cancelToken: cancelToken);
_printHttpLog(response);
......@@ -444,8 +445,8 @@ class DioUtil {
options.connectTimeout = 10 * 1000;
options.receiveTimeout = 20 * 1000;
options.contentType = ContentType.parse('application/x-www-form-urlencoded');
// options.baseUrl = 'https://earth.iyanzhi.com/';http://earth.gmapp.env/
options.baseUrl = 'http://earth.gmapp.env/';
options.baseUrl = 'https://earth.iyanzhi.com/';
// options.baseUrl = 'http://earth.gmapp.env/';
Map<String, dynamic> headers = Map<String, dynamic>();
headers['Accept'] = 'application/json';
return options;
......
......@@ -29,42 +29,22 @@ class _MessageHomePageState extends State<MessageHomePage> with AutomaticKeepAli
Future<List<Message>> _fetchMesssageList() async {
BaseOptions options = DioUtil.getDefOptions();
options.baseUrl = "http://earth.gmapp.env/";
final cookie = new Map<String, dynamic>.from({'_gm_token': 'dfb1d61562677661', '_gtid': 'e49a16069e4411e98014525400e82fab836', 'sessionid': '4w1pyiayin5odywgbosemgul8m28t6x4'});
HttpConfig config = new HttpConfig(options: options, nativeCookie: cookie);
Map<String, dynamic> cookie = {'cookie': '_gm_token=4cabd51562739648; _gtid=fac513b6a2bf11e9acfd525400e5c7a38141; sessionid=7j7s902fmro0pvybwrp374khvva6l3xf;'};
HttpConfig config = new HttpConfig(options: options, nativeCookie:cookie);
DioUtil().setConfig(config);
print(cookie);
List<Message> messageList = List<Message>();
print('aaaaa');
DioUtil().requestR(Method.get, "api/v1/reply/my",data: {'page': 1, 'count': 10}).then((res){
print('333333333');
print(res);
return messageList;
BaseResp<List> baseresp = await DioUtil().request<List>(Method.get, "api/v1/reply/my", queryParameters: {'page': 1, 'count': 10});
if (baseresp.code != 0) {
return new Future.error(baseresp.msg);
}
if (baseresp.data != null) {
messageList = baseresp.data.map((value) {
return Message.fromJson(value);
}).toList();
}
).then((error) {
print('ddddd');
print(error);
// return messageList;
});
// print(res);
return messageList;
// .then((res){
// if (res.code == 0) {
// Map<String, dynamic> data = json.decode(res.data);
// for (dynamic data in data['data']) {
// Message messageData = Message.fromJson(data);
// messageList.add(messageData);
// }
// }
// return messageList;
// }).then((error){
// return messageList;
// });
}
_getdata() async{
return _fetchMesssageList();
}
@override
......@@ -75,32 +55,30 @@ class _MessageHomePageState extends State<MessageHomePage> with AutomaticKeepAli
),
floatingActionButton: new FloatingActionButton(
onPressed: () {
List<Message> res = _getdata();
},
},
child: new Icon(Icons.add_box),
elevation: 3.0,
highlightElevation: 2.0,
backgroundColor: Colors.red, // 红色
),
// body: ListView(children: _getListData()),
body: new Center(
// child: FutureBuilder(
// future: _fetchMesssageList(),
// builder: (context, snapshot) {
// switch (snapshot.connectionState) {
// case ConnectionState.none:
// case ConnectionState.waiting:
// break;
// default:
// if (snapshot.hasData) {
// return _createListView(context, snapshot);
// }
// }
// },
child: FutureBuilder(
future: _fetchMesssageList(),
builder: (context, snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.none:
case ConnectionState.waiting:
break;
default:
if (snapshot.hasData) {
return _createListView(context, snapshot);
}
}
},
),
// )
)
);
}
......@@ -108,6 +86,7 @@ class _MessageHomePageState extends State<MessageHomePage> with AutomaticKeepAli
Widget _createListView(BuildContext context, AsyncSnapshot snapshot) {
List<Message> messageList = snapshot.data;
return ListView.builder(
shrinkWrap: true,
key: new PageStorageKey('message-list'),
itemCount: messageList.length,
itemBuilder: (BuildContext context, int index) {
......
......@@ -29,14 +29,14 @@ class MessageItem extends StatelessWidget {
),
);
var titleRow = new Row(
var titleRow = new Row (
children: <Widget>[
new Row (
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Text(message.name, style: TextStyle(color: Color(0xff323232), fontWeight: FontWeight.bold, fontSize: 13)),
new Padding (
padding: EdgeInsets.only(left: 8),
padding: EdgeInsets.only(left: 8, right: 8),
child: Text('评论了你', style: TextStyle(color: Color(0xff323232), fontSize: 13)),
)
],
......@@ -44,16 +44,23 @@ class MessageItem extends StatelessWidget {
],
);
var contenRow = new Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
timeStr() {
datefr
}
var contenRow = new Row (
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
new Row (
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Text(message.content, style: TextStyle(color: Color(0xff323232), fontSize: 13)),
],
),
new Expanded(
child: new Text(message.content, maxLines: 2, textAlign: TextAlign.start, overflow: TextOverflow.ellipsis, style: TextStyle(color: Color(0xff323232), fontSize: 13, )),
)
],
// mainAxisSize: ,
// children: <Widget>[
// ],
// padding: EdgeInsets.only(right: ),
// mainAxisAlignment: MainAxisAlignment.start,
);
......@@ -85,8 +92,10 @@ class MessageItem extends StatelessWidget {
child: new Padding(
padding: const EdgeInsets.all(10.0),
child: new Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
titleRow,
// Text(message.content, maxLines: 2, textAlign: TextAlign.left, overflow: TextOverflow.ellipsis, style: TextStyle(color: Color(0xff323232), fontSize: 13, )),
contenRow,
timeRow,
],
......@@ -107,7 +116,5 @@ class MessageItem extends StatelessWidget {
),
),
);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment