当前位置:网站首页>[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 .
边栏推荐
- [sword finger offer] interview question 25 Merge two ordered linked lists
- Interpretation of mobile phone private charging protocol
- Webpack system learning (VIII) how contenthash can prevent browsers from using cache files
- MySQL索引
- PAT 1054 The Dominant Color
- SCM: introduction to Modbus communication protocol
- Notes on uni app
- Lenovo notebook computer uses the insert key. When the mouse becomes a small square, how to solve it
- Applet waterfall flow
- Interpretation of usb-if bc1.2 charging protocol
猜你喜欢
Reread the classic: end to end object detection with transformers
Sword finger offer II 022 Entry node of a link in a linked list
2019 Blue Bridge Cup
Dumi builds a document blog
Single chip microcomputer: MODBUS multi computer communication program design
Single chip microcomputer: basic concepts of a/d and d/a
leetcode. 1 --- sum of two numbers
史上最详细的Swin-Transformer 掩码机制(mask of window attentation)————shaoshuai
Introduction to MCU peripherals: temperature sensor DS18B20
Small program imitating Taobao Jiugong grid sliding effect
随机推荐
Unity Shader 学习 004-Shader 调试 平台差异性 第三方调试工具
Redis-HyperLogLog-基数统计算法
Understand the pseudo static configuration to solve the 404 problem of refreshing the page of the deployment project
Interpretation of usb-if bc1.2 charging protocol
Configuration and practice of shardingsphere JDBC sub database separation of read and write
Single chip microcomputer: main index of a/d (analog-to-digital conversion)
Message scrolling JS implementation
Solve the problem of running server nodemon reporting errors
Real time requirements for 5g China Unicom repeater network management protocol
Data analysis report
120. 三角形最小路径和-动态规划
XOR prefix and +map maintenance
力扣刷题338.比特位计数
环评图件制作-数据处理+图件制作
10 minutes to thoroughly understand how to configure sub domain names to deploy multiple projects
Single chip microcomputer: d/a output
Intervention analysis + pseudo regression
Solution to failure to download files by wechat scanning QR code
出现Could not find com.scwang.smart:refresh-layout-kernel:2.0.3.Required by: project :app 无法加载第三方包情况
SCM signal generator program