Im-Kevin / cool_ui

用flutter实现一些我认为好看的UI控件,有Popover,仿Weui的Toast,自定义键盘
Apache License 2.0
460 stars 74 forks source link

使用了showWeuiLoadingToast后Navigator.pop就返回不了返回值了 #8

Closed ni-ken closed 5 years ago

ni-ken commented 5 years ago

var hide = showWeuiLoadingToast(context: context, message: Text("请稍后")); await Future.delayed(Duration(seconds: 2)); hide(); Navigator.pop(context, 'Yep');====>这个‘Yep'就返回不到上个页面了

Im-Kevin commented 5 years ago

Toast 不应该有返回值的

:octocat: From gitme iOS

Im-Kevin commented 5 years ago

还有你这个要么在toast 完成前,要么完成后,toast 是占有pop 的

:octocat: From gitme iOS

ni-ken commented 5 years ago

当然不是要返回toast的值,假设有这样的应用场景,页面B做了一些耗时的事后自动返回页面A,这时先显示一个loading toast,然后发个http请求等回应,然后根据回应传递不同参数给下个页面,这时候这样写就会有问题,从流程角度看,有两个pop应该顺序执行,但toast的pop会比页面的pop延迟一帧

Im-Kevin commented 5 years ago

是的,因为我里面做了个回调处理,不是即时相应,我晚点修改一下,返回一个future``

ni-ken commented 5 years ago

我昨天稍微改了下,这样用的 var hide = showWeuiToast();===>返回内部那个future .... await hideWeuiToast(hide);===>这里面等等future完成,调用callback。

另外,如果你用overlay来实现的话,为什么还要push和pop?

Im-Kevin commented 5 years ago

这里是当时做的时候没有直接使用Overlay,之后会改过的,因为也是个摸索的过程

ni-ken commented 5 years ago

嗯嗯。理论上来说toast是和页面无关的,即使页面跳转了,只要toast还活着就能显示。dialog是显示在当前页面的,页面关了dialog也关了。所以toast之类的用overlay会好一点。 非常期待你的修改版本和其他的作品。

Im-Kevin commented 5 years ago

问题已修复,你更新下版本看看

ni-ken commented 5 years ago

谢谢,已使用。 但是又发现一个新问题。当我在进入一个页面时想先展示loading,同时在异步加载数据,我在initState()里调用了showWeuiLoadingToast,结果程序崩溃了

Im-Kevin commented 5 years ago

initState的时候context 是不是还没初始化好

:octocat: From gitme iOS

Im-Kevin commented 5 years ago

如果可以的话我就关掉这个issue

:octocat: From gitme iOS