zeba_academy_performance_monitor 1.0.0
zeba_academy_performance_monitor: ^1.0.0 copied to clipboard
Flutter performance monitoring toolkit with FPS, memory, rebuild tracking, API latency monitoring and overlay.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:zeba_academy_performance/zeba_academy_performance.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
runApp(const MyApp());
// Stop startup timer after app launch
StartupTimeAnalyzer.stop();
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Zeba Academy Performance Example',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const HomePageWithOverlay(),
);
}
}
/// Wrap the home page with the performance overlay
class HomePageWithOverlay extends StatelessWidget {
const HomePageWithOverlay({super.key});
@override
Widget build(BuildContext context) {
return PerformanceOverlayWidget(
child: const HomePage(),
);
}
}
class HomePage extends StatefulWidget {
const HomePage({super.key});
@override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
String apiResult = "Press the button to simulate API call";
Future<void> simulateApiCall() async {
final result = await ApiLatencyTracker.track(
Future.delayed(
const Duration(milliseconds: 500),
() => "API Success",
),
);
setState(() {
apiResult = result;
});
}
Widget _buildCard({required String title, required Widget child}) {
return Card(
elevation: 4,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
margin: const EdgeInsets.symmetric(vertical: 10, horizontal: 16),
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(title,
style:
const TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
const SizedBox(height: 10),
child,
],
),
),
);
}
@override
Widget build(BuildContext context) {
return RebuildTracker(
name: "HomePage",
child: Scaffold(
appBar: AppBar(
title: const Text("Performance Dashboard Example"),
),
body: SingleChildScrollView(
child: Column(
children: [
_buildCard(
title: "FPS Monitor",
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: const [
Icon(Icons.speed, color: Colors.blue),
Text("FPS monitoring running…"),
],
),
),
_buildCard(
title: "Memory Usage",
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: const [
Icon(Icons.memory, color: Colors.green),
Text("Memory usage tracking…"),
],
),
),
_buildCard(
title: "API Latency Test",
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ElevatedButton(
onPressed: simulateApiCall,
child: const Text("Run API Call"),
),
const SizedBox(height: 8),
Text(apiResult),
],
),
),
_buildCard(
title: "Log Memory",
child: ElevatedButton(
onPressed: () async {
await MemoryTracker.logMemoryUsage();
},
child: const Text("Log Memory Usage"),
),
),
],
),
),
),
);
}
}