Home > Software design >  how to redirect specific link to your app similar to whatsapp
how to redirect specific link to your app similar to whatsapp

Time:11-02

how to create your app's link? like WhatsApp. if you click on this link https://wa.me/546497546464 that link takes you to WhatsApp app in your phone. like how to create a link that takes user to specific screen in your app? --in flutter--

CodePudding user response:

That is called Deep Linking

The following from https://flutter.dev/docs/development/ui/navigation/deep-linking

Enable deep linking on Android

Add a metadata tag and intent filter to AndroidManifest.xml inside the <activity> tag with the ".MainActivity" name:

<!-- Deep linking -->
<meta-data android:name="flutter_deeplinking_enabled" android:value="true" />
<intent-filter android:autoVerify="true">
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:scheme="http" android:host="flutterbooksample.com" />
    <data android:scheme="https" />
</intent-filter>

Enable deep linking on iOS

Add two new keys to Info.plist in the ios/Runner directory:

<key>FlutterDeepLinkingEnabled</key>
<true/>
<key>CFBundleURLTypes</key>
<array>
    <dict>
    <key>CFBundleTypeRole</key>
    <string>Editor</string>
    <key>CFBundleURLName</key>
    <string>flutterbooksample.com</string>
    <key>CFBundleURLSchemes</key>
    <array>
    <string>customscheme</string>
    </array>
    </dict>
</array>

CodePudding user response:

Try below code hope its helpful to you,Used url_launcher package here add this dependency in your pubspec.yaml file

Your Widget

InkWell(
      hoverColor: Colors.transparent,
      child: Image.network('https://upload.wikimedia.org/wikipedia/commons/5/5e/WhatsApp_icon.png',
        width: 70,
        height: 70,
      ),
      onTap: () => _whatsApp(),
    )

Create ontap function

_whatsApp() async {
    const url =
        'https://api.whatsapp.com/send/?phone=546497546464&text&app_absent=0';// or add your URL here
    if (await canLaunch(url)) {
      await launch(url);
    } else {
      throw 'Could not launch $url';
    }
  }

You also refer my answer here and here for url_launcher

  • Related