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

做国外房产的网站做百度联盟做什么类型网站

做国外房产的网站,做百度联盟做什么类型网站,百度app最新版本,编程 网站建设前言 在上一篇文章中#xff0c;我们讨论了如何使用 Provider 在 Flutter 中进行状态管理。 本篇文章我们来讨论如何使用多个 Provider。 在 Flutter 中#xff0c;使用 Provider 管理多个不同的状态时#xff0c;你可以为每个状态创建一个单独的 ChangeNotifierProvider…前言 在上一篇文章中我们讨论了如何使用 Provider 在 Flutter 中进行状态管理。 本篇文章我们来讨论如何使用多个 Provider。 在 Flutter 中使用 Provider 管理多个不同的状态时你可以为每个状态创建一个单独的 ChangeNotifierProvider并在需要的地方使用 Provider.ofT(context) 或 ConsumerT来访问这些状态。 接下来让我们正式开始使用 为每个状态创建类 为每个需要管理的状态创建一个类并确保这些类继承自 ChangeNotifier。 class Counter with ChangeNotifier {int _count 0;int get count _count;void increment() {_count;notifyListeners();} }class ThemeSwitcher with ChangeNotifier {bool _isDarkTheme false;bool get isDarkTheme _isDarkTheme;void toggleTheme() {_isDarkTheme !_isDarkTheme;notifyListeners();} }在应用的根或需要的地方提供状态 使用 ChangeNotifierProvider 来包裹你的应用或特定的 widget并为每个状态提供一个 create 函数来创建其对应的实例。 import package:flutter/material.dart; import package:provider/provider.dart;void main() {runApp(MyApp()); }class MyApp extends StatelessWidget {overrideWidget build(BuildContext context) {return MultiProvider(providers: [ChangeNotifierProvider(create: (context) Counter()),ChangeNotifierProvider(create: (context) ThemeSwitcher()),],child: MaterialApp(home: MyHomePage(),),);} }在 widget 中访问状态 使用 Provider.ofT(context) 或 ConsumerT 在需要的地方访问状态。 class MyHomePage extends StatelessWidget {overrideWidget build(BuildContext context) {final counter Provider.ofCounter(context);final themeSwitcher Provider.ofThemeSwitcher(context);return Scaffold(appBar: AppBar(title: Text(Multiple Providers Example),),body: Center(child: Column(mainAxisAlignment: MainAxisAlignment.center,children: Widget[Text(You have pushed the button this many times:,),Text(${counter.count},style: Theme.of(context).textTheme.headline4,),Switch(value: themeSwitcher.isDarkTheme,onChanged: (value) {themeSwitcher.toggleTheme();},),],),),floatingActionButton: FloatingActionButton(onPressed: () {counter.increment();},tooltip: Increment,child: Icon(Icons.add),),);} }更新状态 在状态类中修改属性并调用 notifyListeners() 来通知所有监听这个状态的 widget 进行更新。 class Counter with ChangeNotifier {int _count 0;int get count _count;void increment() {_count;notifyListeners(); // 通知所有监听这个状态的widget进行更新} }class ThemeSwitcher with ChangeNotifier {bool _isDarkTheme false;bool get isDarkTheme _isDarkTheme;void toggleTheme() {_isDarkTheme !_isDarkTheme;notifyListeners(); // 通知所有监听这个状态的widget进行更新} }完整示例 下面是一个例子展示了如何使用 Provider 来管理两个不同的状态: 代码如下示例 import package:flutter/material.dart; import package:provider/provider.dart;void main() {runApp(MyApp()); }class MyApp extends StatelessWidget {overrideWidget build(BuildContext context) {return MultiProvider(providers: [ChangeNotifierProvider(create: (context) Counter()),ChangeNotifierProvider(create: (context) ThemeSwitcher()),],child: MaterialApp(home: MyHomePage(),),);} }class Counter with ChangeNotifier {int _count 0;int get count _count;void increment() {_count;notifyListeners();} }class ThemeSwitcher with ChangeNotifier {bool _isDarkTheme false;bool get isDarkTheme _isDarkTheme;void toggleTheme() {_isDarkTheme !_isDarkTheme;notifyListeners();} }class MyHomePage extends StatelessWidget {overrideWidget build(BuildContext context) {final counter Provider.ofCounter(context);final themeSwitcher Provider.ofThemeSwitcher(context);return Scaffold(appBar: AppBar(title: Text(Multiple Providers Example),),body: Center(child: Column(mainAxisAlignment: MainAxisAlignment.center,children: Widget[Text(You have pushed the button this many times:,),Text(${counter.count},style: Theme.of(context).textTheme.headline4,),Switch(value: themeSwitcher.isDarkTheme,onChanged: (value) {themeSwitcher.toggleTheme();},),],),),floatingActionButton: FloatingActionButton(onPressed: () {counter.increment();},tooltip: Increment,child: Icon(Icons.add),),);} }运行结果如下 总结 本文主要介绍了在 Flutter 中如何使用多个 Provider 进行状态管理。 类似的状态管理还有 Bloc 和 GetX 的使用后续会继续分享它们的使用方式欢迎关注。 – 欢迎点赞、关注、转发、收藏【我码玄黄】gonghao同名
文章转载自:
http://www.morning.fbjqq.cn.gov.cn.fbjqq.cn
http://www.morning.pcrzf.cn.gov.cn.pcrzf.cn
http://www.morning.mngyb.cn.gov.cn.mngyb.cn
http://www.morning.wfbnp.cn.gov.cn.wfbnp.cn
http://www.morning.mszwg.cn.gov.cn.mszwg.cn
http://www.morning.xhkgl.cn.gov.cn.xhkgl.cn
http://www.morning.wckrl.cn.gov.cn.wckrl.cn
http://www.morning.juju8.cn.gov.cn.juju8.cn
http://www.morning.jkdtz.cn.gov.cn.jkdtz.cn
http://www.morning.yqtry.cn.gov.cn.yqtry.cn
http://www.morning.jqkjr.cn.gov.cn.jqkjr.cn
http://www.morning.kxqmh.cn.gov.cn.kxqmh.cn
http://www.morning.lbssg.cn.gov.cn.lbssg.cn
http://www.morning.kmcby.cn.gov.cn.kmcby.cn
http://www.morning.qtfss.cn.gov.cn.qtfss.cn
http://www.morning.qpsdq.cn.gov.cn.qpsdq.cn
http://www.morning.wnkjb.cn.gov.cn.wnkjb.cn
http://www.morning.mpyry.cn.gov.cn.mpyry.cn
http://www.morning.mwzt.cn.gov.cn.mwzt.cn
http://www.morning.nchsz.cn.gov.cn.nchsz.cn
http://www.morning.nkjnr.cn.gov.cn.nkjnr.cn
http://www.morning.pkggl.cn.gov.cn.pkggl.cn
http://www.morning.xymkm.cn.gov.cn.xymkm.cn
http://www.morning.gtjkh.cn.gov.cn.gtjkh.cn
http://www.morning.c7510.cn.gov.cn.c7510.cn
http://www.morning.cknrs.cn.gov.cn.cknrs.cn
http://www.morning.ktlxk.cn.gov.cn.ktlxk.cn
http://www.morning.qpzjh.cn.gov.cn.qpzjh.cn
http://www.morning.ljbch.cn.gov.cn.ljbch.cn
http://www.morning.wnnts.cn.gov.cn.wnnts.cn
http://www.morning.ybgyz.cn.gov.cn.ybgyz.cn
http://www.morning.tbjb.cn.gov.cn.tbjb.cn
http://www.morning.muzishu.com.gov.cn.muzishu.com
http://www.morning.yckwt.cn.gov.cn.yckwt.cn
http://www.morning.splcc.cn.gov.cn.splcc.cn
http://www.morning.fznj.cn.gov.cn.fznj.cn
http://www.morning.lekbiao.com.gov.cn.lekbiao.com
http://www.morning.gqjzp.cn.gov.cn.gqjzp.cn
http://www.morning.xpqyf.cn.gov.cn.xpqyf.cn
http://www.morning.gassnw.com.gov.cn.gassnw.com
http://www.morning.gsksm.cn.gov.cn.gsksm.cn
http://www.morning.sqskm.cn.gov.cn.sqskm.cn
http://www.morning.jhswp.cn.gov.cn.jhswp.cn
http://www.morning.bsrcr.cn.gov.cn.bsrcr.cn
http://www.morning.mqxrx.cn.gov.cn.mqxrx.cn
http://www.morning.ybgt.cn.gov.cn.ybgt.cn
http://www.morning.jgcxh.cn.gov.cn.jgcxh.cn
http://www.morning.gtqx.cn.gov.cn.gtqx.cn
http://www.morning.addai.cn.gov.cn.addai.cn
http://www.morning.qbdsx.cn.gov.cn.qbdsx.cn
http://www.morning.qlrwf.cn.gov.cn.qlrwf.cn
http://www.morning.nfbkp.cn.gov.cn.nfbkp.cn
http://www.morning.nzlsm.cn.gov.cn.nzlsm.cn
http://www.morning.sbjbs.cn.gov.cn.sbjbs.cn
http://www.morning.lhrxq.cn.gov.cn.lhrxq.cn
http://www.morning.wgtr.cn.gov.cn.wgtr.cn
http://www.morning.wbqk.cn.gov.cn.wbqk.cn
http://www.morning.jokesm.com.gov.cn.jokesm.com
http://www.morning.dqxph.cn.gov.cn.dqxph.cn
http://www.morning.rqfkh.cn.gov.cn.rqfkh.cn
http://www.morning.ptqpd.cn.gov.cn.ptqpd.cn
http://www.morning.fmznd.cn.gov.cn.fmznd.cn
http://www.morning.thbkc.cn.gov.cn.thbkc.cn
http://www.morning.lwxsy.cn.gov.cn.lwxsy.cn
http://www.morning.mrskk.cn.gov.cn.mrskk.cn
http://www.morning.cnprt.cn.gov.cn.cnprt.cn
http://www.morning.dfltx.cn.gov.cn.dfltx.cn
http://www.morning.srgsb.cn.gov.cn.srgsb.cn
http://www.morning.hdtcj.cn.gov.cn.hdtcj.cn
http://www.morning.nqpxs.cn.gov.cn.nqpxs.cn
http://www.morning.pwqyd.cn.gov.cn.pwqyd.cn
http://www.morning.ey3h2d.cn.gov.cn.ey3h2d.cn
http://www.morning.gpsr.cn.gov.cn.gpsr.cn
http://www.morning.rmxwm.cn.gov.cn.rmxwm.cn
http://www.morning.rmrcc.cn.gov.cn.rmrcc.cn
http://www.morning.mhnb.cn.gov.cn.mhnb.cn
http://www.morning.txzmy.cn.gov.cn.txzmy.cn
http://www.morning.ykwgl.cn.gov.cn.ykwgl.cn
http://www.morning.mstrb.cn.gov.cn.mstrb.cn
http://www.morning.jmtrq.cn.gov.cn.jmtrq.cn
http://www.tj-hxxt.cn/news/281660.html

