deinfo 0.0.3

  • Readme
  • Changelog
  • Example
  • Installing
  • 57

deviceinfo #

一个 Flutter 的获取设备信息的 plugin

note 这个 plugin 暂时只支持 Android 系统

Getting Started #

  • 获取 Android app version name
String appVersionName = await _channel.invokeMethod('getAppVersionName');
  • 获取 Android app version code
int appVersionCode = await _channel.invokeMethod('getAppVersionCode');
  • 获取Android device version code (Android API level)
int deviceVersionCode = await _channel.invokeMethod('getDeviceVersionCode');
  • 获取Android device 的 imei 值 (需要获取 READ_PHONE_STATE 权限)
String imei = await _channel.invokeMethod('getImei');
  • 获取 Android device 的 uuid 值
String deviceId = await Deviceinfo.uuid;
  • 获取 Android device 的屏幕信息
ScreenDisplay screenDisplay = await Deviceinfo.screenInfo;

ScreenDisplay 包含: 1.width 屏幕的宽度 2.height 屏幕的高度

  • 获取 Android device 的 Build 信息
Build buildInfo = await Deviceinfo.buildInfo;

Build类的数据结构包括:

  1. String device;
  2. String display;
  3. String hardware;
  4. String host;
  5. String id;
  6. String type;
  7. String user;
  8. String unknow;
  9. Version version;

其中 Version 包括:

  1. String release;
  2. String sdk;
  3. int sdkInt;
  4. String codeName;

以上字段的含义和 Android 的 Build 里的相同名称字段含义一致

  • 获取 Android device 的设备唯一标识 (device token)
String deviceToken = await Deviceinfo.deviceToken

0.0.1 #

  • TODO: Describe initial release.

example/lib/main.dart

import 'dart:async';

import 'package:deinfo/src/buildinfo.dart';
import 'package:deinfo/src/deviceinfo.dart';
import 'package:deinfo/src/screeninfo.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

void main() => runApp(new MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _appVersionName = 'Unknown';
  int _deviceVersionCode = -1;
  int _appVersionCode = -1;
  String _imei = 'Unknown';
  String _deviceId = '';
  ScreenDisplay _screenDisplay;
  Build _buildInfo;
  String _deviceToken;

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


  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String appVersionName;
    int deviceVersionCode;
    int appVersionCode;
    String imei;
    String deviceId;
    ScreenDisplay screenDisplay;
    Build buildInfo;
    String deviceToken;
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      appVersionName = await Deviceinfo.appVersionName;
      deviceVersionCode = await Deviceinfo.deviceVersionCode;
      appVersionCode = await Deviceinfo.appVersionCode;
      imei = await Deviceinfo.imei;
      deviceId = await Deviceinfo.uuid;
      screenDisplay = await Deviceinfo.screenInfo;
      buildInfo = await Deviceinfo.buildInfo;
      deviceToken = await Deviceinfo.deviceToken;
    } on PlatformException {
      appVersionName = 'Failed to get app version name.';
      deviceVersionCode = -2;
      appVersionCode = -2;
      imei = 'Failed to get app imei';
      deviceId = 'Failed to get app deviceId';
      screenDisplay = null;
      buildInfo = null;
      deviceToken = 'Failed to get device token';
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    // if (!mounted) return;

    setState(() {
      _appVersionName = appVersionName;
      _deviceVersionCode = deviceVersionCode;
      _appVersionCode = appVersionCode;
      _imei = imei;
      _deviceId = deviceId;
      _screenDisplay = screenDisplay;
      _buildInfo = buildInfo;
      _deviceToken = deviceToken;
    });
  }

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        appBar: new AppBar(
          title: const Text('Plugin example app'),
        ),
        body: new Center(
          child: Column(
            children: <Widget>[
              Expanded(
                child: new Text('Running on appVersionName: $_appVersionName\n'),
              ),
              Expanded(
                child: Text('deviceVersionCode: $_deviceVersionCode'),
              ),
              Expanded(
                child: Text('appVersionCode: $_appVersionCode'),
              ),
              Expanded(
                child: Text('app imei: $_imei'),
              ),
              Expanded(
                child: Text('app deviceId: $_deviceId'),
              ),
              Expanded(
                child: Text(
                    'device screen display, width: ${_screenDisplay == null ? 0 : _screenDisplay.width};  height: ${_screenDisplay == null ? 0 : _screenDisplay.height}'
                )
              ),
              Expanded(
//                child: Text('device build info: ${_buildInfo == null ? "build info is null" : json.encode(_buildInfo)}'),
                child: Text('device build info:'),
              ),
              Expanded(
                child: Text('device token: ${_deviceToken}'),
              )
            ],
          )
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  deinfo: ^0.0.3

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

Popularity:
Describes how popular the package is relative to other packages. [more]
29
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
59
Overall:
Weighted score of the above. [more]
57
Learn more about scoring.

We analyzed this package on Oct 22, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.4

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Format lib/src/buildinfo.dart.

Run flutter format to format lib/src/buildinfo.dart.

Format lib/src/deviceinfo.dart.

Run flutter format to format lib/src/deviceinfo.dart.

Format lib/src/screeninfo.dart.

Run flutter format to format lib/src/screeninfo.dart.

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (json_serializable).

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Package is getting outdated. (-0.55 points)

The package was last published 52 weeks ago.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
build_runner ^1.0.0 1.2.3 1.7.2
flutter 0.0.0
json_serializable ^1.5.1 1.5.1 3.2.3
Transitive dependencies
analyzer 0.33.6+1 0.39.0
args 1.5.2
async 2.4.0
build 1.1.0 1.2.0
build_config 0.3.2 0.4.1+1
build_daemon 0.2.3 2.1.0
build_resolvers 0.2.3 1.2.1
build_runner_core 2.0.1 4.1.0
built_collection 4.2.2
built_value 6.7.1
charcode 1.1.2
code_builder 3.2.0
collection 1.14.11 1.14.12
convert 2.1.1
crypto 2.1.3
csslib 0.16.1
dart_style 1.2.0 1.3.2
fixnum 0.10.9
front_end 0.1.6+9 0.1.28
glob 1.2.0
graphs 0.2.0
html 0.14.0+3
http 0.12.0+2
http_multi_server 2.1.0
http_parser 3.1.3
io 0.3.3
js 0.6.1+1
json_annotation 1.2.0 3.0.0
kernel 0.3.6+9 0.3.28
logging 0.11.3+2
matcher 0.12.6
meta 1.1.7
mime 0.9.6+3
node_interop 1.0.3
node_io 1.0.1+2
package_config 1.1.0
package_resolver 1.0.10
path 1.6.4
pedantic 1.8.0+1
plugin 0.2.0+3
pool 1.4.0
pub_semver 1.4.2
pubspec_parse 0.1.4 0.1.5
quiver 2.0.5
shelf 0.7.5
shelf_web_socket 0.2.3
sky_engine 0.0.99
source_gen 0.9.4+1 0.9.4+5
source_span 1.5.5
stack_trace 1.9.3
stream_channel 2.0.0
stream_transform 0.0.19
string_scanner 1.0.5
term_glyph 1.1.0
timing 0.1.1+2
typed_data 1.1.6
vector_math 2.0.8
watcher 0.9.7+12
web_socket_channel 1.1.0
yaml 2.2.0