X
    Categories: Flutter

How to Open Another App in Flutter : A Step-by-Step Guide.

Flutter Open Another App :

In this blog, explore how to leverage Flutter powerful capabilities to seamlessly open one app from another. Learn about deep linking techniques and best practices for creating a smooth user experience in your Flutter applications.

Discover how to implement app-to-app communication effortlessly using Flutter’s navigation features. Dive into practical examples and step-by-step guides to master app navigation within the Flutter framework. Unlock the potential of connecting multiple apps and enhancing user interaction with this comprehensive guide to Flutter app-to-app navigation. Start exploring the possibilities today!

 

Flutter Open Another App Video Playlist :

Explore the curated playlist for Flutter App to App Navigation explained in detailed with steps explained.

 

main.dart :

Let’s start with imports

import 'dart:io';
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';

 

then create a main function to start the program

void main(){
  runApp(MyApp());
}

 

Now comes the important aspect i.e., launching app or redirecting to Playstore / Appstore if app is not installed on device.

This functionality is curated in a separate stand alone function such that it can be easily re-used through out the app.

Here you can observe this function will accept a url that can be local or a ul where app is located.

void _launchApp(String url) async{

  if(await canLaunchUrl(Uri.parse(url))){
    await launchUrl(Uri.parse(url));
  }else if(Platform.isIOS){
    _launchApp("https://apps.apple.com/app/id544007664");
  }else if(Platform.isAndroid){
    _launchApp("https://play.google.com/store/apps/details?id=com.Abhishekapps.abhishek.VoicetoText");
  }

}

 

Add a appBar

appBar: AppBar(title: const Text("First App"),),

 

Add a basic functionality to make a button click event such that we are able to move to a second app.

Center(
  child: ElevatedButton(
    onPressed: () {
      _launchApp("amplifyabhi://launch");
    },
    child: const Text("Navigate to Another App"),
  ),
),

 

Complete Code :

import 'dart:io';
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';

void main(){
  runApp(MyApp());
}

class MyApp extends StatelessWidget {

  void _launchApp(String url) async{

    if(await canLaunchUrl(Uri.parse(url))){
      await launchUrl(Uri.parse(url));
    }else if(Platform.isIOS){
      _launchApp("https://apps.apple.com/app/id544007664");
    }else if(Platform.isAndroid){
      _launchApp("https://play.google.com/store/apps/details?id=com.Abhishekapps.abhishek.VoicetoText");
    }
  }

  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text("First App"),),
        body: Center(
          child: ElevatedButton(
            onPressed: (){
              _launchApp("amplifyabhi://launch");
            },
            child: const Text("Navigate to second app"),
          ),
        ),
      ),
    );
  }
}

 

Flutter Android app integration :

To invoke another app in Flutter i,e., to start another app from current app you need to make some configurations on native app i..e, android for this blog so here we provide a configuration which helps you to handle flutter platform channels.

Flutter android app integration is a key factor that helps you in redirection so make sure you configure it properly so as to avoid issues.

<intent-filter>
    <action android:name="android.intent.action.VIEW"/>
    <category android:name="android.intent.category.DEFAULT"/>
    <category android:name="android.intent.category.BROWSABLE"/>
    <data android:scheme="amplifyabhi" android:host="launch"/>
</intent-filter>

 

 

If you have any questions, feel free to drop them in the comments below. If you enjoyed this tutorial, show us some love by liking and sharing for more exciting updates

 

abhishek:
Related Post

This website uses cookies.