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

PlatformAndroid

Droid Dex is a powerful tool crafted to enhance the performance of your Android applications.

example/lib/main.dart

import 'package:droid_dex/droid_dex.dart';
import 'package:droid_dex/performance_class.dart';
import 'package:droid_dex/performance_level.dart';
import 'package:flutter/material.dart';
import 'package:percent_indicator/circular_percent_indicator.dart';

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'DroidDex',
      theme: ThemeData(
        useMaterial3: true,
        fontFamily: 'SF Pro', // Optional: mimic iOS typography in screenshot
      ),
      home: const DroidDexDashboard(),
    );
  }
}

/// Main dashboard page.
class DroidDexDashboard extends StatelessWidget {
  const DroidDexDashboard({super.key});

  String getPerformanceLevelMap(PerformanceLevel? p) {
    switch (p) {
      case PerformanceLevel.low:
        return "Low";
      case PerformanceLevel.average:
        return "Average";
      case PerformanceLevel.high:
        return "Good";
      case PerformanceLevel.excellent:
        return "Best";
      case null:
        return "Unknown";
      case PerformanceLevel.unknown:
        return "Unknown";
    }
  }

  double getPerformanceLevelMapValue(PerformanceLevel? p) {
    switch (p) {
      case PerformanceLevel.low:
        return 0.25;
      case PerformanceLevel.average:
        return 0.5;
      case PerformanceLevel.high:
        return 0.75;
      case PerformanceLevel.excellent:
        return 1;
      case null:
        return 0;
      case PerformanceLevel.unknown:
        return 0;
    }
  }

