Search code examples
fluttergoogle-apigoogle-oauth

I need to add a privacy policy to my flutter web app for Google verification


I have created a Flutter app and I am trying to integrate the Google Calendar API. As part of the process, I need to add a privacy policy link to the web version.

I have added the privacy policy to my website in the root directory and I can view the privacy policy by adding button via LinkTile in the side menu. However, this is not a link because when I try to view the html page it does nothing.

How do I get this to display as an html file in a browser window? How do I get this to register with Google?

Here is the code I am using:

 ListTile(
                leading: const Icon(
                  Icons.private_connectivity,
                  color: Colors.blueAccent,
                ),
                title: const Text('Privacy Policy'),
                onTap: () {
                  if (kIsWeb) {
                    const PropertyWebViewScreenContainer('https://dealdiligencecentral.com/privacy_policy.html'); <<< This line does not work
                  } else {
                    Navigator.pop(context);
                    Navigator.push(
                        context,
                        MaterialPageRoute(
                            builder: (context) => const PrivacyPolicyScreen()));
                  }
                  ;
                },
              ),

If the user is on a mobile device it will display on a new screen. If the user is on the web I want it to display in a new browser window.

How do I do this so Google will recognize it as a link?

Thanks


Solution

  • You can try out the [url_launcher][1] package, which allows you to open URLs in a browser. Check out the below example.

    ListTile(
      leading: const Icon(
        Icons.private_connectivity,
        color: Colors.blueAccent,
      ),
      title: const Text('Privacy Policy'),
      onTap: () {
        if (kIsWeb) {
          // This will open the privacy policy URL in a new browser window/tab on the web
          _launchURL('https://dealdiligencecentral.com/privacy_policy.html');
        } else {
          Navigator.pop(context);
          Navigator.push(
              context,
              MaterialPageRoute(
                  builder: (context) => const PrivacyPolicyScreen()));
        }
      },
    )
    void _launchURL(String url) async {
      if (await canLaunch(url)) {
        await launch(url, webOnlyWindowName: '_blank'); // '_blank' opens in a new window
      } else {
        throw 'Could not launch $url';
      }
    }