gurleensethi / sailor

Easy page navigation and management in Flutter apps.
https://pub.dev/packages/sailor
MIT License
145 stars 24 forks source link

How can I retrieve the param values in opened page in initState? #59

Closed NTMS2017 closed 3 years ago

NTMS2017 commented 3 years ago

In my route:

        SailorRoute(
          name: "/ACCOUNT_DETAILS",
          builder: (context, args, params) => AccountDetails(),
          customTransition: MyCustomTransition(),
          defaultTransitions: [
            SailorTransition.slide_from_bottom,
            SailorTransition.zoom_in,
          ],
          params: [
            SailorParam<String>(
              name: 'userAccountNo',
              defaultValue: "...",
            ),
            SailorParam<String>(
              name: 'userAccountType',
              defaultValue: "...",
            ),
          ],
        ),

Passing the actual parameter when navigating to the new route:

  Future<void> _navigationToAccountsDetailPage() async {
    await Future.delayed(Duration(milliseconds: 400), () async {
      Routes.sailor.pop(true);
      await Routes.sailor.navigate("/ACCOUNT_DETAILS",
          params: {"userAccountNo": _userAccountNo, "userAccountType": _userAccountType});
    });
  }

This also printed empty

  @override
  void didChangeDependencies() {
    super.didChangeDependencies();

    final _userAccountNo = Sailor.param<String>(context, 'userAccountNo');
    final _userAccountType = Sailor.param<String>(context, 'userAccountType');

    print("_userAccountNo: $_userAccountNo");
    print("_userAccountType: $_userAccountType");
  }

But how can I retrieve the values in opened (AccountsDetailPage) page in initState??