callplugin 0.0.4 callplugin: ^0.0.4 copied to clipboard
A new Flutter Plugin That Allow User to get call detail.
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:callplugin/callplugin.dart';
import 'package:permission_handler/permission_handler.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
TextEditingController _phoneNumberController = TextEditingController();
String _platformVersion = 'Call Detail Will Display Here';
final _callpluginPlugin = Callplugin();
Future<void> getCallDetail() async {
String platformVersion = "";
//Permission
PermissionStatus readCallDetail = await Permission.phone.request();
if (readCallDetail == PermissionStatus.granted) {
platformVersion = (await _callpluginPlugin
.getPlatformVersion(_phoneNumberController.text))!;
} else {
print("Not Granted Granted");
}
if (!mounted) return;
setState(() {
_platformVersion = platformVersion;
});
}
Future<void> openDial() async {
//Permission
PermissionStatus readCallDetail = await Permission.phone.request();
if (readCallDetail == PermissionStatus.granted) {
_callpluginPlugin.openDial(_phoneNumberController.text);
} else {
print("Not Granted Granted");
}
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Phone Call App'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Padding(
padding: EdgeInsets.symmetric(horizontal: 20.0),
child: TextField(
controller: _phoneNumberController,
decoration: const InputDecoration(
labelText: 'Phone Number',
),
),
),
const SizedBox(height: 20.0),
ElevatedButton(
onPressed: () {
String phoneNumber = _phoneNumberController.text;
openDial();
},
child: const Text('Call'),
),
const SizedBox(height: 20.0),
ElevatedButton(
onPressed: () {
getCallDetail();
},
child: Text('Get Call Detail'),
),
const SizedBox(height: 20.0),
Text(_platformVersion),
],
),
),
));
}
}