app_analysis 0.1.5 copy "app_analysis: ^0.1.5" to clipboard
app_analysis: ^0.1.5 copied to clipboard

Package that provides an ability to track device stats, including CPU/RAM/Battery/Traffic.

example/lib/main.dart

// Copyright (c) 2022, the MarchDev Toolkit project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:convert';

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

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(const App());
}

class App extends StatelessWidget {
  const App({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'AppAnalysis Example',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const HomePage(),
    );
  }
}

class HomePage extends StatefulWidget {
  const HomePage({Key? key}) : super(key: key);

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

class _HomePageState extends State<HomePage> {
  AnalysisInfoInterface? info;
  String? cpuInfo;
  String? memInfo;

  String getInfoData() {
    final raw = info?.toMap() ?? {};
    const encoder = JsonEncoder.withIndent('  ');
    return encoder.convert(raw);
  }

  @override
  void initState() {
    AppAnalyser().initialise();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('AppAnalysis Example'),
      ),
      body: ListView(
        children: [
          const SizedBox(height: 24),
          Padding(
            padding: const EdgeInsets.symmetric(horizontal: 16),
            child: ElevatedButton(
              onPressed: () => AppAnalyser().start(),
              child: const Text('Start Analysis'),
            ),
          ),
          const SizedBox(height: 16),
          Padding(
            padding: const EdgeInsets.symmetric(horizontal: 16),
            child: ElevatedButton(
              onPressed: () async {
                info = await AppAnalyser().stop();
                setState(() {});
              },
              child: const Text('Stop Analysis'),
            ),
          ),
          const SizedBox(height: 16),
          Padding(
            padding: const EdgeInsets.symmetric(horizontal: 16),
            child: SelectableText(getInfoData()),
          ),
          const SizedBox(height: 16),
          Padding(
            padding: const EdgeInsets.symmetric(horizontal: 16),
            child: ElevatedButton(
              onPressed: () async {
                cpuInfo = 'Temp: ' +
                    (await CpuInfoProvider().temperature).toString() +
                    '\nAvg Temp: ' +
                    (await CpuInfoProvider().averageTemperature).toString() +
                    '\nCurr Freq: ' +
                    (await CpuInfoProvider().currentFrequency).toString() +
                    '\nExtremum Freq: ' +
                    (await CpuInfoProvider().extremumFrequency).toString();
                setState(() {});
              },
              child: const Text('Get Cpu Info'),
            ),
          ),
          const SizedBox(height: 16),
          Padding(
            padding: const EdgeInsets.symmetric(horizontal: 16),
            child: SelectableText(cpuInfo ?? '-'),
          ),
          const SizedBox(height: 16),
          Padding(
            padding: const EdgeInsets.symmetric(horizontal: 16),
            child: ElevatedButton(
              onPressed: () async {
                final info = await RamInfoProvider().info;
                memInfo = 'Total: ' +
                    info.total.inMB.toInt().toString() +
                    '\nFree: ' +
                    info.available.inMB.toInt().toString() +
                    '\nUsed: ' +
                    info.used.inMB.toInt().toString();
                setState(() {});
              },
              child: const Text('Get Memory Info'),
            ),
          ),
          const SizedBox(height: 16),
          Padding(
            padding: const EdgeInsets.symmetric(horizontal: 16),
            child: SelectableText(memInfo ?? '-'),
          ),
          const SizedBox(height: 24),
        ],
      ),
    );
  }
}
2
likes
120
pub points
68%
popularity

Publisher

verified publisherthisismarch.dev

Package that provides an ability to track device stats, including CPU/RAM/Battery/Traffic.

Repository (GitHub)
View/report issues
Contributing

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

battery_info, cross_platform, flinq, flutter, flutter_web_plugins, path_provider

More

Packages that depend on app_analysis