多个WillPopScope?

时间:2019-12-04 19:11:59

标签: flutter dart flutter-layout flutter-test

这是我的应用程序的场景: 启动屏幕 -> 登录屏幕 -> 主屏幕

我的登录屏幕主屏幕中都有WillPopScope

如果用户已成功登录,我将使用:

Navigator.push(
          context, MaterialPageRoute(builder: (context) => HomeScreen()));

我遇到的问题是,我现在处于主屏幕中,但是当我尝试按手机的后退按钮时,登录屏幕中的WillPopScope 而不是主屏幕吗?

我是新手,我对此简单的逻辑感到困惑。请帮忙。

2 个答案:

答案 0 :(得分:1)

登录屏幕中时,您需要从堆栈弹出登录屏幕,然后将主屏幕推入其中。您可以执行以下操作:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<!-- Deutsches Format dd.mm.yyyy -->
<script language="JavaScript" src="calendar_de.js"></script><!-- Datum mit Jahresauswahlmoeglichkeit -->
<!-- Englisches Format mm/dd/yyyy -->
<script language="JavaScript" src="calendar_en.js"></script><!-- Datum mit Jahresauswahlmoeglichkeit -->
<LINK REL="STYLESHEET" media="screen" TYPE="text/css" HREF="__default.css">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Auswahl</title>

</head>
<script type="text/javascript">
function absenden(feldname)
{
document.CheckForm.FKT.value = feldname;
if ("SUBMITREP" == feldname) {
document.CheckForm.SUBTYP.value="SUBANDREP";
}
document.CheckForm.submit();
document.CheckForm.ANZB.value="";
}

function enableBtn(wert) {
if (wert > 0) {
document.CheckForm.btn_submit_repair.disabled=false;
}
else {
document.CheckForm.btn_submit_repair.disabled=true;
}
}

function Auswahl_link(){
var vLink = document.getElementById("link");
var vNameNr = document.getElementById("Name");
var vMin = 0;

// Link in Grossbuchstaben umwandeln
vLink.value = vLink.value.toUpperCase();
// bei 'ESC' Popup schließen
if(window.event.keyCode == 27) {
top.document.getElementById("IFRAME").style.visibility = "hidden";
return;
}


// Workaround für fehlerhaftes Encoding von Umlauten beim ersten Aufruf
if (vLink.value.length > vMin-1) {
window.IFRAME.location.href = "PopupLink.jsp?LINK="+vLink.value+
"&LANG=de"+
"&Name=G"+
"&Ort="+"B".replace("%","%25")+
"&Gliederung="+document.HauptForm.Gliederung.value.replace("%","%25")+
"&Name="+vNameNr.value.replace("%","%25")+
"&SORT1=1"+
"&Mandat=Bereich";
}
if (vLink.value.length > vMin) {
var Element = document.getElementById("link");
var x=0, y=0;
var pos=0;
while (Element) {
x = x + Element.offsetLeft;
y = y + Element.offsetTop;
Element = Element.offsetParent;
}
document.getElementById("IFRAME_DIV").style.top = y + 25;
document.getElementById("IFRAME_DIV").style.left = x;
document.getElementById("IFRAME").width = 700;
document.getElementById("IFRAME").height = 200;
document.getElementById("IFRAME").style.backgroundColor = 'white';
document.getElementById("IFRAME").style.visibility = "visible";
} else {
document.getElementById("IFRAME").style.visibility = "hidden";
}
}

function Auswahl_NameNr(){
var vNameNr = document.getElementById("Name");
var vMin = 0;

// Link in Grossbuchstaben umwandeln
vNameNr.value = vNameNr.value.toUpperCase();
// bei 'ESC' Popup schließen
if(window.event.keyCode == 27) {
top.document.getElementById("IFRAME").style.visibility = "hidden";
return;
}


if (vNameNr.value.length > vMin-1) {
window.IFRAME.location.href = "PopupNameNr.jsp?NAMEANR="+vNAMENr.value.replace("%","%25")+
"&LANG=de"+
"&Name=G"+
"&Ort="+"B".replace("%","%25")+
"&Gliederung="+"%".replace("%","%25")+
"&SORT1=1"+
"&Mandat=Bereich";
}
if (vNameNr.value.length > vMin) {
var Element = document.getElementById("NAME");
var x=0, y=0;
var pos=0;
while (Element) {
x = x + Element.offsetLeft;
y = y + Element.offsetTop;
Element = Element.offsetParent;
}
document.getElementById("IFRAME_DIV").style.top = y + 25;
document.getElementById("IFRAME_DIV").style.left = x;
document.getElementById("IFRAME").width = 300;
document.getElementById("IFRAME").height = 200;
document.getElementById("IFRAME").style.backgroundColor = 'white';

document.getElementById("IFRAME").style.visibility = "visible";
} else {
document.getElementById("IFRAME").style.visibility = "hidden";
}
}

