From ea2c8205a2744ab6c563b2421cbe60268ecaf14e Mon Sep 17 00:00:00 2001 From: lcy <2503978335@qq.com> Date: Mon, 19 Jun 2023 18:04:38 +0800 Subject: [PATCH] feat:更新代码 --- lib/login/loginpage/bloc/login_bloc.dart | 8 ++++---- lib/login/loginpage/bloc/login_state.dart | 3 ++- lib/models/response_model.dart | 16 ++++++++++++++++ lib/models/response_model.g.dart | 21 +++++++++++++++++++++ lib/models/test_model.dart | 18 ++++++++++++++++++ lib/models/test_model.g.dart | 19 +++++++++++++++++++ lib/modes/response_model.dart | 16 ---------------- lib/modes/response_model.g.dart | 21 --------------------- lib/modes/test_model.dart | 18 ------------------ lib/modes/test_model.g.dart | 19 ------------------- lib/network/network_manager.dart | 5 +++-- 11 files changed, 83 insertions(+), 81 deletions(-) create mode 100644 lib/models/response_model.dart create mode 100644 lib/models/response_model.g.dart create mode 100644 lib/models/test_model.dart create mode 100644 lib/models/test_model.g.dart delete mode 100644 lib/modes/response_model.dart delete mode 100644 lib/modes/response_model.g.dart delete mode 100644 lib/modes/test_model.dart delete mode 100644 lib/modes/test_model.g.dart diff --git a/lib/login/loginpage/bloc/login_bloc.dart b/lib/login/loginpage/bloc/login_bloc.dart index b7bfe0d..323b1a8 100644 --- a/lib/login/loginpage/bloc/login_bloc.dart +++ b/lib/login/loginpage/bloc/login_bloc.dart @@ -42,19 +42,19 @@ class LoginBloc extends Bloc { ///请求登陆 void _requestLoginApi(RequestLoginEvent event, Emitter emitter) async { - DioUtil().requestData( + await DioUtil().requestData( Api.login, + method: HttpMethod.post, data: { 'phoneNum':'17730280759', 'type':_loginType.toString(), 'password':'asd123456'}, successCallBack: (data){ - + emitter(LoginResultChangeState(true)); }, errorCallBack: (error){ - + emitter(LoginResultChangeState(false)); }); - // emitter(LoginResultChangeState()); } ///切换登陆方式 diff --git a/lib/login/loginpage/bloc/login_state.dart b/lib/login/loginpage/bloc/login_state.dart index 42da334..b48e57e 100644 --- a/lib/login/loginpage/bloc/login_state.dart +++ b/lib/login/loginpage/bloc/login_state.dart @@ -14,5 +14,6 @@ class SmsSendTypeChangeState extends LoginState {} class AgreementTypeChangeState extends LoginState {} ///登陆请求结果 class LoginResultChangeState extends LoginState { - + bool result = false; + LoginResultChangeState(this.result); } diff --git a/lib/models/response_model.dart b/lib/models/response_model.dart new file mode 100644 index 0000000..3f891db --- /dev/null +++ b/lib/models/response_model.dart @@ -0,0 +1,16 @@ +import 'package:json_annotation/json_annotation.dart'; + +part 'response_model.g.dart'; + +@JsonSerializable() +class ResponseModel { + int? code; + dynamic data; + String? msg; + + ResponseModel(this.code,this.data,this.msg); + + factory ResponseModel.fromJson(Map json) => _$ResponseModelFromJson(json); + + Map toJson() => _$ResponseModelToJson(this); +} diff --git a/lib/models/response_model.g.dart b/lib/models/response_model.g.dart new file mode 100644 index 0000000..81a714a --- /dev/null +++ b/lib/models/response_model.g.dart @@ -0,0 +1,21 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'response_model.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +ResponseModel _$ResponseModelFromJson(Map json) => + ResponseModel( + json['code'] as int?, + json['data'], + json['msg'] as String?, + ); + +Map _$ResponseModelToJson(ResponseModel instance) => + { + 'code': instance.code, + 'data': instance.data, + 'msg': instance.msg, + }; diff --git a/lib/models/test_model.dart b/lib/models/test_model.dart new file mode 100644 index 0000000..9f6d4a0 --- /dev/null +++ b/lib/models/test_model.dart @@ -0,0 +1,18 @@ +import 'package:json_annotation/json_annotation.dart'; + +part 'test_model.g.dart'; + +@JsonSerializable() +class TestModel { + @JsonKey(name: 'test_name') + String? name; + @JsonKey(defaultValue: '男') + String? sex; + int? age; + + TestModel({this.name,this.sex,this.age}); + + factory TestModel.fromJson(Map json) => _$TestModelFromJson(json); + + Map toJson() => _$TestModelToJson(this); +} \ No newline at end of file diff --git a/lib/models/test_model.g.dart b/lib/models/test_model.g.dart new file mode 100644 index 0000000..2c80e8c --- /dev/null +++ b/lib/models/test_model.g.dart @@ -0,0 +1,19 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'test_model.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +TestModel _$TestModelFromJson(Map json) => TestModel( + name: json['test_name'] as String?, + sex: json['sex'] as String? ?? '男', + age: json['age'] as int?, + ); + +Map _$TestModelToJson(TestModel instance) => { + 'test_name': instance.name, + 'sex': instance.sex, + 'age': instance.age, + }; diff --git a/lib/modes/response_model.dart b/lib/modes/response_model.dart deleted file mode 100644 index 3f891db..0000000 --- a/lib/modes/response_model.dart +++ /dev/null @@ -1,16 +0,0 @@ -import 'package:json_annotation/json_annotation.dart'; - -part 'response_model.g.dart'; - -@JsonSerializable() -class ResponseModel { - int? code; - dynamic data; - String? msg; - - ResponseModel(this.code,this.data,this.msg); - - factory ResponseModel.fromJson(Map json) => _$ResponseModelFromJson(json); - - Map toJson() => _$ResponseModelToJson(this); -} diff --git a/lib/modes/response_model.g.dart b/lib/modes/response_model.g.dart deleted file mode 100644 index 81a714a..0000000 --- a/lib/modes/response_model.g.dart +++ /dev/null @@ -1,21 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'response_model.dart'; - -// ************************************************************************** -// JsonSerializableGenerator -// ************************************************************************** - -ResponseModel _$ResponseModelFromJson(Map json) => - ResponseModel( - json['code'] as int?, - json['data'], - json['msg'] as String?, - ); - -Map _$ResponseModelToJson(ResponseModel instance) => - { - 'code': instance.code, - 'data': instance.data, - 'msg': instance.msg, - }; diff --git a/lib/modes/test_model.dart b/lib/modes/test_model.dart deleted file mode 100644 index 9f6d4a0..0000000 --- a/lib/modes/test_model.dart +++ /dev/null @@ -1,18 +0,0 @@ -import 'package:json_annotation/json_annotation.dart'; - -part 'test_model.g.dart'; - -@JsonSerializable() -class TestModel { - @JsonKey(name: 'test_name') - String? name; - @JsonKey(defaultValue: '男') - String? sex; - int? age; - - TestModel({this.name,this.sex,this.age}); - - factory TestModel.fromJson(Map json) => _$TestModelFromJson(json); - - Map toJson() => _$TestModelToJson(this); -} \ No newline at end of file diff --git a/lib/modes/test_model.g.dart b/lib/modes/test_model.g.dart deleted file mode 100644 index 2c80e8c..0000000 --- a/lib/modes/test_model.g.dart +++ /dev/null @@ -1,19 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'test_model.dart'; - -// ************************************************************************** -// JsonSerializableGenerator -// ************************************************************************** - -TestModel _$TestModelFromJson(Map json) => TestModel( - name: json['test_name'] as String?, - sex: json['sex'] as String? ?? '男', - age: json['age'] as int?, - ); - -Map _$TestModelToJson(TestModel instance) => { - 'test_name': instance.name, - 'sex': instance.sex, - 'age': instance.age, - }; diff --git a/lib/network/network_manager.dart b/lib/network/network_manager.dart index c95f893..c34fc78 100644 --- a/lib/network/network_manager.dart +++ b/lib/network/network_manager.dart @@ -3,9 +3,9 @@ import 'dart:io'; import 'package:dio/dio.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter_easyloading/flutter_easyloading.dart'; +import 'package:wow_english/models/response_model.dart'; import 'package:wow_english/network/basic_configuration.dart'; -import '../modes/response_model.dart'; enum HttpMethod { get, @@ -37,12 +37,13 @@ class DioUtil { Future requestData( String path, { data, - HttpMethod method = HttpMethod.post, + // HttpMethod method = HttpMethod.post, Map? queryParameters, ProgressCallback? onSendProgress, ProgressCallback? onReceiveProgress, required Function successCallBack, required Function errorCallBack, + required HttpMethod method, }) async{ try { Map headers = {}; -- libgit2 0.22.2