当前位置:网站首页>[chapter 67 of the flutter problem series] the solution to the problem that the get plug-in cannot jump to the route twice in the dialog pop-up window in flutter
[chapter 67 of the flutter problem series] the solution to the problem that the get plug-in cannot jump to the route twice in the dialog pop-up window in flutter
2022-06-13 04:26:00 【Allen Su】
This is a 【Flutter Question Series No 67 piece 】, If it works , Welcome to the column .
For blog posts Flutter SDK:2.2.3,Dart SDK:2.13.4,get: 4.3.8.
List of articles
One : Problem description
A problem discovered by chance before , It is hereby recorded that .
When it was put on the shelves of Xiaomi store , It is reported that there should be a pop-up window of privacy agreement when the user enters the application for the first time , Then I added one , Click on 《 User agreement 》 Can also jump to the corresponding Web page , I thought it would be a success , As shown in the figure below

I happened to be testing , When I first popped up in the pop-up window , Clicking the link for the first time can jump normally , sign out Web There is no response when the page is clicked again , Why is that ?
Breakpoint debugging , Found the root of the problem .
Two : Solution
Set up Get.toNamed() Properties of method preventDuplicates by false that will do , As shown in the following code
/// Jump to 《 User agreement 》 Webpage
void _toAgreementPage() {
Get.toNamed(
AppRoutes.WEB,
arguments: WebModel(title: "《 User agreement 》", url: agreementUrl, isLocal: false),
preventDuplicates: false, // “ Prevent duplication ” Set to false
);
}
Then the problem is solved , This is not only for Dialog, Also suitable for Snackbar、BottomSheet Methods such as .
3、 ... and : Source code analysis 《 How to solve Dialog Pop up the problem of the second jump route exception 》
Some students like to break the casserole and ask the truth , Want to know that the problem is solved , But why ? Let's start with source code analysis .
First, let's take a look at... Through breakpoint debugging Get.toNamed() Method source code , As shown in the figure below
It can be seen from the picture that ,toNamed() The comment above the method means
- By default ,GetX It will prevent you from jumping to the route you have entered .
- If you want to lift this restriction , Set properties preventDuplicates by false that will do .
From the location of the breakpoint , here preventDuplicates by true, Can enter this judgment again , explain page == currentRoute The conditions also hold , That is to say, the current route to jump is the route that has been entered .
Method returns null , So in Dialog Click the link again to jump Web There is no response when the page .
We just need to set preventDuplicates by false, The conditions are broken , Nature enters into the later judgment .
Four : Source code analysis 《 Why is there no such problem in the page Dialog In the pop-up window 》
One : When the route is stacked
Let's look at a class first GetObserver
, This class inherits from NavigatorObserver
class , The function is to monitor page Jump . As usual Toast And so on will inherit this class , GetObserver
The source code of the class is shown in the following figure
When I click 《 User agreement 》 Link to Web Page time , From the selected part of the red box , Only PageRoute The current route can only be modified if it is of type current Value of field , So it will be updated at this time .
That's why from Dialog There is no problem when the pop-up window enters the new page .
Two : When the route is out of the stack
As shown in the figure below
When I click Web When the back button of the page exits the current page , From the selected part of the red box , Only PageRoute The current route can only be modified if it is of type current Value of field , And we are from Dialog Pop up window , The type of the previous page is GetDialogRoute, Does not satisfy the update current Conditions .
So although we did quit Web page , But this time current The value of has not been updated , still /web
, That is to say, what the eyes see is a pop-up window , But the program thinks you're Web page , This leads to the problem that the same page cannot be skipped .
thus , About the Flutter Use in Get Plug in Dialog In the pop-up window, you cannot jump the route twice , That's it .
Last one get The class that determines the current route type , As shown in the figure below
It can be seen from the picture that
- Dialog The type is GetDialogRoute, Inherited from PopupRoute.
- Snackbar The type is SnackRoute, Inherited from OverlayRoute.
- BottomSheet The type is GetModalBottomSheetRoute, Inherited from PopupRoute.
- Page The type is GetPageRoute, Inherited from PageRoute.
Has your problem been solved ? Feel free to leave a comment in the comments section .
A gift of rose , Fragrance in hand , If you think the article is good , I hope you can give me one button three times , thank .
Google Of Flutter More and more fire , end 2022 year 6 month 10 Japan GitHub Target star has reached 142K,Flutter Determination is a trend , So as a front-end Developer , There is no reason not to study as soon as possible .
Conclusion
No matter you are Flutter Novices are still getting started , You might as well pay attention to , In the future, I will Flutter Common components in ( Contains source code analysis 、 Usage and precautions of components ) As well as possible problems CSDN Blog , I hope I can learn at the same time , It can also help more people .
边栏推荐
- 建模雜談系列143 數據處理、分析與决策系統開發的梳理
- 5g China Unicom ap:b SMS ASCII transcoding requirements
- Call C function in Lua
- Milliards de données pour déterminer si un élément existe
- Checkmarks and crosses to collect
- 【自动化测试】关于unittest你需要知道的事
- H5 the blue background color appears when clicking the picture
- Configuration and practice of shardingsphere JDBC sub database separation of read and write
- Real time requirements for 5g China Unicom repeater network management protocol
- 1-72 convert string to decimal integer
猜你喜欢
Dumi builds a document blog
【自动化测试】关于unittest你需要知道的事
出现Could not find com.scwang.smart:refresh-layout-kernel:2.0.3.Required by: project :app 无法加载第三方包情况
Single chip microcomputer: basic concepts of a/d and d/a
10 minutes to thoroughly understand how to configure sub domain names to deploy multiple projects
dumi 搭建文档型博客
Uni app dynamic add style dynamic bind background image invalid
knife4j aggregation 2.0.9支持路由文档自动刷新
ET框架-22 创建ServerInfo实体及事件
Knife4j aggregation 2.0.9 supports automatic refresh of routing documents
随机推荐
EMC rectification outline
Configuration and practice of shardingsphere JDBC sub database separation of read and write
电磁兼容常用名词术语
Dumi construit un blog documentaire
【自动化测试】关于unittest你需要知道的事
7-289 tag count (300 points)
高等数学(第七版)同济大学 习题1-3 个人解答
Understand the pseudo static configuration to solve the 404 problem of refreshing the page of the deployment project
Applet waterfall flow
Et framework -22 creating serverinfo entities and events
H5 the blue background color appears when clicking the picture
Detailed explanation of KOA development process
web自动化测试之webdriver api总结
120. triangle minimum path sum - Dynamic Planning
UE4 learning notes - functions of terrain tool
Introduction and use of ES6
【Flutter 问题系列第 67 篇】在 Flutter 中使用 Get 插件在 Dialog 弹窗中不能二次跳转路由问题的解决方案
PAT 1054 The Dominant Color
Time format method on the official demo of uniapp
2019 Blue Bridge Cup