deinfo 0.0.3

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • new54

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 packages get

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

Version Uploaded Documentation Archive
0.0.3 Oct 20, 2018 Go to the documentation of deinfo 0.0.3 Download deinfo 0.0.3 archive
0.0.2 Oct 20, 2018 Go to the documentation of deinfo 0.0.2 Download deinfo 0.0.2 archive
0.0.1 Oct 20, 2018 Go to the documentation of deinfo 0.0.1 Download deinfo 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
21
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
70
Overall:
Weighted score of the above. [more]
54
Learn more about scoring.

We analyzed this package on Nov 14, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.12.6
  • Flutter: 0.11.3

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Maintenance suggestions

The description is too short. (-20 points)

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

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

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

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
build_runner ^1.0.0 1.1.2
flutter 0.0.0
json_serializable ^1.5.1 1.5.1 2.0.0
Transitive dependencies
analyzer 0.33.3
args 1.5.1
async 2.0.8
build 1.0.1
build_config 0.3.1+4
build_resolvers 0.2.2+6
build_runner_core 1.1.0
built_collection 4.0.0
built_value 6.1.6
charcode 1.1.2
code_builder 3.1.3
collection 1.14.11
convert 2.0.2
crypto 2.0.6
csslib 0.14.6
dart_style 1.2.0
fixnum 0.10.9
front_end 0.1.6+3
glob 1.1.7
graphs 0.1.3+1
html 0.13.3+3
http_multi_server 2.0.5
http_parser 3.1.3
io 0.3.3
js 0.6.1+1
json_annotation 1.2.0 2.0.0
kernel 0.3.6+3
logging 0.11.3+2
matcher 0.12.4
meta 1.1.6
mime 0.9.6+2
package_config 1.0.5
path 1.6.2
pedantic 1.3.0
plugin 0.2.0+3
pool 1.3.6
pub_semver 1.4.2
pubspec_parse 0.1.2+3
quiver 2.0.1
shelf 0.7.3+3
shelf_web_socket 0.2.2+4
sky_engine 0.0.99
source_gen 0.9.1+3
source_span 1.4.1
stack_trace 1.9.3
stream_channel 1.6.8
stream_transform 0.0.14+1
string_scanner 1.0.4
timing 0.1.1+1
typed_data 1.1.6
utf 0.9.0+5
vector_math 2.0.8
watcher 0.9.7+10
web_socket_channel 1.0.9
yaml 2.1.15