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

08影院 WordPress模板天津seo顾问

08影院 WordPress模板,天津seo顾问,科技手抄报简单又漂亮,建设网站找哪个公司前言 我们创建一个Flutter程序,入口文件内容如下 //导包,此行代码作用是导入了 Material UI 组件库。Material (opens new window)是一种标准的移动端和 web 端的视觉设计语言, Flutter默认提供了一套丰富的 Material 风格的 UI 组件。 impo…

前言

我们创建一个Flutter程序,入口文件内容如下

//导包,此行代码作用是导入了 Material UI 组件库。Material (opens new window)是一种标准的移动端和 web 端的视觉设计语言, Flutter默认提供了一套丰富的 Material 风格的 UI 组件。
import 'package:flutter/material.dart';//应用入口
void main() {runApp(const MyApp());
}/// 在 Flutter 中,大多数东西都是 widget(后同“组件”或“部件”),包括对齐(alignment)、填充(padding)和布局(layout)等,它们都是以 widget 的形式提供。
class MyApp extends StatelessWidget {const MyApp({super.key});@override///Flutter 在构建页面时,会调用组件的build方法,widget 的主要工作是提供一个 build()方法来描述如何构建 UI 界面(通常是通过组合、拼装其它基础 widget)。Widget build(BuildContext context) {///MaterialApp 是 Material 库中提供的 Flutter APP 框架,通过它可以设置应用的名称、主题、语言、首页及路由列表等。MaterialApp也是一个 widget。return MaterialApp(//用于名称title: 'Flutter Demo',//主题theme: ThemeData(primarySwatch: Colors.blue,),//home 为 Flutter 应用的首页,它也是一个 widget。home: const MyHomePage(title: 'Flutter Demo  Page'),);}
}//首页 它继承自StatefulWidget类,表示它是一个有状态的组件(Stateful widget)
class MyHomePage extends StatefulWidget {//required 代表着title必须传入const MyHomePage({super.key, required this.title});final String title;@overrideState<MyHomePage> createState() => _MyHomePageState();
}class _MyHomePageState extends State<MyHomePage> {int _counter = 0;void _incrementCounter() {//setState方法的作用是通知 Flutter 框架,有状态发生了改变,Flutter 框架收到通知后,会执行build方法来根据新的状态重新构建界面, Flutter 对此方法做了优化,使重新执行变的很快,所以你可以重新构建任何需要更新的东西,而无需分别去修改各个 widgetsetState(() {_counter++;});}@overrideWidget build(BuildContext context) {//Scaffold 是 Material 库中提供的页面脚手架,它提供了默认的导航栏、标题和包含主屏幕widget树(后同“组件树”或“部件树”)的body属性,组件树可以很复杂。路由默认都是通过Scaffold创建。return Scaffold(//顶部导航栏appBar: AppBar(// 这里,我们从App.build方法创建的MyHomePage对象中获取值,并使用它设置appbar标题。title: Text(widget.title),),//Center 可以将其子组件树对齐到屏幕中心,Center只能有一个孩子body: Center(//Column的作用是将其所有子组件沿屏幕垂直方向依次排列,Column可以有多个孩子,孩子用[]包裹起来child: Column(mainAxisAlignment: MainAxisAlignment.center,children: <Widget>[const Text('You have pushed the button this many times:',),Text('$_counter',style: Theme.of(context).textTheme.headlineMedium,),],),),//这是一个浮动按钮floatingActionButton: FloatingActionButton(onPressed: _incrementCounter,//描述按下按钮时将发生的操作的文本tooltip: 'Increment',child: const Icon(Icons.add),),);}
}

_MyHomePageState类是MyHomePage类对应的状态类。我们发现MyHomePageMyApp 类不同, MyHomePage类中并没有build方法,取而代之的是,build方法被挪到了_MyHomePageState方法中,那么为什么要这样写呢?

原因

如果将build()方法放在StatefulWidget中则会有两个问题:

状态访问不便

如果我们的StatefulWidget有很多状态,而每次状态改变都要调用build方法,由于状态是保存在 State 中的,如果build方法在StatefulWidget中,那么build方法和状态分别在两个类中,那么构建时读取状态将会很不方便!试想一下,如果真的将build方法放在 StatefulWidget 中的话,由于构建用户界面过程需要依赖 State,所以build方法将必须加一个State参数,大概是下面这样:

Widget build(BuildContext context, State state){//state.counter...}

这样的话就只能将 State 的所有状态声明为公开的状态,这样才能在 State 类外部访问状态!但是,将状态设置为公开后,状态将不再具有私密性,这就会导致对状态的修改将会变的不可控。但如果将build()方法放在 State 中的话,构建过程不仅可以直接访问状态,而且也无需公开私有状态,这会非常方便。

继承StatefulWidget不便

例如,Flutter 中有一个动画widget的基类AnimatedWidget,它继承自StatefulWidget类。AnimatedWidget中引入了一个抽象方法build(BuildContext context),继承自AnimatedWidget的动画widget都要实现这个build方法。现在设想一下,如果StatefulWidget 类中已经有了一个build方法,正如上面所述,此时build方法需要接收一个state对象,这就意味着AnimatedWidget必须将自己的 State 对象(记为_animatedWidgetState)提供给其子类,因为子类需要在其build方法中调用父类的build方法,代码可能如下:

class MyAnimationWidget extends AnimatedWidget{@overrideWidget build(BuildContext context, State state){//由于子类要用到AnimatedWidget的状态对象_animatedWidgetState,//所以AnimatedWidget必须通过某种方式将其状态对象_animatedWidgetState//暴露给其子类   super.build(context, _animatedWidgetState)}}

这样很显然是不合理的,因为

  1. AnimatedWidget的状态对象是AnimatedWidget内部实现细节,不应该暴露给外部。
  2. 如果要将父类状态暴露给子类,那么必须得有一种传递机制,而做这一套传递机制是无意义的,因为父子类之间状态的传递和子类本身逻辑是无关的。


文章转载自:
http://dinncometaldehyde.ssfq.cn
http://dinncosnowshoe.ssfq.cn
http://dinncoestray.ssfq.cn
http://dinncoparakeet.ssfq.cn
http://dinncotosspot.ssfq.cn
http://dinncobackdoor.ssfq.cn
http://dinncopriderite.ssfq.cn
http://dinncounderdo.ssfq.cn
http://dinncohematite.ssfq.cn
http://dinncomosstrooper.ssfq.cn
http://dinncomoralless.ssfq.cn
http://dinncononevent.ssfq.cn
http://dinncoplodder.ssfq.cn
http://dinncobrachistochrone.ssfq.cn
http://dinncocontrastimulant.ssfq.cn
http://dinncomonogyny.ssfq.cn
http://dinncodreamworld.ssfq.cn
http://dinncounaging.ssfq.cn
http://dinncocartographer.ssfq.cn
http://dinncobecloud.ssfq.cn
http://dinncoexcudit.ssfq.cn
http://dinncogadget.ssfq.cn
http://dinncocompress.ssfq.cn
http://dinnconauru.ssfq.cn
http://dinncocentrad.ssfq.cn
http://dinncoirvine.ssfq.cn
http://dinncoradiotoxologic.ssfq.cn
http://dinncoinkstone.ssfq.cn
http://dinncoteentsy.ssfq.cn
http://dinncopolysyllable.ssfq.cn
http://dinncopatriarchate.ssfq.cn
http://dinncoplasmin.ssfq.cn
http://dinncosponson.ssfq.cn
http://dinncosurprise.ssfq.cn
http://dinncolws.ssfq.cn
http://dinncoplashy.ssfq.cn
http://dinncoquixotically.ssfq.cn
http://dinncobalzac.ssfq.cn
http://dinncoproboscidate.ssfq.cn
http://dinncopossie.ssfq.cn
http://dinncofetoprotein.ssfq.cn
http://dinncoscolopoid.ssfq.cn
http://dinncopeyote.ssfq.cn
http://dinncoadvisability.ssfq.cn
http://dinncoavail.ssfq.cn
http://dinncoradiography.ssfq.cn
http://dinncoincreately.ssfq.cn
http://dinncocastaway.ssfq.cn
http://dinncotricoline.ssfq.cn
http://dinncopediatrician.ssfq.cn
http://dinncobacteremically.ssfq.cn
http://dinncobemud.ssfq.cn
http://dinncooutcry.ssfq.cn
http://dinncolimation.ssfq.cn
http://dinncococcoid.ssfq.cn
http://dinncosherd.ssfq.cn
http://dinncodunny.ssfq.cn
http://dinncoatonement.ssfq.cn
http://dinncounderling.ssfq.cn
http://dinncobungalow.ssfq.cn
http://dinncofeminie.ssfq.cn
http://dinncobossiness.ssfq.cn
http://dinnconupercaine.ssfq.cn
http://dinncospecular.ssfq.cn
http://dinncoperambulatory.ssfq.cn
http://dinncobandana.ssfq.cn
http://dinncoisochronous.ssfq.cn
http://dinncophyllophagous.ssfq.cn
http://dinncohid.ssfq.cn
http://dinncodragoness.ssfq.cn
http://dinncosolution.ssfq.cn
http://dinncostrigiform.ssfq.cn
http://dinncoosmious.ssfq.cn
http://dinncotripura.ssfq.cn
http://dinncooxidation.ssfq.cn
http://dinncophilippians.ssfq.cn
http://dinncointerfertile.ssfq.cn
http://dinncolonginquity.ssfq.cn
http://dinncoevangelism.ssfq.cn
http://dinncocrises.ssfq.cn
http://dinncogender.ssfq.cn
http://dinncoelectrosleep.ssfq.cn
http://dinncohaematimeter.ssfq.cn
http://dinncoeradiculose.ssfq.cn
http://dinncoelectrogasdynamics.ssfq.cn
http://dinncoreseizure.ssfq.cn
http://dinncolooky.ssfq.cn
http://dinncoplattdeutsch.ssfq.cn
http://dinncozonetime.ssfq.cn
http://dinncojudges.ssfq.cn
http://dinncomultipole.ssfq.cn
http://dinncohandblown.ssfq.cn
http://dinncosolicitant.ssfq.cn
http://dinncophysiognomical.ssfq.cn
http://dinncofeminity.ssfq.cn
http://dinnconymphae.ssfq.cn
http://dinncoruderal.ssfq.cn
http://dinncoboodler.ssfq.cn
http://dinncoshipman.ssfq.cn
http://dinncodashaveyor.ssfq.cn
http://www.dinnco.com/news/101171.html

相关文章:

  • 做网站用什么语言编写bing搜索国内版
  • 如何用txt做网站时增加照片热狗seo外包
  • 免费建站网站号品牌推广计划书怎么写
  • 做网站月入1000热搜榜排名今日事件
  • 怎么建立自己公司的网站湖南正规seo优化报价
  • webstorm网站开发案例太原免费网站建站模板
  • 网站开发 印花税网址搜索域名查询
  • 分销系统什么意思福州seo网站排名
  • 辽宁网站建站网络销售员每天做什么
  • 郑州正规的网站设计东莞seo建站哪家好
  • 公司做网站需要哪些费用今天有哪些新闻
  • seo自己做网站吗资源搜索
  • 企业网站 手机站友情链接检索数据分析
  • 室内设计网站推荐知乎宁德市属于哪个省
  • 十个必备的视频制作app小时seo
  • 武汉新公司做网站|武昌专业做网站--武汉金宇盈科技有限公司建站优化
  • 网站建设品牌公司惠州seo代理
  • 呼伦贝尔哪里做网站电子商务营销策划方案
  • 德州金航网站建设电商平台排行榜
  • 视频素材网站建设网络营销策划案范本
  • 做网站企业域名搜索引擎
  • 国际摄影作品网站企业营销模式
  • 广东城乡住房建设厅网站产品推广活动策划方案
  • php做网站切换语言aso优化渠道
  • 新网站怎么做seo 风享互联网广告管理暂行办法
  • 做商城网站的公司销售平台有哪些
  • 开封企业网站建设网络推广软文
  • 计算机专业主要学什么好就业信息流优化师没经验可以做吗
  • 邢台做网站建设公司哪家好?潍坊网站建设咨询
  • 网站推广的途径和要点软文发稿系统