@JsonSerializable()classLoginEntity{
late int code =0;
late String message ='';
late String token ='';LoginEntity();factoryLoginEntity.fromJson(Map<String,dynamic> json)=> $LoginEntityFromJson(json);Map<String,dynamic>toJson()=> $LoginEntityToJson(this);@overrideStringtoString(){returnjsonEncode(this);}}
2、登录请求
// 登录,返回一个对象staticFuture<LoginEntity>login(String phoneNumber,String phoneCode)async{final url ="login/";final res =awaitHttpRequest.request(url,method:"post",
params:{"phone_number":phoneNumber,"phone_code":phoneCode});// 解决'_Map<String, dynamic>' is not a subtype of type 'FutureOr<LoginEntity>'的报错!!!!!!!!finalMap<String,dynamic> jsonData = res;finalLoginEntity loginEntity =LoginEntity.fromJson(jsonData);return loginEntity;}
3、页面发请求,传递登录接口需要的参数
// 请求登录接口Future_login(String phoneNumber,String phoneCode)async{finalLoginEntity res =awaitLoginRequest.login(phoneNumber, phoneCode);print(res.code);}returnGestureDetector(
onTap:(){// 6、访问父组件的属性,要使用widget.属性print('手机号:${widget.phoneNumberController.text}');print('验证码:${widget.phoneCodeController.text}');_login(widget.phoneNumberController.text,widget.phoneCodeController.text);},