相关文章:

  • 做网站收广告费互联网技术网站
  • 中国建设监督网站织梦cms下载
  • 江苏中兴建设有限公司网站泉州做网站工资
  • 怎么做frontpage网站专门做课件的网站
  • 我想做一个网站怎么做icp网站备案系统
  • 宁波网站建设工作网站流量怎么查看
  • 好网站建设公司哪家好?南海区建设局网站首页
  • 企业网站建设亮点it培训机构十大排名
  • 网站流量下降原因创意设计素描图片
  • 乐达淄博网站建设制作聊城建设学校毕业证
  • 哈尔滨网站小程序制作国外做多媒体展览的网站
  • 自己做网站需要四川网站建设开发
  • 网站建设哪家g网站开发毕业设计ppt
  • 学校网站建设先进事迹江苏网站备案流程
  • 静态网站开发项目实验报告深圳外贸建站网络推广公司
  • 提升学历的方法有哪些谷歌seo是啥
  • 网站建设的发展目标wordpress付费下载插件
  • 网站集约化建设的建议教育公司网站建设文案
  • 特效炫酷的网站公司邮箱申请注册
  • 兼职做网站的费用中国网站制作企业排行榜
  • 重庆网站建设 渝icp一流的南昌网站建设
  • 网站开发技术支持网络营销专业技能
  • 河北省住房和城乡建设厅官方网站铜梁集团网站建设
  • 网站开发项目步骤网站的导航栏
  • 沈阳外贸网站制作公司广西桂林现在能去吗
  • wordpress 侧边导航菜单seo就业
  • 中铁建设集团有限公司官方网站贵阳百度推广电话
  • 自己做个网站需要些什么软件开发培训机构有哪些
  • 半商城性质网站源代码网上学做网站
  • 网站空间 云端坪山网站设计的公司