function Auswahl(){
if (document.getElementById("IFRAME").height == 125 && document.getElementById("IFRAME").style.visibility == "visible"){
document.getElementById("IFRAME").style.visibility = "hidden";
}
else {
window.IFRAME.location.href = "PopupAuswahl.jsp?MANDAT=Bereich"+
"&ORT="+document.HauptForm.ORT.options[document.HauptForm.ORT.selectedIndex].text.replace("%","%25")+
"&GLIEDERUNG="+document.HAUPTForm.GLIEDERUNG.value.replace("%","%25");

var Element = document.HauptForm.GLIEDERUNG;
var x=0, y=0;
while (Element) {
x = x + Element.offsetLeft;
y = y + Element.offsetTop;
Element = Element.offsetParent;
}
document.getElementById("IFRAME_DIV").style.top = y + 16;
document.getElementById("IFRAME_DIV").style.left = x;
document.getElementById("IFRAME").width = 160;
document.getElementById("IFRAME").height = 125;
document.getElementById("IFRAME").style.backgroundColor = 'white';
document.getElementById("IFRAME").style.visibility = "visible";
}
}

function Auswahl_BELinkNr(){
var vBELinkNr = document.getElementById("belinknnr");
var vMin = 0;

// Link in Grossbuchstaben umwandeln
vBELinkNr.value = vBELinkNr.value.toUpperCase();
// bei 'ESC' Popup schließen
if(window.event.keyCode == 27) {
top.document.getElementById("IFRAME").style.visibility = "hidden";
return;
}


if (vBELinkNr.value.length > vMin) {
window.IFRAME.location.href = "PopupBELinknNr.jsp?BELINKNR="+vBELinkNr.value.replace("%","%25")+
"&BTGRP="+"%".replace("%","%25")+
"&BTKLA="+"%".replace("%","%25")+
"&MANDAT=Bereich";
var Element = document.getElementById("belinknr");
var x=0, y=0;
var pos=0;
while (Element) {
x = x + Element.offsetLeft;
y = y + Element.offsetTop;
Element = Element.offsetParent;
}
document.getElementById("IFRAME_DIV").style.top = y + 25;
document.getElementById("IFRAME_DIV").style.left = x ;
document.getElementById("IFRAME").width = 700;
document.getElementById("IFRAME").height = 200;
document.getElementById("IFRAME").style.backgroundColor = 'white';

document.getElementById("IFRAME").style.visibility = "visible";
} else {
document.getElementById("IFRAME").style.visibility = "hidden";
}
}
</script>

<body onLoad="javascript:document.CheckForm.PDAT.focus();">

<div id="IFRAME_DIV" style="position:absolute;z-index:2;visibility:hidden;">
<iframe src="JavaScript:void(0);" id="IFRAME" name="IFRAME" width="650" height="200" marginheight="0" marginwidth="0" align="middle" scrolling="yes">
</iframe>
</div>

