Reputation: 1349
iam implementing app with Flutter that has a pin screen must be entered to access the app, pin shows every time you resume the app so iam using (didChangeAppLifecycleState) the problem here that if something interups the app like whatsapp notification the pin shows and thats cool ,, but if two messages comes , i get two pin codes and so one , once i got 27 pin codes i have to enter them to resume the app and that's not cool at all
so the question here , is there any method or way to know which screen is on the top of stack(Navigator Stack) ? i mean visible to the user right now, so i don't have to show pin again ,
thanks in advance
Upvotes: 0
Views: 743
Reputation: 1742
Suppose you have 3 pages in your App, namely 'PageHome', 'Page1', 'PagePin'. Then:
create a file 'GlobalVariables.dart', inside this file, create a class gv.
Inside class gv, create a static var:
static String strCurPage = 'PageHome';
Import this dart file in all 3 pages.
Before navigate to a new page, e.g. from 'PageHome' to 'PagePin', set:
gv.strCurPage = 'PagePin';
When the app resume from background, navigate to 'PagePin' only if gv.strCurPage != 'PagePin'.
Upvotes: 2