system_status 1.0.5 copy "system_status: ^1.0.5" to clipboard
system_status: ^1.0.5 copied to clipboard

The system_status Plugin is a powerful and user-friendly tool designed to provide real-time statistics on RAM, battery, storage, and CPU usage for MacOS computers.

example/lib/main.dart

import 'dart:async';

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

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

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

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      title: 'SystemStatus Demo',
      home: SystemStatusPage(),
    );
  }
}

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

  @override
  _SystemStatusPageState createState() => _SystemStatusPageState();
}

class _SystemStatusPageState extends State<SystemStatusPage> {
  late Timer timer;
  final SystemStatusMacOS systemStatus = SystemStatusMacOS();
  SystemStatusModel? systemStatusModel;

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

    timer = Timer.periodic(const Duration(seconds: 1), (Timer t) {
      fetchSystemStatus();
    });
  }

  @override
  void dispose() {
    timer.cancel();
    super.dispose();
  }

  Future<void> fetchSystemStatus() async {
    try {
      final SystemStatusModel? newSystemStatusModel = await systemStatus.getSystemStatus();

      if (newSystemStatusModel != null) {
        setState(() {
          systemStatusModel = newSystemStatusModel;
          print(systemStatusModel?.toJson());
        });
      }
    } catch (e) {
      debugPrint('Error fetching system status: $e');
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('System Status'),
      ),
      body: systemStatusModel != null
          ? ListView(
              padding: const EdgeInsets.all(16.0),
              children: [
                ListTile(
                  title: const Text('CPU Usage'),
                  subtitle: Text(
                      'User: ${systemStatusModel?.cpuUsage?.userPercentage?.toStringAsFixed(2)}% | Sys: ${systemStatusModel?.cpuUsage?.sysPercentage?.toStringAsFixed(2)}% | Idle: ${systemStatusModel?.cpuUsage?.idlePercentage?.toStringAsFixed(2)}%'),
                ),
                ListTile(
                  title: const Text('Battery'),
                  subtitle: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text('Capacity: %${systemStatusModel?.batteryStatus?.currentCapacity}'),
                      Text('Health: ${systemStatusModel?.batteryStatus?.healthString}'),
                      Text('Charging: ${systemStatusModel?.batteryStatus?.isCharging == true ? 'Yes' : 'No'}'),
                      Text('Charged: ${systemStatusModel?.batteryStatus?.isCharged == true ? 'Yes' : 'No'}'),
                    ],
                  ),
                ),
                ListTile(
                  title: const Text('Disk Space'),
                  subtitle: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      SelectableText('Total: ${((systemStatusModel?.diskSpace?.totalDiskSpace ?? 0) / (1024 * 1024 * 1024)).toStringAsFixed(2)} GB'),
                      Text('Free: ${((systemStatusModel?.diskSpace?.freeDiskSpace ?? 0) / (1024 * 1024 * 1024)).toStringAsFixed(2)} GB'),
                      Text('Used: ${((systemStatusModel?.diskSpace?.usedDiskSpace ?? 0) / (1024 * 1024 * 1024)).toStringAsFixed(2)} GB'),
                      Text('Used Percentage: ${systemStatusModel?.diskSpace?.usedPercentage?.toStringAsFixed(2)}%'),
                    ],
                  ),
                ),
                ListTile(
                  title: const Text('Memory Statistics'),
                  subtitle: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text('Usage Ratio: ${systemStatusModel?.memoryStatistics?.memoryUsageRatio?.toStringAsFixed(2)}%'),
                      Text('Application Memory: ${systemStatusModel?.memoryStatistics?.applicationMemory} bytes'),
                      Text('Wired Memory: ${systemStatusModel?.memoryStatistics?.wiredMemory} bytes'),
                      Text('Compressed Memory: ${systemStatusModel?.memoryStatistics?.compressedMemory} bytes'),
                      Text('Memory Pressure: ${systemStatusModel?.memoryStatistics?.memoryPressure}'),
                    ],
                  ),
                ),
              ],
            )
          : const Center(
              child: CircularProgressIndicator(),
            ),
    );
  }
}
4
likes
0
pub points
52%
popularity

Publisher

verified publisherdevrasityilmaz.com

The system_status Plugin is a powerful and user-friendly tool designed to provide real-time statistics on RAM, battery, storage, and CPU usage for MacOS computers.

Homepage
Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, system_status_macos, system_status_platform_interface

More

Packages that depend on system_status