尝试直接从 FLUTTER 进行调用:MissingPluginException(未找到方法 callNumber 的实现 [英] TRYING TO PLACE CALL DIRECTLY FROM FLUTTER: MissingPluginException(No implementation found for method callNumber
问题描述
我希望我的应用在出现特定情况时自动拨打特定号码.两个流行的插件是 flutter_phone_direct_caller 和 url_launcher.Url 启动器的问题是该方法会将号码推送到您手机的拨号器,但不会启动呼叫,但 flutter_phone_direct_caller 声称它将启动.这是他们文档中的示例.
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);
}
这是我页面的代码..当按下按钮时,呼叫应该启动,但对我来说,它返回一个错误.(我的电话号码是XXXd,当我运行它时,我输入了我的实际号码).
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)] 未处理的异常:MissingPluginException(在频道 flutter_phone_direct_caller 上找不到方法 callNumber 的实现)
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)
这个插件有 94% 的流行度,所以它适用于大多数人.有人知道是什么问题吗?
This plugin has 94% popularity so it works for most people. Does anyone know what the issue is?
推荐答案
flutter 与原生功能集成的方式是创建所谓的 MethodChannels
使用它们可以调用在原生内部注册的函数java
来自 dart 的代码.
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.
因此,此错误可能出现的一个原因是您的 Flutter 代码无法与本机 java 代码通信,这意味着它没有找到任何 channel
或没有找到 方法
由包通过channel
注册.
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.
步骤
- 从您的设备上卸载该应用.
- 再次重建应用.
这应该可以解决问题.
这篇关于尝试直接从 FLUTTER 进行调用:MissingPluginException(未找到方法 callNumber 的实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!