mx_memory_info 0.0.1 copy "mx_memory_info: ^0.0.1" to clipboard
mx_memory_info: ^0.0.1 copied to clipboard

获取手机硬盘内存信息

example/lib/main.dart

import 'dart:ffi';

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

import 'package:flutter/services.dart';
import 'package:mx_memory_info/mx_memory_info.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';
  final _mxMemoryInfoPlugin = MxMemoryInfo();
  int myFree = 0;
  double myUse = 0.0;
  double myTotal = 0.0;

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

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;

    try {
      platformVersion =
          await _mxMemoryInfoPlugin.getPlatformVersion() ?? 'Unknown platform version';
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }


    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  getFree()async{
  int free = await  _mxMemoryInfoPlugin.getFreeMemory();
      setState(() {
        myFree = free;
      });
  }

  getUse()async{
    double use = await  _mxMemoryInfoPlugin.getUsedMemory();
    setState(() {
      myUse = use;
    });
  }

  getTotal()async{
    double total = await  _mxMemoryInfoPlugin.getTotalMemory();
    setState(() {
      myTotal = total;
    });
  }



  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            children: [
             ElevatedButton(onPressed: (){
                 getFree();
             }, child: const Text("get free")),
                 Text("Free:$myFree M"),
                 const SizedBox(height: 20,),
              ElevatedButton(onPressed: (){
                   getUse();
              }, child: const Text("get use")),
              Text("Use:$myUse G"),
              ElevatedButton(onPressed: (){
                getTotal();
              }, child: const Text("get total")),
              Text("Use:$myTotal G"),
            ],
          ),
        ),
      ),
    );
  }
}
0
likes
140
points
17
downloads

Publisher

unverified uploader

Weekly Downloads

获取手机硬盘内存信息

Homepage

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on mx_memory_info