call_logs_plus 0.0.4
call_logs_plus: ^0.0.4 copied to clipboard
A Flutter plugin for accessing call logs, created for educational and learning purposes only. Not intended for production or commercial use.
example/lib/main.dart
import 'package:call_logs_plus/logs.dart';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'clog.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();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home:
CallLogsPage()
);
}
}
class CallLogsPage extends StatefulWidget {
const CallLogsPage({super.key});
@override
State<CallLogsPage> createState() => _CallLogsPageState();
}
class _CallLogsPageState extends State<CallLogsPage> {
final CallLogsPlugin _plugin = CallLogsPlugin();
List<CallLogEntry> _logs = [];
bool _loading = true;
String _selectedRange = "all";
@override
void initState() {
super.initState();
_loadLogs("all");
}
Future<void> _loadLogs(String range) async {
setState(() {
_loading = true;
_selectedRange = range;
});
await _plugin.checkPermissions();
_plugin.getCallLogs(range).listen((data) {
setState(() {
_logs = data;
_loading = false;
});
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Call Logs')),
body: Column(
children: [
// FILTER DROPDOWN
Padding(
padding: const EdgeInsets.all(10),
child: DropdownButtonFormField<String>(
value: _selectedRange,
decoration: const InputDecoration(
labelText: "Filter by time",
border: OutlineInputBorder(),
),
items: const [
/// those value are key so don't change the values
DropdownMenuItem(value: "1h", child: Text("Last 1 Hour")),
DropdownMenuItem(value: "6h", child: Text("Last 6 Hours")),
DropdownMenuItem(value: "1w", child: Text("Last 1 Week")),
DropdownMenuItem(value: "all", child: Text("All Logs")),
],
onChanged: (value) {
if (value != null) _loadLogs(value);
},
),
),
const SizedBox(height: 10),
// CALL LOGS LIST
Expanded(
child: _loading
? const Center(child: CircularProgressIndicator())
: ListView.builder(
itemCount: _logs.length,
itemBuilder: (context, index) {
final log = _logs[index];
return Card(
child: ListTile(
leading: const Icon(Icons.call),
title: Text(
log.name.isNotEmpty ? log.name : log.number,
),
subtitle: Text(
'${log.type} | ${log.duration}s | ${log.dateTime}',
),
trailing: Text(
log.simName,
style: const TextStyle(
fontWeight: FontWeight.bold,
color: Colors.blue),
),
),
);
},
),
),
],
),
);
}
}