hardware_details 0.0.3 copy "hardware_details: ^0.0.3" to clipboard
hardware_details: ^0.0.3 copied to clipboard

A Flutter plugin to retrieve low-level hardware information using native platform APIs.

example/lib/main.dart

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

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

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

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';
  String _cpuId = 'Unknown';
  String _motherboardId = 'Unknown';
  String _biosSerial = 'Unknown';
  String _ntpDate = 'Unknown';
  final _hardwareDetailsPlugin = HardwareDetails();

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

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    String cpuId;
    String motherboardId;
    String biosSerial;
    String ntpDate;
    // Platform messages may fail, so we use a try/catch PlatformException.
    // We also handle the message potentially returning null.
    try {
      platformVersion =
          await _hardwareDetailsPlugin.getPlatformVersion() ??
          'Unknown platform version';
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }
    try {
      cpuId = await _hardwareDetailsPlugin.getCpuId() ?? 'Unknown CPU id';
    } on PlatformException {
      cpuId = 'Failed to get cpu id.';
    }

    try {
      motherboardId =
          await _hardwareDetailsPlugin.getMotherboardId() ??
          'Unknown motherboard id';
    } on PlatformException {
      motherboardId = 'Failed to get motherboard id.';
    }
    try {
      biosSerial =
          await _hardwareDetailsPlugin.getBiosSerial() ?? 'Unknown BIOS serial';
    } on PlatformException {
      biosSerial = 'Failed to get BIOS serial.';
    }
    try {
      ntpDate =
          await _hardwareDetailsPlugin.getNTPDate() ?? 'Unknown internet date';
    } on PlatformException {
      ntpDate = 'Failed to internet date.';
    }
    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
      _cpuId = cpuId;
      _motherboardId = motherboardId;
      _biosSerial = biosSerial;
      _ntpDate = ntpDate;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('Plugin example app')),
        body: Center(
          child: Column(
            children: [
              Text('Running on: $_platformVersion\n'),
              Text('CPU: $_cpuId\n'),
              Text('Motherboard: $_motherboardId\n'),
              Text('BIOS: $_biosSerial\n'),
              Text('Date: $_ntpDate\n'),
            ],
          ),
        ),
      ),
    );
  }
}
0
likes
0
points
16
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter plugin to retrieve low-level hardware information using native platform APIs.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, flutter_web_plugins, plugin_platform_interface, web

More

Packages that depend on hardware_details

Packages that implement hardware_details