<!-- ===== top navigation ===== -->
<div style="position:absolute;top:0;left:0;">
<TABLE border="0" height="100%" width="100%" cellspacing="0" cellpadding="0">
<TR ALIGN="center" NOWRAP bgcolor="#336699" height="1%">
<TD align="right" rowspan="3" width="1%">
<A HREF="Prozess.COMMON.SHOW" onMouseOver="document.keyvisual.src='img/key-visual_light.gif';" onMouseOut="document.keyvisual.src='img/key-visual.gif';">
<IMG SRC="img/key-visual.gif" name="keyvisual" border="0" width="144" height="83">
</A>
</TD>
<TD width="1%"></TD>
<TD ALIGN="left" style="color:#FFFFFF;"><nobr>Sprache</nobr></TD>
<TD ALIGN="left" style="color:#FFFFFF;"><nobr>Ort</nobr></TD>
<TD ALIGN="left" style="color:#FFFFFF;"><nobr>Name</nobr></TD>
<TD ALIGN="left" style="color:#FFFFFF;"><nobr>Gerät</nobr></TD>
<TD ALIGN="left" style="color:#FFFFFF;"><nobr>Prozess</nobr></TD>
<TD ALIGN="left" style="color:#FFFFFF;"><nobr>Sortierung</nobr></TD>
<TD ALIGN="left" style="color:#FFFFFF;"><nobr>&nbsp</nobr></TD>
<TD ALIGN="left" style="color:#FFFFFF;"><nobr>&nbsp</nobr></TD>
<TD width="1%"></TD>
</TR>
<TR ALIGN="center" NOWRAP bgcolor="#336699" height="1%">
<form name="ArbeitsplatzForm" action=/delta-beleg/HauptContro.jsp method=post>
<TD></TD>
<TD align="left" valign="top" NOWRAP>
<select name="LANG" size="1">
<option selected value="de" >Deutsch</option>
<option value="en" >Englisch</option>
</select>
</TD>
<TD align="left" valign="top" NOWRAP>
<SELECT name="BEREICH" size="1">
<OPTION>%</OPTION>
<OPTION>A</OPTION>
<OPTION selected>B</OPTION>
<OPTION>C</OPTION>
<OPTION>nn</OPTION>
</SELECT>
&nbsp;</TD>
<TD align="left" valign="top" NOWRAP>
<span style="position:relative;top:-6px;left:0px;"><INPUT readonly onClick="Auswahl_Gliederung();" name="GLIEDERUNG" id="FAGRU" type="text" value="%" size="21"/><IMG onClick="Auswahl_Gliederung();" src="img/DropDown.gif" height="22" width="18" style="position:relative;top:5px;left:-1px;"/>&nbsp;</span> </TD>
<TD align="left" valign="top" NOWRAP>
<INPUT type="text" name="NAME" id="NAME" onKeyUp="Auswahl_NameNr();" value="%" size="21"/> </TD>
<TD align="left" valign="top" NOWRAP>
<select name="NAME" size="1">
<option value="fp" >Prozess1</option>
<option value="fr" >Prozess2</option>
<option value="bp" >Prozess3</option>
<option value="br" >Prozess4</option>
<option selected value="gp" >Prozess5</option>
<option value="gr" >Prozess6</option>
<option value="rf" >Prozess7</option>
</select>
</TD>
<TD align="left" valign="top" NOWRAP>
<select name="SORT1" size="1">
<option selected value="1" >NAME, Nr, Index</option>
<option value="2" >Nr, Index, Name</option>
</select>
</TD>
<TD align="left" valign="top" NOWRAP>
&nbsp
</TD>
<TD align="left" valign="top" NOWRAP>
<input type="submit" value="Absenden">
</TD>
<TD ALIGN="left" width="50"></TD>
</FORM>
</TR>
<TR ALIGN="center" NOWRAP height="1%" bgcolor="#99CCFF">
<TD colspan="6" align="right" nowrap="nowrap"></TD>
<TD colspan="2" align="left" nowrap="nowrap">Benutzer</TD>
<TD align="left" nowrap="nowrap">
<nobr>&nbsp;</nobr><A HREF="LoginForm.jsp" class="navigation">logout</A>
</TD>
<TD ALIGN="left" width="50"></TD>
</TR>
</TABLE>
</div>
<!-- ===== END - top navigation ===== -->
<!-- ===== left navigation ===== -->
<div style="position:absolute;top:83;left:0;z-index:0;">
<TABLE width="144" height="445" bgcolor="#99CCFF">
<TR>
<TD></TD>
</TR>
</TABLE>
</div>
<div style="position:absolute;top:83;left:0;">
<TABLE border="0" width="144" height="41" bgcolor="#336699" cellspacing="0" cellpadding="0">
<TR bgcolor="#336699">
<TD>&nbsp;</TD>
<TD align="LEFT" style="color:#FFFFFF;font-weight:bold;">DELTA-<br> FER</TD>
</TR>
</TABLE>
</div>
<!-- ===== inner page ===== -->
<div style="position:absolute;top:86;left:144;">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td width="300" align=left valign=bottom>
<img src="img/chip_01.jpg" width=300 height=24 border=0>
</td>
<td align="left" valign="bottom" style="FONT-FAMILY:Arial;FONT-SIZE:18px;font-weight:bold;COLOR:#000000;">Geräte-Prüfung</td>
<td align="right" valign="bottom"><a href="./help.htm">
<img src="img/icohelp1.gif" width=24 height=20 border=0 alt="Hilfe"></a>
</td>
</tr>
<tr>
<td colspan=3 align=left bgcolor=#0000ff>
<img src="img/1x1.gif" width=1 height=1 border=0>
</td>
</tr>
</table>
<table ALIGN="CENTER" width="100%">
<TR>
<TD WIDTH="1%" colspan="2"></TD>
</TR>
</TABLE>
<!-- ===== START - Anwendungsbereich ===== -->
<form name="CheckForm" action="/delta-beleg/CheckContro.jsp" method=post width="500" autocomplete="off">
<center>
<table cellpadding=4 cellspacing=2 border=0>

