DEV Community

timfong888
timfong888

Posted on

Suggestions on how to deep link and route using Flutter?

Hello, I built an app using a third-party deep-linking service called GetSocial.

Locally, on Xcode, I have been able to get the listener in main() to display the parameters that I pass through the deep link.

However, I need to then route to a specific page and pass values to that page (ideally as a persisted local variable).

But I am stuck.

ReferralData globalReferralData;
    List<BuildContext> buildContextList = [];
    BuildContext context;


    void main() async {
      WidgetsFlutterBinding.ensureInitialized();
      await Firebase.initializeApp();

      FFAppState(); // Initialize FFAppState

      GetSocial.addOnInitializedListener(() => {
            // GetSocial SDK is ready to use
          });

      runApp(MyApp());
      registerListeners();
    }

    void registerListeners() {
      Invites.setOnReferralDataReceivedListener((received) {
        globalReferralData = received;
        print(globalReferralData);
        print(globalReferralData.linkParams);
        print(globalReferralData.linkParams['referralID']);

        // pass value and open route -- this line failed to do anything

        Navigator.pushNamed(context, '/landingPage');

        // showAlert(buildContextList.last, 'Referral Data Received', '$received');
      });
    }
Enter fullscreen mode Exit fullscreen mode

Top comments (0)