How to use firebase Dynamic Link with flutter go_route package - flutter

in firebase doc they call FirebaseDynamicLinks.instance.getInitialLink() in main funtion but with go route can i call it main funtion and how to handle initialLink
where i call getInitialLink() !!
Future<void> fBdynamicLink() async {
// Get any initial links
final PendingDynamicLinkData? initialLink =
await FirebaseDynamicLinks.instance.getInitialLink();
if (initialLink != null) {
debugPrint('initialLink ${initialLink.toString()}');
final Uri deepLink = initialLink.link;
// Example of using the dynamic link to push the user to a different screen
context.push(deepLink.path);
}
}

Related

Flutter - Firebase Dynamic Link not Working while app is in kill mode

I have integrated Firebase Dynamic link in my Flutter application to open and navigate application users to specific screen in app.
For that first of all I have added below plugin in pubspec.yaml file:
firebase_dynamic_links: ^5.0.5
Then, I have created a separate class to handle related stuffs as below:
class DynamicLinkService {
late BuildContext context;
FirebaseDynamicLinks dynamicLinks = FirebaseDynamicLinks.instance;
Future<void> initDynamicLinks(BuildContext context) async {
this.context = context;
dynamicLinks.onLink.listen((dynamicLinkData) {
var dynamicLink=dynamicLinkData.link.toString();
if (dynamicLink.isNotEmpty &&
dynamicLink.startsWith(ApiConstants.baseUrl) &&
dynamicLink.contains("?")) {
//Getting data here and navigating...
...
...
...
}
}).onError((error) {
print("This is error >>> "+error.message);
});
}
}
Now, I am initialising Deep-link as below in my home_screen:
final DynamicLinkService _dynamicLinkService = DynamicLinkService();
and then calling below method in initState()
#override
void initState() {
SchedulerBinding.instance.addPostFrameCallback((_) async {
await _dynamicLinkService.initDynamicLinks(context);
});
}
This is working like a charm! when my application is in recent mode or in background mode.
But the issue is when the application is closed/Killed, clicking on dynamic link just open the app but could not navigate.
What might be the issue? Thanks in advance.
Let me answer my own question, It might be useful for someone!
So, In above code I forgot to add code to handle dynamic link while the app is in closed/kill mode.
We need to add this code separately:
//this is when the app is in closed/kill mode
final PendingDynamicLinkData? initialLink = await FirebaseDynamicLinks.instance.getInitialLink();
if (initialLink != null) {
handleDynamicLink(initialLink);
}
So, final code looks like as below:
//this is when the app is in closed/kill mode
final PendingDynamicLinkData? initialLink = await FirebaseDynamicLinks.instance.getInitialLink();
if (initialLink != null) {
handleDynamicLink(initialLink);
}
//this is when the app is in recent/background mode
dynamicLinks.onLink.listen((dynamicLinkData) {
handleDynamicLink(dynamicLinkData);
}).onError((error) {
print("This is error >>> "+error.message);
});
Its working like a charm now! That's All.

How to get parameter value from link in flutter?

I am using Firebase dynamic links and I save it to a deepLink variable and pass it to the next page. Tell me, how can I get the code and pageName parameters from the link so that I can use them in the future?
url
https://.........app?pageName=emailActivationPage&code=7075
code
await Firebase.initializeApp();
final PendingDynamicLinkData? initialLink =
await FirebaseDynamicLinks.instance.getInitialLink();
if (widget.initialLink != null) {
final Uri deepLink = widget.initialLink!.link;
routeCubit.toForgotPasswordPage(deepLink.path, true);
} else {
routeCubit.toPhoneNumberPage();
}
You can access the data through the queryParameter property. It also should be a good idea to check beforehand if the key is given in the Map
if(deepLink.queryParameters.containsKey('code')){
final code = deepLink.queryParameters['code'];
}

uploading image to backed from flutter error 401

Flutter image upload to laravel backed is returning 401 error. My backed have database fields name, middelName , and profilePic The api works fine on postman but on flutter picking image from gallery and camera its not working i have implemented internet permission on all manifests i used Vpn but error 401
here is flutter code
Future uploadImage() async{
final uri =Uri.parse("https://www.compaytarining.com/api/exrecise2/");
var request =http.MultipartRequest('POST',uri);
request.fields["name"]=nameController.text;
request.fields["middelName"] = mnameController.text;
var pic= await http.MultipartFile.fromPath("profilePic", _image.path);
request.files.add(pic);
var response = await request.send();
print(response.statusCode);
if(response.statusCode==200)
{
print('ImageUploaded');
}
else
{
print("Error");
}
}
Gallery Image
File _image;
final picker=ImagePicker();
Future getImage() async
{
final pickedImage=await picker.getImage(source: ImageSource.gallery);
setState(() {
_image=File(pickedImage.path);
});
}
Many thanks
Hello check it may be error is from your response which is when you return an api response may be u set it to return 401.

Get Package Name/ApplicationId in Other pages

I want to implement rate and share button in my app so I am using url_launcher and here I want to put url of my app.
Currently it is working as
url="https://play.google.com/store/apps/details?id=in.learncodeonline.lco";
but I want this type
url="https://play.google.com/store/apps/details?id={packageName}"
Just call this function with package Name
void shareAnyApp(String packageName) async {
var url = "https://play.google.com/store/apps/details?id=$packageName";
if (await canLaunch(url)) {
await launch(url);
}
}
To Get Current App Package use Package_info
PackageInfo packageInfo = await PackageInfo.fromPlatform();
shareAnyApp(packageInfo.packageName );

Flutter - webRTC Video Call signalling doesn't work

I am able to implement voice and video call using agora.io library which is available at https://www.agora.io/ && https://github.com/AgoraIO/Flutter-SDK
how ever the process for starting a call is both user has to join a particular channel name defined by the user manually or automatically. which is not the practical way.
Is there any way to create a separate signalling system (may be using, nodejs socket, firebase or one-signal notification? )
What's the simultaneous/parallel way to be used along side that?
or what's the complete alternative?
Agora.io doesn't provide any method other passing a channel name manually or a default string. But what you can do is use Firebase dynamic link to share the channel name via a dynamic link. This link will redirect you to the page where you're taking channel name as input and fill the channel name according to the parameters passed. So your code will look something like:
class AgoraImpementation extends State<AgoraImplementation> {
#override
void initState() {
super.initState();
this.initDynamicLinks();
}
initDynamicLinks(BuildContext context) async {
await Future.delayed(Duration(seconds: 3));
var data = await FirebaseDynamicLinks.instance.getInitialLink();
var deepLink = data?.link;
final queryParams = deepLink.queryParameters;
if (queryParams.length > 0) {
var channelName = queryParams['channel_name'];
openFormScreen(channelName);
}
FirebaseDynamicLinks.instance.onLink(onSuccess: (dynamicLink)
async {
var deepLink = dynamicLink?.link;
final queryParams = deepLink.queryParameters;
if (queryParams.length > 0) {
var userName = queryParams['channel_name'];
openFormScreen(channelName);
}
debugPrint('DynamicLinks onLink $deepLink');
}, onError: (e) async {
debugPrint('DynamicLinks onError $e');
});
}
openFormScreen(String userName){
Navigator.of(context).pushNamed("routeFormScreen", arguments: {"channelName": channelName});
}
}