I want to open a bunch of music app links using links data I have in firebase. I want to open, amazonPrimeMusic, Ganna, Spotify, Wynk, JioSavaan to name some.

Widget buildResultCard(data) {
  List items = [Text(data['Ganna']),
    IconButton(icon:Icon(Icons.all_inclusive),
      onPressed: ()=> {Text("Ganna")}
    ),

    Text(data['Wynk']),
    IconButton(icon:Icon(Icons.all_inclusive),
      onPressed: ()=> {Text("Ganna")}
    ),

    Text(data['JioSavaan']),
    IconButton(icon:Icon(Icons.all_inclusive),
      onPressed: ()=> {Text("Ganna")}
    ),

    Text(data['PrimeMusic']),
    IconButton(icon:Icon(Icons.all_inclusive),
      onPressed: ()=> {Text("Ganna")}
    )
  ];

  return ListView.builder(
    padding: EdgeInsets.only(top: 20),
    itemCount: items.length,
    itemBuilder: (BuildContext context, int index) {
      return items[index];
    },
  );
}

when I tap the button in the list it should open up the particular app for which the link is, for example for AmazonPrimeMusic link, it should open the Amazon music app.

2 Answers

1
Aryan On

You can use flutter_appavailability package. This plugin allows you to check if an app is installed in mobile and using this plugin you can launch an app.

If already installed then launch otherwise open link in WebView using url_launcher.

0
Lokesh Karki On

add this to the pubspec.yaml file under dependencies-

  device_apps:
  android_intent:
  url_launcher:

and add these to the top -

import 'package:device_apps/device_apps.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:android_intent/android_intent.dart';

and here is the sample code -

_openJioSavaan (data) async
{String dt = data['JioSavaan'] as String;
  bool isInstalled = await DeviceApps.isAppInstalled('com.jio.media.jiobeats');
if (isInstalled != false)
 {
    AndroidIntent intent = AndroidIntent(
      action: 'action_view',
      data: dt
  );
  await intent.launch();
 }
else
  {
  String url = dt;
  if (await canLaunch(url)) 
    await launch(url);
   else 
    throw 'Could not launch $url';
}
}