Implementing deep linking without Firebase
=> First we have to add plugins for deep linking in pubspec.yaml :
uni_links: ^0.5.1
=> we should add below code in AndroidManifest.xml
<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="nutsby.com" /> <data android:scheme="https" /> </intent-filter>
=> Then we have to import package
import 'package:uni_links/uni_links.dart';
=> Then we have to handle the deep linking process
void initUniLinks() async { try { String? initialLink = await getInitialLink(); print(initialLink); if (initialLink != null) { // Handle the initial deep link handleDeepLink(context,initialLink); } } on PlatformException { // Handle errors } } void handleDeepLink(BuildContext context,String link) { if (link == null) { return null; } final uri = Uri.parse(link); if (uri.pathSegments.length < 2) { print("The pathSegments list does not have enough elements"); return; } var route = uri.pathSegments[0]; print("path1: $route"); var route_id= uri.pathSegments[1]; print("path2: $route_id"); if(route=="product_details"){ Navigator.push(context, MaterialPageRoute( builder: (context) => ProductDetails(prod_id: route_id))); } // Add your logic to handle the deep link print("Received deep link: $link"); }