  Color getPerformanceLevelMapColor(PerformanceLevel? p) {
    switch (p) {
      case PerformanceLevel.low:
        return Colors.redAccent;
      case PerformanceLevel.average:
        return Colors.amber;
      case PerformanceLevel.high:
        return Color(0xFF9ACD32);
      case PerformanceLevel.excellent:
        return Colors.green;
      case null:
        return Colors.green;
      case PerformanceLevel.unknown:
        return Colors.green;
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      body: SafeArea(
        child: SingleChildScrollView(
          padding: const EdgeInsets.all(16),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: [
              const _Header(),
              const SizedBox(height: 24),
              _Section(
                title: 'Individual',
                children: [
                  FutureBuilder<PerformanceLevel>(
                    future: DroidDex.getPerformanceLevel([
                      PerformanceClass.cpu,
                    ]),
                    // Your stream from EventChannel
                    builder: (context, snapshot) {
                      if (snapshot.hasData) {
                        return _DonutCard(
                          label: 'CPU',
                          status: getPerformanceLevelMap(snapshot.data),
                          percent: getPerformanceLevelMapValue(snapshot.data),
                          color: getPerformanceLevelMapColor(snapshot.data),
                        );
                      } else if (snapshot.hasError) {
                        return Text("Error: ${snapshot.error}");
                      }
                      return CircularProgressIndicator();
                    },
                  ),
                  FutureBuilder<PerformanceLevel>(
                    future: DroidDex.getPerformanceLevel([
                      PerformanceClass.memory,
                    ]),
                    // Your stream from EventChannel
                    builder: (context, snapshot) {
                      if (snapshot.hasData) {
                        return _DonutCard(
                          label: 'Memory',
                          status: getPerformanceLevelMap(snapshot.data),
                          percent: getPerformanceLevelMapValue(snapshot.data),
                          color: getPerformanceLevelMapColor(snapshot.data),
                        );
                      } else if (snapshot.hasError) {
                        return Text("Error: ${snapshot.error}");
                      }
                      return CircularProgressIndicator();
                    },
                  ),
                  FutureBuilder<PerformanceLevel>(
                    future: DroidDex.getPerformanceLevel([
                      PerformanceClass.storage,
                    ]),
                    // Your stream from EventChannel
                    builder: (context, snapshot) {
                      if (snapshot.hasData) {
                        return _DonutCard(
                          label: 'Storage',
                          status: getPerformanceLevelMap(snapshot.data),
                          percent: getPerformanceLevelMapValue(snapshot.data),
                          color: getPerformanceLevelMapColor(snapshot.data),
                        );
                      } else if (snapshot.hasError) {
                        return Text("Error: ${snapshot.error}");
                      }
                      return CircularProgressIndicator();
                    },
                  ),
                  FutureBuilder<PerformanceLevel>(
                    future: DroidDex.getPerformanceLevel([
                      PerformanceClass.network,
                    ]),
                    // Your stream from EventChannel
                    builder: (context, snapshot) {
                      if (snapshot.hasData) {
                        return _DonutCard(
                          label: 'Network',
                          status: getPerformanceLevelMap(snapshot.data),
                          percent: getPerformanceLevelMapValue(snapshot.data),
                          color: getPerformanceLevelMapColor(snapshot.data),
                        );
                      } else if (snapshot.hasError) {
                        return Text("Error: ${snapshot.error}");
                      }
                      return CircularProgressIndicator();
                    },
                  ),
                  FutureBuilder<PerformanceLevel>(
                    future: DroidDex.getPerformanceLevel([
                      PerformanceClass.battery,
                    ]),
                    // Your stream from EventChannel
                    builder: (context, snapshot) {
                      if (snapshot.hasData) {
                        return _DonutCard(
                          label: 'Battery',
                          status: getPerformanceLevelMap(snapshot.data),
                          percent: getPerformanceLevelMapValue(snapshot.data),
                          color: getPerformanceLevelMapColor(snapshot.data),
                        );
                      } else if (snapshot.hasError) {
                        return Text("Error: ${snapshot.error}");
                      }
                      return CircularProgressIndicator();
                    },
                  ),
                ],
              ),
              const SizedBox(height: 32),
              _Section(
                title: 'Aggregate',
                children: [
                  FutureBuilder<PerformanceLevel>(
                    future: DroidDex.getPerformanceLevel([
                      PerformanceClass.cpu,
                      PerformanceClass.memory,
                    ]),
                    // Your stream from EventChannel
                    builder: (context, snapshot) {
                      if (snapshot.hasData) {
                        return _DonutCard(
                          label: 'CPU + Memory',
                          status: getPerformanceLevelMap(snapshot.data),
                          percent: getPerformanceLevelMapValue(snapshot.data),
                          color: getPerformanceLevelMapColor(snapshot.data),
                        );
                      } else if (snapshot.hasError) {
                        return Text("Error: ${snapshot.error}");
                      }
                      return CircularProgressIndicator();
                    },
                  ),
                  FutureBuilder<PerformanceLevel>(
                    future: DroidDex.getPerformanceLevel([
                      PerformanceClass.network,
                      PerformanceClass.storage,
                    ]),
                    // Your stream from EventChannel
                    builder: (context, snapshot) {
                      if (snapshot.hasData) {
                        return _DonutCard(
                          label: 'Network + Storage',
                          status: getPerformanceLevelMap(snapshot.data),
                          percent: getPerformanceLevelMapValue(snapshot.data),
                          color: getPerformanceLevelMapColor(snapshot.data),
                        );
                      } else if (snapshot.hasError) {
                        return Text("Error: ${snapshot.error}");
                      }
                      return CircularProgressIndicator();
                    },
                  ),
                  FutureBuilder<PerformanceLevel>(
                    future: DroidDex.getPerformanceLevel([
                      PerformanceClass.cpu,
                      PerformanceClass.memory,
                      PerformanceClass.network,
                    ]), // Your stream from EventChannel
                    builder: (context, snapshot) {
                      if (snapshot.hasData) {
                        return _DonutCard(
                          label: 'CPU + Memory + Network',
                          status: getPerformanceLevelMap(snapshot.data),
                          percent: getPerformanceLevelMapValue(snapshot.data),
                          color: getPerformanceLevelMapColor(snapshot.data),
                        );
                      } else if (snapshot.hasError) {
                        return Text("Error: ${snapshot.error}");
                      }
                      return CircularProgressIndicator();
                    },
                  ),
                ],
              ),
              const SizedBox(height: 32),
              _Section(
                title: 'Weighted Aggregate',
                children: [
                  FutureBuilder<PerformanceLevel>(
                    future: DroidDex.getWeightedPerformanceLevel({
                      PerformanceClass.memory: 2,
                      PerformanceClass.network: 1,
                    }), // Your stream from EventChannel
                    builder: (context, snapshot) {
                      if (snapshot.hasData) {
                        return _DonutCard(
                          label: 'Memory x2.0 + Network x1.0',
                          status: getPerformanceLevelMap(snapshot.data),
                          percent: getPerformanceLevelMapValue(snapshot.data),
                          color: getPerformanceLevelMapColor(snapshot.data),
                        );
                      } else if (snapshot.hasError) {
                        return Text("Error: ${snapshot.error}");
                      }
                      return CircularProgressIndicator();
                    },
                  ),
                  FutureBuilder<PerformanceLevel>(
                    future: DroidDex.getWeightedPerformanceLevel({
                      PerformanceClass.cpu: 2,
                      PerformanceClass.battery: 3,
                    }),
                    // Your stream from EventChannel
                    builder: (context, snapshot) {
                      if (snapshot.hasData) {
                        return _DonutCard(
                          label: 'CPU x2 + Battery x3',
                          status: getPerformanceLevelMap(snapshot.data),
                          percent: getPerformanceLevelMapValue(snapshot.data),
                          color: getPerformanceLevelMapColor(snapshot.data),
                        );
                      } else if (snapshot.hasError) {
                        return Text("Error: ${snapshot.error}");
                      }
                      return CircularProgressIndicator();
                    },
                  ),
                ],
              ),
            ],
          ),
        ),
      ),
    );
  }
}

