Hi Guys, Welcome to Proto Coders Point. In this flutter Article will learn how to get app name, package name, app version and build number of app programmatically by using flutter package info plus dependencies.
Package_info_plus
Flutter plugin that help us in getting app information, basically a API for querying detail info about the application programmatically.
Platform supported
Package info plus flutter plugin support all the OS : Android, iOS, MacOS, Web, Linux, Windows.
How to use package info plus
Installation
Open pubspec.yaml file & under dependencies section add plugin
dependencies:
package_info_plus:
Then hit pub get button.
Alternatively, To add the package using terminal, in IDE terminal rub below cmd
flutter pub add package_info_plus
Import it
Now in dart file, where you want to use the package import it example: main.dart
import 'package:package_info_plus/package_info_plus.dart';
Code usage
Initialize
PackageInfo packageInfo = await PackageInfo.fromPlatform();
Now by using packageInfo object, you can easily get appName, packageName, AppVersion & app build number.
String appName = packageInfo!.appName; String packageName = packageInfo!.packageName; String version = packageInfo!.version; String buildNumber = packageInfo!.buildNumber;
Complete Source Code – get package detail in flutter
import 'package:flutter/material.dart'; import 'package:package_info_plus/package_info_plus.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({Key? key}) : super(key: key); // This widget is the root of your application. @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', theme: ThemeData( primarySwatch: Colors.blue, ), home: const MyHomePage(title: 'Flutter Demo Home Page'), ); } } class MyHomePage extends StatefulWidget { const MyHomePage({Key? key, required this.title}) : super(key: key); final String title; @override State<MyHomePage> createState() => _MyHomePageState(); } class _MyHomePageState extends State<MyHomePage> { PackageInfo? packageInfo; @override void initState() { // TODO: implement initState super.initState(); getPackage(); } void getPackage() async { packageInfo = await PackageInfo.fromPlatform(); String appName = packageInfo!.appName; String packageName = packageInfo!.packageName; String version = packageInfo!.version; String buildNumber = packageInfo!.buildNumber; print("App Name : ${appName}, App Package Name: ${packageName },App Version: ${version}, App build Number: ${buildNumber}"); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text(widget.title), ), body: Center( child: Text("Flutter get Package info"), ) // This trailing comma makes auto-formatting nicer for build methods. ); } }