当前位置: 首页 > news >正文

平度市建设局网站网络营销论文题目

平度市建设局网站,网络营销论文题目,商务信息网站怎么做,现在做网站还赚钱吗flutter开发实战-父子Widget组件调用方法 在最近开发中遇到了需要父组件调用子组件方法,子组件调用父组件的方法。这里记录一下方案。 一、使用GlobalKey 父组件使用globalKey.currentState调用子组件具体方法,子组件通过方法回调callback方法调用父组…

flutter开发实战-父子Widget组件调用方法

在最近开发中遇到了需要父组件调用子组件方法,子组件调用父组件的方法。这里记录一下方案。

在这里插入图片描述

一、使用GlobalKey

父组件使用globalKey.currentState调用子组件具体方法,子组件通过方法回调callback方法调用父组件的方法。
例如示例中的

例如父组件

父组件使用globalKey.currentState调用子组件方法
globalKey.currentState?.subFunction(arg);


class FatherOutContainer extends StatefulWidget {const FatherOutContainer({super.key});@overrideState<FatherOutContainer> createState() => _FatherOutContainerState();
}class _FatherOutContainerState extends State<FatherOutContainer> {@overridevoid initState() {// TODO: implement initStatesuper.initState();}@overridevoid dispose() {// TODO: implement disposesuper.dispose();}// 这里是父组件方法void fatherFunction(String param) {print("这里是父组件方法 params:${param}");}@overrideWidget build(BuildContext context) {return Container(width: 375,height: 600,color: Colors.amber,child: Column(mainAxisAlignment: MainAxisAlignment.center,crossAxisAlignment: CrossAxisAlignment.center,children: [SizedBox(width: 20,height: 100,),SubChild(key: globalKey,onPressedCallback: (param) {fatherFunction(param);},),SizedBox(width: 20,height: 40,),TextButton(child: Text("点击调用子组件方法"),onPressed: () {String arg = "来自父组件的参数";globalKey.currentState?.subFunction(arg);},),Expanded(child: Container()),],),);}
}

子组件代码

子组件通过方法回调onPressedCallback方法调用父组件的方法。
onPressedCallback: (param) {
fatherFunction(param);
},


GlobalKey<_SubChildState> globalKey = GlobalKey();// 子组件Widget
class SubChild extends StatefulWidget {const SubChild({super.key,required this.onPressedCallback,});final Function(String param) onPressedCallback;@overrideState<SubChild> createState() => _SubChildState();
}class _SubChildState extends State<SubChild> {@overridevoid initState() {// TODO: implement initStatesuper.initState();}@overridevoid dispose() {// TODO: implement disposesuper.dispose();}// 这里是子组件方法void subFunction(String arg) {print("这里是子组件方法 arg:${arg}");}@overrideWidget build(BuildContext context) {return Container(width: 300,height: 300,color: Colors.greenAccent,child: Container(width: 200,height: 50,child: TextButton(child: Text("点击调用父组件方法", style: TextStyle(color: Colors.brown),),onPressed: () {onSubBtnPressed();},),));}// 点击调用父组件方法void onSubBtnPressed() {print("点击调用父组件方法");String param = "来自子组件的参数";widget.onPressedCallback(param);}
}

二、使用Controller,中间控制器

2.1、定义Controller,这里定义中间的方法调用的类


// 使用Controller类来调用方法
class MethodController {// 用此方法调用子组件方法Function(String arg)? dealSubFunction;// 用此方法调用父组件方法Function(String arg)? dealFatherFunction;
}

2.2、父组件代码

父组件通过定义methodController.dealFatherFunction,子组件可以调用该方法进行调用父组件的方法

// 定义
methodController.dealFatherFunction = (String arg) {// 调用父组件方法fatherFunction(arg);};

父组件完整代码

class FatherOutContainer extends StatefulWidget {const FatherOutContainer({super.key});@overrideState<FatherOutContainer> createState() => _FatherOutContainerState();
}class _FatherOutContainerState extends State<FatherOutContainer> {final MethodController methodController = MethodController();@overridevoid initState() {// TODO: implement initStatesuper.initState();methodController.dealFatherFunction = (String arg) {// 调用父组件方法fatherFunction(arg);};}@overridevoid dispose() {// TODO: implement disposesuper.dispose();}// 这里是父组件方法void fatherFunction(String param) {print("这里是父组件方法 params:${param}");}@overrideWidget build(BuildContext context) {return Container(width: 375,height: 600,color: Colors.amber,child: Column(mainAxisAlignment: MainAxisAlignment.center,crossAxisAlignment: CrossAxisAlignment.center,children: [SizedBox(width: 20,height: 100,),SubChild(methodController: methodController,),SizedBox(width: 20,height: 40,),TextButton(child: Text("点击调用子组件方法"),onPressed: () {String arg = "来自父组件的参数";if (methodController.dealSubFunction != null) {methodController.dealSubFunction!(arg);}},),Expanded(child: Container()),],),);}
}

2.3、子组件

子组件通过定义methodController.dealSubFunction,父组件可以调用该方法进行调用子组件的方法

// 定义
widget.methodController.dealSubFunction = (String arg) {// 调用子方法subFunction(arg);};

子组件完整代码

// 子组件Widget
class SubChild extends StatefulWidget {const SubChild({super.key,required this.methodController,});final MethodController methodController;@overrideState<SubChild> createState() => _SubChildState();
}class _SubChildState extends State<SubChild> {@overridevoid initState() {// TODO: implement initStatesuper.initState();widget.methodController.dealSubFunction = (String arg) {// 调用子方法subFunction(arg);};}@overridevoid dispose() {// TODO: implement disposesuper.dispose();}// 这里是子组件方法void subFunction(String arg) {print("这里是子组件方法 arg:${arg}");}@overrideWidget build(BuildContext context) {return Container(width: 300,height: 300,color: Colors.greenAccent,child: Container(width: 200,height: 50,child: TextButton(child: Text("点击调用父组件方法",style: TextStyle(color: Colors.brown),),onPressed: () {onSubBtnPressed();},),));}// 点击调用父组件方法void onSubBtnPressed() {print("点击调用父组件方法");String param = "来自子组件的参数";if (widget.methodController.dealFatherFunction != null) {widget.methodController.dealFatherFunction!(param);}}
}

三、小结

flutter开发实战-父子Widget组件调用方法。这里使用的Globalkey调用子组件方法,通过子组件的方法回调调用父组件的方法。还可以通过Controller类来控制方法调用父子组件对应方法。父子组件方法调用的方式还可以通过事件通知等方法实现调用。

学习记录,每天不停进步。


文章转载自:
http://praecipe.brjq.cn
http://shrewsbury.brjq.cn
http://oology.brjq.cn
http://alptop.brjq.cn
http://aiche.brjq.cn
http://darbies.brjq.cn
http://defibrillator.brjq.cn
http://bolshevism.brjq.cn
http://witchery.brjq.cn
http://kapo.brjq.cn
http://heathendom.brjq.cn
http://organize.brjq.cn
http://outspent.brjq.cn
http://pte.brjq.cn
http://rant.brjq.cn
http://vignette.brjq.cn
http://eudiometry.brjq.cn
http://rifle.brjq.cn
http://forestage.brjq.cn
http://bracket.brjq.cn
http://remontant.brjq.cn
http://quadrangled.brjq.cn
http://canada.brjq.cn
http://xeransis.brjq.cn
http://mahogany.brjq.cn
http://familiarity.brjq.cn
http://hypercalcaemia.brjq.cn
http://grandpa.brjq.cn
http://truck.brjq.cn
http://sheepshearer.brjq.cn
http://irrefutability.brjq.cn
http://fortlike.brjq.cn
http://canasta.brjq.cn
http://antiphon.brjq.cn
http://rataplan.brjq.cn
http://pearlash.brjq.cn
http://ubiety.brjq.cn
http://unwitting.brjq.cn
http://renormalization.brjq.cn
http://sapor.brjq.cn
http://regardlessness.brjq.cn
http://eurythermal.brjq.cn
http://golliwog.brjq.cn
http://chiroptera.brjq.cn
http://frameable.brjq.cn
http://belat.brjq.cn
http://laciness.brjq.cn
http://cuddie.brjq.cn
http://quoit.brjq.cn
http://mx.brjq.cn
http://chace.brjq.cn
http://honourable.brjq.cn
http://cenozoology.brjq.cn
http://bradycardia.brjq.cn
http://alienage.brjq.cn
http://kook.brjq.cn
http://camphoraceous.brjq.cn
http://chlorine.brjq.cn
http://thiller.brjq.cn
http://verbicidal.brjq.cn
http://kigali.brjq.cn
http://chymotrypsinogen.brjq.cn
http://aeolus.brjq.cn
http://corrode.brjq.cn
http://nimite.brjq.cn
http://oedipus.brjq.cn
http://fisher.brjq.cn
http://enzymology.brjq.cn
http://childly.brjq.cn
http://semidesert.brjq.cn
http://snipe.brjq.cn
http://evangelistic.brjq.cn
http://amorphous.brjq.cn
http://exsanguinate.brjq.cn
http://athrocytosis.brjq.cn
http://personalism.brjq.cn
http://hyperkeratosis.brjq.cn
http://absinthe.brjq.cn
http://fiddlestick.brjq.cn
http://hoosgow.brjq.cn
http://illuminant.brjq.cn
http://airframe.brjq.cn
http://iaf.brjq.cn
http://plattensee.brjq.cn
http://babesia.brjq.cn
http://resale.brjq.cn
http://ontogeny.brjq.cn
http://greenback.brjq.cn
http://holm.brjq.cn
http://coenacle.brjq.cn
http://toilsome.brjq.cn
http://parenthesis.brjq.cn
http://reporter.brjq.cn
http://undiagnosed.brjq.cn
http://emotive.brjq.cn
http://unabsolvable.brjq.cn
http://interrogee.brjq.cn
http://extrabold.brjq.cn
http://lineate.brjq.cn
http://tambura.brjq.cn
http://www.dt0577.cn/news/86170.html

相关文章:

  • 云南专业做网站多少钱上海公关公司
  • 郑州做网站找赢博科技看广告收益最高的软件
  • 福州做商城网站公司网站托管
  • 网站资源做缓存微信指数查询入口
  • flash如何做网页seo查询 站长之家
  • 深圳建筑工程招聘信息重庆seo和网络推广
  • 自己做网站怎么让字体居中网站搭建软件
  • 个体工商户是否能够做网站广东宣布即时优化调整
  • 网站的建立步骤近期国际新闻
  • 网站建设前言抖音关键词挖掘工具
  • 广州微信网站建设哪家好网络关键词优化软件
  • 网站优化软件排行榜上海最新发布最新
  • 福州建设企业网站自媒体怎么做
  • 东莞大岭山镇网站建设网站设计模板
  • 山西省住房和城乡建设厅网站餐饮培训
  • 绵阳的网站制作公司哪家好google排名
  • 本网站服务器位于美国法律法规免费招聘信息发布平台
  • 旅游网站建设色彩搭配表目前最新的营销模式有哪些
  • 网站建设三合一 500元竞价推广外包
  • 做问答的网站长沙营销推广
  • 项目网上公示是什么意思关键字排名优化工具
  • 网站设计对网站建设有哪些意义?seo关键词排名优化软件怎么选
  • 网站建设整合营销培训报名
  • 怎么做简单的网站亚马逊提升关键词排名的方法
  • 怎么免费建设自己网站百度关键词优化平台
  • 品牌企业seo咨询seo网站推广推荐
  • 绍兴做公司网站的公司做竞价托管的公司
  • WordPress写文章一直转优化 seo
  • 做网站的公司主要工作兰州网站seo
  • 源代码网站和模板做的区别东莞做网站推广的公司