Reputation: 139
I want my app to place an automated call to a specific number when a certain condition arises. The two popular plugins are flutter_phone_direct_caller and url_launcher. Url launcher's problem is that the method will push the number to the dialer of your phone but wont start the call but flutter_phone_direct_caller claims it will initiate. This is the example in their documentation.
import 'package:flutter/material.dart';
import 'package:flutter_phone_direct_caller/flutter_phone_direct_caller.dart';
void main() {
runApp(Scaffold(
body: Center(
child: RaisedButton(
onPressed: _callNumber,
child: Text('Call Number'),
),
),
));
}
_callNumber() async{
const number = '08592119XXXX'; //set the number here
bool res = await FlutterPhoneDirectCaller.callNumber(number);
}
this is the code for my page..when the button is pressed, call should initiate but for me, it returns an error.(my phone no. is XXXd out ,when i ran it i put in my actual no).
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:vitality/components/bottomAppBar.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:vitality/components/biom.dart';
import 'package:flutter_phone_direct_caller/flutter_phone_direct_caller.dart';
class HomeScreen extends StatefulWidget {
static const String id = 'home_screen';
final String docid;
final bool isCaretaker;
HomeScreen({@required this.docid, @required this.isCaretaker});
@override
_HomeScreenState createState() => _HomeScreenState();
}
_callNumber() async {
const number = '86065XXXXX'; //set the number here
bool res = await FlutterPhoneDirectCaller.callNumber(number);
}
class _HomeScreenState extends State<HomeScreen> {
final auth = FirebaseAuth.instance;
var pulse;
var temp;
@override
Widget build(BuildContext context) {
print('got here');
print(auth.currentUser.uid);
String id = ModalRoute.of(context).settings.arguments;
CollectionReference main = FirebaseFirestore.instance.collection('maindb');
main.doc(id).get().then((DocumentSnapshot documentSnapshot) {
if (documentSnapshot.exists) {
print('Document exists on the database');
pulse = documentSnapshot['pulse'];
temp = documentSnapshot['temperature'];
}
});
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
backgroundColor: Color(0xFF602247),
toolbarHeight: 50.0,
centerTitle: true,
title: Text(
'HEALTH TRACKER',
style: Theme.of(context).textTheme.headline4,
)),
body: Container(
decoration: BoxDecoration(
image: DecorationImage(
image:
NetworkImage('https://cdn.wallpapersafari.com/12/24/GiZRfh.jpg'),
fit: BoxFit.cover,
colorFilter: new ColorFilter.mode(
Colors.black.withOpacity(.7), BlendMode.dstATop),
)),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Text(widget.docid),
Text({widget.isCaretaker}.toString()),
biom(which: 'pulse', image: 'pulse', docid: widget.docid),
RoundBorderText(text: 'PULSE'),
biom(which: 'temperature', image: 'temper', docid: widget.docid),
RoundBorderText(text: 'TEMPERATURE'),
SizedBox(height: 30.0),
FlatButton(
child: Text('test call'),
onPressed: () async {
FlutterPhoneDirectCaller.callNumber('5');
})
]),
),
bottomNavigationBar: bottomAppBar(id: widget.docid),
);
}
}
class RoundBorderText extends StatelessWidget {
final String text;
RoundBorderText({this.text});
@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.only(
left: 40.0, right: 40.0, top: 8.0, bottom: 8.0),
decoration: BoxDecoration(
// border: Border.all(
// color: Colors.black,
// width: 1.0,
// ),
borderRadius: BorderRadius.all(Radius.circular(20))),
child: Text(text, style: Theme.of(context).textTheme.headline1));
}
}
E/flutter (23210): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: MissingPluginException(No implementation found for method callNumber on channel flutter_phone_direct_caller)
This plugin has 94% popularity so it works for most people. Does anyone know what the issue is?
Upvotes: 3
Views: 2886
Reputation: 6405
The way flutter integrates with native functionality is that is creates what are called MethodChannels
using which they can call functions that are registered inside native java
code from dart.
So one reason this error might be coming is that your flutter code is not able to communicate with the native java code, means it is not finding any channel
or it is not finding the method
registered by the package through a channel
there.
I suspect this could be a build issue.
Steps
This should solve the issue.
Upvotes: 9