ram_info 0.0.4
ram_info: ^0.0.4 copied to clipboard
A Flutter plugin that provides total and free RAM memory information for Android and iOS devices.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:ram_info/memory_info.dart';
import 'package:ram_info/ram_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> {
@override
void initState() {
super.initState();
initPlatformState();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
// Platform messages may fail, so we use a try/catch PlatformException.
// We also handle the message potentially returning null.
try {
await RamInfo.getMemoryDetails();
} on PlatformException {
// If the plugin is not implemented on the platform, we can handle it here.
// For example, we could show an error message or log it.
debugPrint('Failed to get memory details.');
} catch (e) {
// Handle any other exceptions that might occur.
debugPrint('An unexpected error occurred: $e');
}
// 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(() {
// Update the state if necessary, e.g., to show that the memory details
// have been fetched successfully.
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'Running on:',
),
FutureBuilder<MemoryInfo>(
future: RamInfo.getMemoryDetails(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const CircularProgressIndicator();
} else if (snapshot.hasError) {
return Text('Error: ${snapshot.error}');
} else {
final memoryDetails = snapshot.data;
return Text(
'Total Memory: ${memoryDetails?.totalMB ?? 0} MB\n'
'Free Memory: ${memoryDetails?.freeMB ?? 0} MB\n',
);
}
},
),
],
),
),
),
);
}
}