• 02-13 flutter+mvp


    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");
        }
    
      }
    
    
    
    }
    
  • 相关阅读:
    jQuery
    基于Js实现的UrlEncode和UrlDecode函数代码
    利用缓存、Timer间隔时间发送微信的实例,很有用的例子
    VisualStudio 自动排版等 快捷键
    正则表达式判断手机号码属于哪个运营商
    .Net常用方法汇总
    .NET中的三种Timer的区别和用法
    C# List和String互相转换
    Tempdb--TempDB Basic
    Tempdb--查看tempdb使用的脚本
  • 原文地址:https://www.cnblogs.com/xiaowuqing/p/14028007.html
Copyright © 2020-2023  润新知