当前位置:网站首页>[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 .
边栏推荐
- JS common array methods
- Introduction to RFM analysis
- Introduction to MCU peripherals: temperature sensor DS18B20
- 【Flutter 问题系列第 67 篇】在 Flutter 中使用 Get 插件在 Dialog 弹窗中不能二次跳转路由问题的解决方案
- Uni app dynamic add style dynamic bind background image invalid
- Understand the pseudo static configuration to solve the 404 problem of refreshing the page of the deployment project
- MCU: EEPROM multi byte read / write operation sequence
- PAT 1054 The Dominant Color
- Google Chrome browser reports an error: net:: err_ BLOCKED_ BY_ CLIENT
- Cache read / write -- write
猜你喜欢

Single chip microcomputer: infrared remote control communication principle

2019 Blue Bridge Cup

Solution to failure to download files by wechat scanning QR code

MCU: NEC protocol infrared remote controller

Intervention analysis + pseudo regression

Day45. data analysis practice (1): supermarket operation data analysis

电磁兼容常用名词术语

Interpretation of mobile phone private charging protocol

Hugo blog building tutorial

Single chip microcomputer: pcf8591 application program
随机推荐
dumi 搭建文檔型博客
SQL advanced challenge (1 - 5)
MySQL索引
120. 三角形最小路径和-动态规划
2019 Blue Bridge Cup
Advanced Mathematics (Seventh Edition) Tongji University exercises 1-3 personal solutions
Hugo 博客搭建教程
H5 the blue background color appears when clicking the picture
VGA display based on de2-115 platform
剑指 Offer 11. 旋转数组的最小数字-二分查找
Applet waterfall flow
干预分析 + 伪回归
出现Could not find com.scwang.smart:refresh-layout-kernel:2.0.3.Required by: project :app 无法加载第三方包情况
Lightweight digital mall system based on PHP
[kubernetes series] pod chapter actual operation
SQL 进阶挑战(1 - 5)
7-289 tag count (300 points)
Simple static web page + animation (small case)
Uni app enables pull-up loading and pull-down refresh (pull-down with animation)
Uni app dynamic add style dynamic bind background image invalid