hi_device_util 0.0.2 copy "hi_device_util: ^0.0.2" to clipboard
hi_device_util: ^0.0.2 copied to clipboard

PlatformAndroidiOS
outdated

手机设备数据抓取工具类

example/lib/main.dart

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

import 'package:flutter/services.dart';
import 'package:hi_device_util/hi_device_util.dart';

void main() {
  runApp(MyApp());
}

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

class _MyAppState extends State<MyApp> {
  String _deviceInfo = "获取设备信息失败";

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

  Future<void> getDeviceInfo() async {
    String info;
    // Platform messages may fail, so we use a try/catch PlatformException.
    // We also handle the message potentially returning null.
    try {
      info =
          await HiDeviceUtil.getDeviceInfo ?? 'Unknown platform version';
    } on PlatformException {
      info = '获取设备信息失败';
    }

    // 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(() {
      _deviceInfo = info;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            children: [
              Text('设备信息: $_deviceInfo\n'),
            ],
          ),
        ),
      ),
    );
  }
}
3
likes
125
points
17
downloads

Publisher

unverified uploader

Weekly Downloads

手机设备数据抓取工具类

Repository

Documentation

API reference

License

Apache-2.0 (license)

Dependencies

flutter

More

Packages that depend on hi_device_util

Packages that implement hi_device_util