Apologies if my question is a bit dumb but I have just started with flutter.
I am working on sharing and deep link flutter. I have created intent and everything is working perfect except one. I am calling "initUniLinks" on my homepage not mainpage. So link and navigation is working perfect but when I open app through link shared and specific page opens but after that when go to homepage it again gets the "initUniLinks" and again redirects to specified page.
I am using Uni-link plugin and app or deep link method from this https://pub.dev/packages/uni_links
I have tried not too much but some basic options like giving null value to initialLink before navigation but as my widget is in initstate it is called again when I come back to homepage.
class HomePage extends StatefulWidget {
final Widget child;
HomePage({Key key, this.child}) : super(key: key);
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> with WidgetsBindingObserver {
String initialLink = "";
void initState() {
super.initState();
initUniLinks();
}
Future<Null> initUniLinks() async {
try {
initialLink = await getInitialLink();
if (initialLink != null || initialLink != "") {
initialLink.contains("pgpost")
? await Navigator.push(
context, MaterialPageRoute(builder: (context) => PostPage()))
: await Navigator.push(context,
MaterialPageRoute(builder: (context) => UserPage()));
}
} on PlatformException {
}
}
}
I just want to know is there any way that I can call 'initUniLinks" just one time not every time by removing from initstate ? Or any other better solution. Scenario here is simple I want my user to navigate to deep link page only one time when he clicks the link but after that my app should be able to navigate normally.