flutter父组件调用子组件
子组件调用父组件就用callBack而父组件调用子组件除了eventBus 的通知还可以 用GlobalKey()//父组件...InkWell(onTap:(){childKey.currentState.testFun("233");},child: Test(ke...
·
子组件调用父组件就用官方的各种callBack就行
而父组件调用子组件除了eventBus 的通知 (eventBus 应用场景适合组件太多 父子信息交互过于繁琐的时候 ) 还可以 用GlobalKey()
//父组件
...
InkWell(
onTap:(){
childKey.currentState.testFun("233");
},
child: Test(key:childKey,)
),
...
//子组件
import 'package:flutter/cupertino.dart';
GlobalKey<_State> childKey = GlobalKey();
class Test extends StatefulWidget {
Test({
Key key,
}) : super(key: key);
@override
_State createState() => _State();
}
class _State extends State<Test> {
testFun(String test){
print("____触发子组件");
print("${test}");
}
@override
Widget build(BuildContext context) {
return Container(
child:Text("子组件"),
);
}
}
更多推荐



所有评论(0)