//──────────────────────────────────────────────────────────────────────────────
// Building Blocks
//──────────────────────────────────────────────────────────────────────────────

class _Header extends StatelessWidget {
  const _Header();

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Text(
        'droiddex',
        style: Theme
            .of(context)
            .textTheme
            .headlineMedium
            ?.copyWith(
          fontWeight: FontWeight.w700,
          color: const Color(0xFF00C58E),
        ),
      ),
    );
  }
}

class _Section extends StatelessWidget {
  final String title;
  final List<Widget> children;

  const _Section({required this.title, required this.children});

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
        color: Colors.blue.shade50,
        borderRadius: BorderRadius.circular(24),
      ),
      padding: const EdgeInsets.all(16),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Row(
            children: [
              Text(
                title,
                style: Theme
                    .of(
                  context,
                )
                    .textTheme
                    .titleLarge
                    ?.copyWith(fontWeight: FontWeight.w700),
              ),
              const SizedBox(width: 8),
              const Icon(Icons.info_outline, size: 20),
            ],
          ),
          const SizedBox(height: 16),
          Wrap(spacing: 0, runSpacing: 16, children: children),
        ],
      ),
    );
  }
}

class _DonutCard extends StatelessWidget {
  final String label;
  final String status;
  final double percent;
  final Color color;

  const _DonutCard({
    required this.label,
    required this.status,
    required this.percent,
    required this.color,
  });

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      width: 120,
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          Container(
            padding: const EdgeInsets.all(12),
            decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.circular(24),
              boxShadow: [
                BoxShadow(
                  color: Colors.black.withOpacity(0.06),
                  blurRadius: 4,
                  offset: const Offset(0, 1),
                ),
              ],
            ),
            child: CircularPercentIndicator(
              radius: 36,
              lineWidth: 8,
              percent: percent.clamp(0.0, 1.0),
              backgroundColor: Colors.blue.shade100,
              progressColor: color,
              circularStrokeCap: CircularStrokeCap.round,
              animation: true,
              center: Text(
                status,
                style: Theme
                    .of(
                  context,
                )
                    .textTheme
                    .bodyMedium
                    ?.copyWith(fontWeight: FontWeight.w600),
                textAlign: TextAlign.center,
              ),
            ),
          ),
          const SizedBox(height: 8),
          Text(
            label,
            textAlign: TextAlign.center,
            style: Theme
                .of(
              context,
            )
                .textTheme
                .bodyMedium
                ?.copyWith(fontWeight: FontWeight.w600),
          ),
        ],
      ),
    );
  }
}
1
likes
160
points
20
downloads

Publisher

verified publisherpriyatosh.is-a.dev

Weekly Downloads

Droid Dex is a powerful tool crafted to enhance the performance of your Android applications.

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on droid_dex

Packages that implement droid_dex