<tr bgcolor="#c8d8f8">
<td valign=top colspan=2>
<b>Pruefdatum</b>
<br>
<input type="text" name="PDAT" size=10 value="" maxlength=10><a href="javascript:cal1.popup();"><img src="img/cal.gif" width="16" height="16" border="0" alt="Click Here to Pick up the date"></a>
<script language="JavaScript">
function setHeute(){
var jetzt = new Date();
var Tag = jetzt.getDate()<10?"0"+jetzt.getDate():jetzt.getDate();
var Monat = jetzt.getMonth()+1<10?"0"+(jetzt.getMonth()+1):(jetzt.getMonth()+1);
var Jahr = jetzt.getFullYear();

var txt = Tag+"."+Monat+"."+Jahr;

document.getElementsByName("PDAT")[0].value = txt;
}
</script>
&nbsp;&nbsp;<a href="JavaScript:setHeute();" style="font-size:10px;text-decoration:none;color:#000000;cursor:hand;">[heute]</a>
</td>
</tr>

<tr bgcolor="#c8d8f8">
<td valign=top colspan=2>
<b>Gerät / Gerät St</b>
<br>
<input type="text" name="LINK" id="link" size="70" value="" onKeyUp="Auswahl_Link();">
</td>
</tr>



<tr bgcolor="#c8d8f8">
<td valign=top colspan=2>
<b>Plan</b>
<br>
<SELECT name="PLALT" size="1" null>
<OPTION selected value="-" >-, -</OPTION>
</SELECT>
</td>
</tr>
<tr bgcolor="#c8d8f8">
<td valign=top colspan=2>
<b>Anzahl geprueft</b>
<br>
<input type="text" name="ANZG" size=10 value="" maxlength=10></td>
</tr>

<tr bgcolor="#c8d8f8">
<td valign=top colspan=2>
<b>Anzahl beanstandet</b>
<br>
<input type="text" name="ANZB" size=10 value="" maxlength=10 onkeyup="enableBtn(this.value)">
</td>
</tr>

<!--
<tr bgcolor="#c8d8f8">
<td valign=top colspan=2>
<b>%= Translator.getTranslation(Constants.CHECKFORM_ANZ_REPARIERT, lang) %></b>
<br>
<input type="text" name="%=Constants.PARA_ANZ_REPARIERT %>" size=10 value="" maxlength=10>
</td>
</tr>
-->



<tr bgcolor="#c8d8f8">
<td align=center colspan=2>
<input type="button" value="Speichern" onClick="absenden('SUBMIT')">
<input type="button" name="btn_submit_repair" value="Speichern" onClick="absenden('SUBMITREP')">
<input type="button" value="Zurücksetzen" onClick="absenden('CLEAR')">

</td>
</tr>

</table>
<input type="hidden" name="FKT" value="">
<input type="hidden" name="SUBTYP" value="">
</center>
</form>

<!-- ===== END - Anwendungsbereich ===== -->
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td colspan="3" align=left bgcolor=#0000ff>
<img src="img/1x1.gif" width=1 height=1 border=0>
</td>
</tr>
<tr>
<td align="left" valign="top" width="1%">
<img src="img/chip_01b.jpg" width="300" height="23" border="0">
</td>
<td align="left" valign="bottom">&nbsp;</td>
<td align="right" valign="bottom">
<SCRIPT LANGUAGE='JavaScript'> jetzt = new Date(); Std = jetzt.getHours(); Min = jetzt.getMinutes(); Tag = jetzt.getDate(); Jahr = jetzt.getYear();
if(Jahr < 100) Jahr+=1900; Jahresmonat = jetzt.getMonth(); var Monat = new Array("Jan","Feb","M&auml;r","Apr","Mai","Jun","Jul","Aug","Sep","Okt","Nov","Dez");
var StdAusgabe = ((Std < 10) ? "0" + Std : Std); var MinAusgabe = ((Min < 10) ? "0" + Min : Min);
document.write("<span style='color:#000000;font-size:10px;font-family:Arial,sans-serif;'>Stand: " + Tag+ "." + Monat[Jahresmonat] + "." + Jahr + " " + StdAusgabe + ":" + MinAusgabe + " Uhr" + "&nbsp;</span><br/>");</SCRIPT>
<span style="FONT-FAMILY:Arial;FONT-SIZE:12px;font-weight:900;COLOR:#000055;">---&nbsp;</span>
</td>
</tr>
</table>
</div>
<script language="JavaScript">
<!-- // create calendar object(s) just after form tag closed
// specify form element as the only parameter (document.forms['formname'].elements['inputname']);
// note: you can have as many calendar objects as you need for your application
var cal1 = new calendar_de(document.forms['CheckForm'].elements['PDAT']);
cal1.year_scroll = true;
cal1.time_comp = false;
//-->
</script>

</body>
</html>

答案 1 :(得分:0)

在登录屏幕中,在呼叫主屏幕前添加Navigator.pop(context)

Navigator.pop(context);
Navigator.push(context, MaterialPageRoute(builder: (context) => HomeScreen()));