Commit 893122ed authored by “Icebear”'s avatar “Icebear”

添加请求数据返回是列表的解析

parent 829ea00b
import 'package:json_annotation/json_annotation.dart';
part 'ExamListModel.g.dart';
@JsonSerializable()
class ExamListModel {
///可考试总次数
int totalCount;
///已考次数
int useCount;
String name;
String startTime;
String endTime;
int resultStatus;
///考试时长
int often;
String examUserId;
int status;
///题目数
int questionNo;
ExamListModel(this.totalCount, this.useCount, this.name,this.startTime,this.endTime,this.resultStatus,this.often,this.examUserId,this.status,this.questionNo);
factory ExamListModel.fromJson(Map<String, dynamic> json) => _$ExamListModelFromJson(json);
Map<String, dynamic> toJson() => _$ExamListModelToJson(this);
}
\ No newline at end of file
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'ExamListModel.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
ExamListModel _$ExamListModelFromJson(Map<String, dynamic> json) {
return ExamListModel(
json['totalCount'] as int,
json['useCount'] as int,
json['name'] as String,
json['startTime'] as String,
json['endTime'] as String,
json['resultStatus'] as int,
json['often'] as int,
json['examUserId'] as String,
json['status'] as int,
json['questionNo'] as int,
);
}
Map<String, dynamic> _$ExamListModelToJson(ExamListModel instance) =>
<String, dynamic>{
'totalCount': instance.totalCount,
'useCount': instance.useCount,
'name': instance.name,
'startTime': instance.startTime,
'endTime': instance.endTime,
'resultStatus': instance.resultStatus,
'often': instance.often,
'examUserId': instance.examUserId,
'status': instance.status,
'questionNo': instance.questionNo,
};
...@@ -24,4 +24,13 @@ class LoginApi { ...@@ -24,4 +24,13 @@ class LoginApi {
} }
}); });
} }
///请求列表数据
static requestListData(Map<String, dynamic> param, OnResult onResult) {
return HttpManager.getInstance().request('exam/user/0', parameters: param,onResult: (data,errorMsg){
if(onResult != null){
onResult(data, errorMsg);
}
});
}
} }
...@@ -7,6 +7,7 @@ import 'LoginApi.dart'; ...@@ -7,6 +7,7 @@ import 'LoginApi.dart';
import 'package:netrain_flutter_app/common/Images.dart'; import 'package:netrain_flutter_app/common/Images.dart';
import 'package:image_picker/image_picker.dart';//从相册里面选择图片或者拍照获取照片 import 'package:image_picker/image_picker.dart';//从相册里面选择图片或者拍照获取照片
import 'dart:io'; import 'dart:io';
import 'ExamListModel.dart';
class LoginRequestPage extends StatefulWidget { class LoginRequestPage extends StatefulWidget {
final String title = "登录页"; final String title = "登录页";
...@@ -56,6 +57,10 @@ class _LoginState extends State<LoginRequestPage> { ...@@ -56,6 +57,10 @@ class _LoginState extends State<LoginRequestPage> {
} }
Future getImage() async { Future getImage() async {
if(UserModel.getModel() == null){
Fluttertoast.showToast(msg:'请登录');
return;
}
var image = await ImagePicker.platform.pickImage(source: ImageSource.gallery); var image = await ImagePicker.platform.pickImage(source: ImageSource.gallery);
_upLoadImage(image);//上传图片 _upLoadImage(image);//上传图片
setState(() { setState(() {
...@@ -71,7 +76,25 @@ class _LoginState extends State<LoginRequestPage> { ...@@ -71,7 +76,25 @@ class _LoginState extends State<LoginRequestPage> {
} }
}); });
} }
void _requestListData() {
if(UserModel.getModel() == null){
Fluttertoast.showToast(msg:'请登录');
return;
}
Map<String, String> map = new Map<String, String>();
map['page'] = '0';
LoginApi.requestListData(map, (httpModel, error) {
if (error != null) {
Fluttertoast.showToast(msg: error);
} else {
List examList = httpModel.data["content"].map((m) => new ExamListModel.fromJson(m)).toList();
if(examList.length > 0){
ExamListModel model = examList[0];
Fluttertoast.showToast(msg: model.toJson().toString(),timeInSecForIos:5);
}
}
});
}
@override @override
...@@ -144,11 +167,20 @@ class _LoginState extends State<LoginRequestPage> { ...@@ -144,11 +167,20 @@ class _LoginState extends State<LoginRequestPage> {
), ),
), ),
Container( Container(
margin: EdgeInsets.only(top: 50), margin: EdgeInsets.only(top: 0),
width: 100, width: 100,
height: 100, height: 100,
child: Image.asset(_image != null ? _image.path : Images.lake), child: Image.asset(_image != null ? _image.path : Images.lake),
), ),
Container(
margin: EdgeInsets.only(top: 10),
width: 100,
height: 50,
child: ElevatedButton(
child: Text("请求列表数据"),
onPressed: _requestListData,
)
),
], ],
), ),
), // This trailing comma makes auto-formatting nicer for build methods. ), // This trailing comma makes auto-formatting nicer for build methods.
......
import 'dart:convert'; import 'dart:convert';
import 'dart:ffi';
import 'package:dio/dio.dart'; import 'package:dio/dio.dart';
import 'package:netrain_flutter_app/zhangfeng/Network/BaseHttpModel.dart'; import 'package:netrain_flutter_app/zhangfeng/Network/BaseHttpModel.dart';
import 'package:netrain_flutter_app/zhangfeng/UserModel.dart'; import 'package:netrain_flutter_app/zhangfeng/UserModel.dart';
......
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