gpt4 book ai didi

flutter - 尝试直接从 FLUTTER : MissingPluginException(No implementation found for method callNumber 调用电话

转载 作者:行者123 更新时间:2023-12-02 16:12:54 28 4
gpt4 key购买 nike

我希望我的应用程序在出现特定情况时自动调用特定号码。两个流行的插件是 flutter_phone_direct_caller 和 url_launcher。 Url launcher 的问题是该方法会将号码推送到您手机的拨号器,但不会开始通话,但 flutter_phone_direct_caller 声称它会启动。这是他们文档中的示例。

    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 out,当我运行它时,我输入了我的实际号码) .

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));
}
}

error

E/flutter (23210): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] 未处理的异常:MissingPluginException(未找到方法 callNumber 在 channel flutter_phone_direct_caller 上的实现)

这个插件有 94% 的流行度,所以它适用于大多数人。有谁知道问题出在哪里?

最佳答案

Flutter 与原生功能集成的方式是创建所谓的MethodChannels,使用它们可以从 dart 调用在原生 java 代码中注册的函数。

所以这个错误可能出现的一个原因是你的 flutter 代码无法与本地 java 代码通信,这意味着它没有找到任何 channel 或者它没有找到 方法 由包通过那里的 channel 注册。

我怀疑这可能是构建问题。

步骤

  1. 从您的设备上卸载该应用。
  2. 重新构建应用。

这应该可以解决问题。

关于flutter - 尝试直接从 FLUTTER : MissingPluginException(No implementation found for method callNumber 调用电话,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67573226/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com