whatsapp_call 0.0.2
whatsapp_call: ^0.0.2 copied to clipboard
Call whatsapp
example/lib/main.dart
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return const Center(
child: Text('Test'),
);
}
}
// class _MyAppState extends State<MyApp> {
// final _contacts = ValueNotifier<List<Contact>>([]);
// final _permission = ValueNotifier<bool>(true);
// @override
// void initState() {
// super.initState();
// _fetchContacts();
// _requestPermission();
// }
// Future _insertContacts(String phoneNumber) async {
// if (await FlutterContacts.requestPermission()) {
// int count = _contacts.value.length + 1;
// final newContact = Contact()
// ..name.first = 'Pengguna'
// ..name.last = count.toString()
// ..phones = [Phone(phoneNumber)];
// await newContact.insert();
// }
// }
// Future _fetchContacts() async {
// if (!await FlutterContacts.requestPermission(readonly: true)) {
// _permission.value = false;
// } else {
// final contacts = await FlutterContacts.getContacts();
// _contacts.value = contacts;
// }
// }
// void _requestPermission() {
// CallWithWhatsapp.requestPermissions().then((x) {
// print("success");
// }).catchError((e) {
// print(e);
// });
// }
// void _openStore() {
// CallWithWhatsapp.openInPlayStore().then((x) {
// print("success");
// }).catchError((e) {
// print(e);
// });
// }
// void _initiateCall() {
// CallWithWhatsapp.initiateCall("+6281215951538").then((x) {
// print("success");
// }).catchError((e) {
// print(e);
// });
// }
// void _callNumber(String phoneNumber) {
// CallWithWhatsapp.initiateCall(phoneNumber).then((x) {
// print("success");
// }).catchError((e) async {
// print(e);
// if (e == 'NO_CONTACT') {
// _insertContacts(phoneNumber);
// FlutterContacts.addListener(() => print('Contact DB changed'));
// Future.delayed(Duration(seconds: 10)).then((value) {
// CallWithWhatsapp.initiateCall(phoneNumber);
// });
// }
// });
// }
// void _createNewContact() {
// CallWithWhatsapp.createContact("Mas Zian", "+6281215951538").then((x) {
// print("success");
// }).catchError((e) {
// print(e);
// });
// }
// @override
// Widget build(BuildContext context) {
// return MaterialApp(
// home: Scaffold(
// appBar: AppBar(
// title: const Text('Plugin example app'),
// ),
// body: ValueListenableBuilder<bool>(
// valueListenable: _permission,
// builder: (context, value, child) {
// if (!_permission.value) {
// return Center(
// child: Text('Permission: ${_permission.value}'),
// );
// } else {
// return _body();
// }
// },
// ),
// ),
// );
// }
// Widget _body() {
// if (_contacts.value == null)
// return Center(
// child: CircularProgressIndicator(),
// );
// return SafeArea(
// child: Center(
// child: SingleChildScrollView(
// child: Column(
// mainAxisAlignment: MainAxisAlignment.spaceEvenly,
// crossAxisAlignment: CrossAxisAlignment.center,
// children: <Widget>[
// Row(
// mainAxisAlignment: MainAxisAlignment.spaceAround,
// children: [
// ElevatedButton(
// onPressed: _requestPermission,
// child: const Text(
// "Request permission",
// ),
// ),
// ElevatedButton(
// onPressed: _openStore,
// child: const Text(
// "Open In Playstore",
// ),
// ),
// ],
// ),
// Row(
// mainAxisAlignment: MainAxisAlignment.spaceAround,
// children: [
// ElevatedButton(
// onPressed: _initiateCall,
// child: const Text(
// "Initiate Call",
// ),
// ),
// ElevatedButton(
// onPressed: _createNewContact,
// child: const Text(
// "Create contact",
// ),
// ),
// ],
// ),
// DialPad(
// dialButtonIconColor: Colors.indigo,
// keyPadColor: Colors.lightBlue,
// dialButtonColor: Colors.greenAccent[400],
// buttonIcon: Icons.call,
// backspaceButtonIconColor: Colors.blue,
// useNumber: (number) {
// print(number);
// _callNumber(number);
// }),
// ],
// ),
// ),
// ),
// );
// }
// }