iosflutterdartbundle-identifierpackage-name

How to get bundle id in flutter


I used the below method to get the app name and packageName but I need Bundle id for iPhone users. I want to share an app link. I did it in android but on iPhone, I need bundle id.

 Future<Null> _initPackageInfo() async {
        final PackageInfo info = await PackageInfo.fromPlatform();
        setState(() {
          _packageInfo = info;
          packageName = info.packageName;
          appName = info.appName;
          buildNumber = info.buildNumber;
        });
      }

Solution

  • Use get_version package . It's the easiest way

    Installing :

     dependencies:
       get_version: any
    

    Usage:

    String projectAppID;
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      projectAppID = await GetVersion.appID;
    } on PlatformException {
      projectAppID = 'Failed to get app ID.';
    }
    

    You can use it as String inside anything you want like Text widget etc ...


    Another extract of get_version in a small application :

    import 'package:get_version/get_version.dart';    
      class _MyAppState extends State<MyApp> {
      String _projectAppID = '';
      @override
      initState() {
        super.initState();
        initPlatformState();
      }    
      // Platform messages are asynchronous, so we initialize in an async method.
      initPlatformState() async {
        String projectAppID;
        try {
          projectAppID = await GetVersion.appID;
        } catch (e) {
          projectAppID = 'Failed to get app ID.';
        }
        setState(() {
          _projectAppID = projectAppID;
        });
      }
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          home: Scaffold(
            body: ListTile(
              leading: new Icon(Icons.info),
              title: const Text('App ID'),
              subtitle: new Text(_projectAppID),
            ),
          ),
        );
      }
    }
    

    Output :

    enter image description here