Giter VIP home page Giter VIP logo

Comments (8)

simplezhli avatar simplezhli commented on May 20, 2024

首先如果是这种串联的请求接口,建议第一个及中间的接口isClose设为false,将关闭dialog的工作交给最后一个请求的接口。这样可以避免不断的弹出关闭dialog。至于dialog在这种场景不关闭的情况,我明天在测试一下,后面回复你。

from flutter_deer.

MeDeity avatar MeDeity commented on May 20, 2024

首先如果是这种串联的请求接口,建议第一个及中间的接口isClose设为false,将关闭dialog的工作交给最后一个请求的接口。这样可以避免不断的弹出关闭dialog。至于dialog在这种场景不关闭的情况,我明天在测试一下,后面回复你。

好的,谢谢大佬,如果需要,我明天也可以做个demo

from flutter_deer.

simplezhli avatar simplezhli commented on May 20, 2024

@MeDeity 我并没有成功复现出问题,你还是提供一下问题的demo吧。

from flutter_deer.

MeDeity avatar MeDeity commented on May 20, 2024

@simplezhli
测试Demo
页面跳转: 测试首页:LoginNormal
该页面有调用mvp->presenter->LoginNormalPresenter类的requestLogin,

class LoginNormalPresenter extends BasePagePresenter<LoginNormalState>{


  requestLogin(Function(UserDetailEntity data) callback) {
    requestNetwork<LoginItemEntity>(
      Method.post,
//      isShow: false,
      url: Api.user_login,
      onSuccess: (data){
        print("登录成功:$data");
        requestUserDetail(callback);
      },
    );
  }

  /// 接口请求例子
  /// get请求参数queryParameters  post请求参数params
  void requestUserDetail(Function(UserDetailEntity data) callback){
    requestNetwork<UserDetailEntity>(Method.get,
      url: Api.get_user_detail,
//      isShow: false,
      onSuccess: (data){
        print("获取登录用户信息参数成功:$data");
        callback(data);
      },
    );
  }
}

当执行成功后会跳转到Index页面

  void _login(){
//    FlutterStars.SpUtil.putString(PrefKey.phone, _nameController.text);
    presenter.requestLogin((data){
      AppNavigator.push(context, Index());
    });
  }
  
   Widget _buildContent() {
    return Scaffold(
      appBar: AppBar(
        title: Text("仿登录页面"),
      ),
      body: Column(
        children: <Widget>[
          Text("点击按钮执行登录请求->获取用户信息->跳转到Index页面"),
          FlatButton(
            onPressed: () {
              _login();
            },
            child: Text("模拟登录"),
          )
        ],
      ),
    );
  }

以上: dialog 无法自动关闭,并且无法跳转到Index页面.
log:

07-29 09:54:59.383 26992-27043/com.example.test_dialog I/flutter: DEBUG->开启dialog
07-29 09:54:59.922 26992-27043/com.example.test_dialog I/flutter: DEBUG->关闭dialog
07-29 09:54:59.923 26992-27043/com.example.test_dialog I/flutter: DEBUG->开启dialog
07-29 09:55:00.410 26992-27043/com.example.test_dialog I/flutter: DEBUG->关闭dialog

from flutter_deer.

simplezhli avatar simplezhli commented on May 20, 2024

@MeDeity 问题找到了,你关闭dialog使用的是 Navigator.maybePop(context);方法,它是一个Future方法,内部并没有马上调用pop方法,而是等待willPop方法的返回结果。由于我对Dialog做了WillPopScope的拦截并返回了true导致maybePop无法执行成功,使用Navigator.pop(context);不会有问题。

from flutter_deer.

MeDeity avatar MeDeity commented on May 20, 2024

@simplezhli 谢谢大神,我更改成Navigator.pop(context),确实恢复正常了.
但我发现好像不是因为WillPopScope引起的,我尝试将WillPopScope注释,然后发现,Navigator.maypop(context)仍无法关闭dialog.

  @override
  void showProgress() {
    /// 避免重复弹出
    print("DEBUG->开启dialog");
    if (mounted && !_isShowDialog){
      _isShowDialog = true;
      try{
        showTransparentDialog(
            context: context,
            barrierDismissible: false,
            builder:(_) {
              return ProgressDialog(hintText: "正在加载...");
//              return WillPopScope(
//                onWillPop: () async {
//                  // 拦截到返回键,证明dialog被手动关闭
//                  _isShowDialog = false;
//                  return Future.value(true);
//                },
//                child: ProgressDialog(hintText: "正在加载..."),
//              );
            }
        );
      }catch(e){
        /// 异常原因主要是页面没有build完成就调用Progress。
        print(e);
      }
    }
  }

from flutter_deer.

simplezhli avatar simplezhli commented on May 20, 2024

我整个来梳理一遍,因为使用了maybePop,所以真正执行pop方法并不是实时的。所以顺序大致是:
show --> close --> show -->真正关闭第一个doalog--> close --> 跳转页面 --> 关闭第二个dialog(由于页面跳转导致页面关闭,第二个dialog没有关闭成功)

from flutter_deer.

MeDeity avatar MeDeity commented on May 20, 2024

谢谢百忙中给予指导,虽然原理上还不太明白,但总体确定是maybePop的实时性问题.问题我关闭了,再次表示感谢!

from flutter_deer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.