博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

02-13 flutter+mvp

Posted on 2020-11-23 23:39  肖无情  阅读(84)  评论(0编辑  收藏  举报

1、

abstract class CLoginPrenter{

  void loginWithShopCode(String shopCode);

}

abstract class CLoginView  {
  void loginSuccess();

}


abstract class CLoginModel extends IModel{
    void  toLogin( Map<String,dynamic> params, {ResponseSuccess success,ResponseFail fail});
}

p:

class LoginPresenter implements CLoginPrenter{
  CLoginModel cLoginModel;
  CLoginView cLoginView;

  LoginPresenter(CLoginView cLoginView){
    this.cLoginView = cLoginView;
    cLoginModel = LoginModel();
  }


  @override
  void loginWithShopCode(String shopCode) {

    cLoginModel.toLogin(Map(),success: (data){

    },fail: (code,msg){

    }
    );
  }


}

m:

typedef ResponseSuccess (dynamic data);
typedef ResponseFail (int code,String msg);

class LoginModel implements CLoginModel{

  @override
  void toLogin(Map<String, dynamic> params,{ResponseSuccess success,ResponseFail fail}) {

    if(true){
       success("data");
    }
    else{
      fail(1,"data");
    }

  }



}

v

class _FirstLoginPageState extends State<FirstLoginPage> implements CLoginView {


  LoginPresenter loginPresenter ;


  @override
  void initState() {
    super.initState();
    loginPresenter = LoginPresenter(this);
  }

  @override
  void loginSuccess() {

  }
 }

方式2:

abstract class CLoginPrenter{

  void loginWithShopCode(String shopCode);

}

abstract class CLoginView  {
  void loginSuccess();

}


abstract class CLoginModel extends IModel{
    void  toLogin( Map<String,dynamic> params);
}



 class ResponseCallBack {

  responseSuccess(dynamic data, {String msg}){}
  //登录/注册失败
  responseFailed(int code , String msg){}
}

p:

class LoginPresenter implements CLoginPrenter,ResponseCallBack{
  CLoginModel cLoginModel;
  CLoginView cLoginView;

  LoginPresenter(CLoginView cLoginView){
    this.cLoginView = cLoginView;
    cLoginModel = LoginModel(this);
  }


  @override
  void loginWithShopCode(String shopCode) {

    cLoginModel.toLogin(Map());
  }

  @override
  responseFailed(int code, String msg) {
    throw UnimplementedError();
  }

  @override
  responseSuccess(code, {String msg}) {
    throw UnimplementedError();
  }
}

m:

class LoginModel implements CLoginModel{

  ResponseCallBack callBack;

  LoginModel(ResponseCallBack  callBack){
    this.callBack = callBack;

  }
  @override
  void toLogin(Map<String, dynamic> params) {

    if(true){
      callBack.responseSuccess("data");
    }
    else{
      callBack.responseFailed(1,"data");
    }

  }



}

v:同上

方式3:

abstract class CLoginPrenter{

  void loginWithShopCode(String shopCode);

}

abstract class CLoginView  {
  void loginSuccess();

}


abstract class CLoginModel extends IModel{
    void  toLogin( Map<String,dynamic> params,{ResponseCallBack responseCallBack});
}


typedef ResponseSuccess (dynamic data);
typedef ResponseFailed (int code,String msg);
 class ResponseCallBack {

   ResponseSuccess  responseSuccess ;
  //登录/注册失败
   ResponseFailed responseFailed;

  ResponseCallBack({
    this.responseSuccess,
    this.responseFailed,
  });
}
class LoginPresenter implements CLoginPrenter{
  CLoginModel cLoginModel;
  CLoginView cLoginView;

  LoginPresenter(CLoginView cLoginView){
    this.cLoginView = cLoginView;
    cLoginModel = LoginModel();
  }


  @override
  void loginWithShopCode(String shopCode) {

    cLoginModel.toLogin(Map(),
        responseCallBack: ResponseCallBack(
            responseSuccess: (data){

            } ,responseFailed: (code,msg){

        })
    );
  }


}
class LoginModel implements CLoginModel{


  @override
  void toLogin(Map<String, dynamic> params,{ResponseCallBack responseCallBack}) {

    if(true){
      responseCallBack.responseSuccess("data");
    }
    else{
      responseCallBack.responseFailed(1,"data");
    }

  }



}