device_info_plugin 0.0.5 copy "device_info_plugin: ^0.0.5" to clipboard
device_info_plugin: ^0.0.5 copied to clipboard

A new Flutter plugin for platform device info.

example/lib/main.dart

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

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

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

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

class _MyAppState extends State<MyApp> {
  Map<String, String> _platformInfo;
  String _storageDirectory = "";

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

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    Map<String, String> platformInfo = new Map();
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      Map<dynamic, dynamic> platformInfoTmp = await DTPlaformInfoPlugin.dtPlaformInfoPlugin;
      platformInfoTmp.forEach((key, value){
        platformInfo.putIfAbsent(key, ()=>value);
      });
      _storageDirectory = await DTPlaformInfoPlugin.dtStorageDirectoryPlugin;
    } on PlatformException {
      platformInfo = Map();
      _storageDirectory = "error-storage_directory";
    }

    // 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(() {
      _platformInfo = platformInfo;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Text('Running on: \n' + _platformInfo.toString() + "\n" + _storageDirectory),
        ),
      ),
    );
  }
}
0
likes
20
pub points
35%
popularity

Publisher

unverified uploader

A new Flutter plugin for platform device info.

Homepage

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on device_info_plugin