Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/118.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何使用颤振方法通道从本机swift代码调用dart代码中的方法?_Ios_Swift_Flutter_Dart - Fatal编程技术网

Ios 如何使用颤振方法通道从本机swift代码调用dart代码中的方法?

Ios 如何使用颤振方法通道从本机swift代码调用dart代码中的方法?,ios,swift,flutter,dart,Ios,Swift,Flutter,Dart,关于这个话题,我看过很多类似的问题,但没有一个解决方案对我有效。。我正在Flatter中开发一个应用程序,但想从本机iOS项目中的AppDelegate.swift调用我的main.dart文件中的特定方法 为了删除所有其他变量,我将问题提取到一个新的dart项目中。我试图使用methodChannel.invokeMethod()从AppDelegate.swift调用setChannelText(),但没有成功 有人知道我哪里出错了吗?我知道我没有对methodChannel.invokeM

关于这个话题,我看过很多类似的问题,但没有一个解决方案对我有效。。我正在Flatter中开发一个应用程序,但想从本机iOS项目中的
AppDelegate.swift
调用我的
main.dart
文件中的特定方法

为了删除所有其他变量,我将问题提取到一个新的dart项目中。我试图使用
methodChannel.invokeMethod()
AppDelegate.swift
调用
setChannelText()
,但没有成功

有人知道我哪里出错了吗?我知道我没有对
methodChannel.invokeMethod()
中的“name”参数进行操作,但那是因为我只希望调用调用该方法

这是我的主.dart文件:

导入“包装:颤振/材料.省道”;
导入“包:flifter/services.dart”;
void main(){
runApp(MyApp());
}
类MyApp扩展了StatefulWidget{
@凌驾
_MyAppState createState()=>\u MyAppState();
}
类MyAppState扩展了状态{
方法通道通道=
新方法频道(“com.example.channeltest/changetext”);
字符串中心文本;
@凌驾
小部件构建(构建上下文){
返回材料PP(
家:脚手架(
背景颜色:Colors.purple,
正文:中(
子:文本(
centerText,
样式:TextStyle(
颜色:颜色,白色,
fontWeight:fontWeight.bold,
字体大小:30.0,
),
),
),
),
);
}
@凌驾
void initState(){
super.initState();
this.channel.setMethodCallHandler((call)async=>wait setChannelText());
this.centerText=“你好,世界!”;
}
Future setChannelText()异步{
延迟(持续时间(毫秒:200));
setState(()=>this.centerText=“另一个文本”);
}
}