꿈꾸는 시스템 디자이너

Flutter Example - How to get app information | App Name, App ID, Version, BuildNumber | package_info plugin 본문

Tutorial/Flutter with App

Flutter Example - How to get app information | App Name, App ID, Version, BuildNumber | package_info plugin

독행소년 2019. 10. 17. 13:46

* About Plugin

https://pub.dev/packages/package_info

 

package_info | Flutter Package

Flutter plugin for querying information about the application package, such as CFBundleVersion on iOS or versionCode on Android.

pub.dev

 

1. Add this to pubspec.yaml file

dependencies:
  package_info: ^0.4.0+6

 

2. Source Code

import 'package:flutter/material.dart';
import 'package:package_info/package_info.dart';

AppInfoDemoState pageState;

class AppInfoDemo extends StatefulWidget {
  @override
  AppInfoDemoState createState() {
    pageState = AppInfoDemoState();
    return pageState;
  }
}

class AppInfoDemoState extends State<AppInfoDemo> {
  String appName = "";
  String appID = "";
  String version = "";
  String buildNumber = "";

  @override
  void initState() {
    super.initState();
    getAppInfo();
  }

  void getAppInfo() async {
    PackageInfo packageInfo = await PackageInfo.fromPlatform();
    setState(() {
      appName = packageInfo.appName;
      appID = packageInfo.packageName;
      version = packageInfo.version;
      buildNumber = packageInfo.buildNumber;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text("App Infomation")),
      body: ListView(
        children: <Widget>[
          Card(
            child: ListTile(
              title: Text("App Name"),
              subtitle: Text(appName),
            ),
          ),
          Card(
            child: ListTile(
              title: Text("Package Name (AppID)"),
              subtitle: Text(appID),
            ),
          ),
          Card(
            child: ListTile(
              title: Text("Version"),
              subtitle: Text(version),
            ),
          ),
          Card(
            child: ListTile(
              title: Text("Build Number"),
              subtitle: Text(buildNumber),
            ),
          ),
        ],
      ),
    );
  }
}

 

.

 

▶ Go to Table of Contents | 강의 목차로 이동


※ This example is also available in the Flutter Code Examples app. | 본 예제는 Flutter Code Examples 앱에서도 제공됩니다.

 

Flutter Code Examples - Google Play 앱

Are you a beginner at Flutter? Check out the various features of Flutter through the demo. Source code for all demos is also provided.

play.google.com

Comments