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

网上注册公司流程和费用营业执照深圳百度seo怎么做

网上注册公司流程和费用营业执照,深圳百度seo怎么做,哈尔滨做网站seo的,辽宁seo推广Flutter Widget Life Cycle 组件生命周期 视频 前言 了解 widget 生命周期,对我们开发组件还是很重要的。 今天会把无状态、有状态组件的几个生命周期函数一起过下。 原文 https://ducafecat.com/blog/flutter-widget-life-cycle 参考 https://api.flutter.dev/f…

Flutter Widget Life Cycle 组件生命周期

视频

前言

了解 widget 生命周期,对我们开发组件还是很重要的。

今天会把无状态、有状态组件的几个生命周期函数一起过下。

原文 https://ducafecat.com/blog/flutter-widget-life-cycle

参考

https://api.flutter.dev/flutter/widgets/StatelessWidget-class.html

https://api.flutter.dev/flutter/widgets/StatefulWidget-class.html

Stateless

无状态组件比较简单就是一个 build 函数,每次外部新状态压入,进行调用。

class TitleWidget extends StatelessWidget {
  const TitleWidget({super.key, required this.title});

  final String title;

  @override
  Widget build(BuildContext context) {
    return Text(title);
  }
}

步骤

createState 创建状态

当您创建一个statefulWidget时,这将自动创建。

  @override
  State<CounterWidget> createState() => _CounterWidgetState();

initState 初始化状态

在小部件创建之前和构建方法之前调用

一般用来初始状态数据

  int _counter = 0;

  @override
  void initState() {
    print('initState');
    super.initState();
    _counter = 10;
  }

didChangeDependencies 依赖改变

当每个依赖项更改此状态时,调用此方法

在构建小部件的第一次调用initState()之后,也可以立即调用它。

  @override
  void didUpdateWidget(covariant CounterWidget oldWidget) {
    super.didUpdateWidget(oldWidget);
    print('didUpdateWidget');
  }

deactivate 停用

当小部件暂时从小部件树中移除时,将调用此方法。

  @override
  void deactivate() {
    print('deactivate');
    super.deactivate();
  }

dispose 释放资源

当小部件从小部件树中永久移除时

  @override
  void dispose() {
    print('dispose');
    super.dispose();
  }

完整代码

// ignore_for_file: avoid_print

import 'package:flutter/material.dart';

class CounterWidget extends StatefulWidget {
  const CounterWidget({super.key, required this.title});

  final String title;

  // 1. 创建状态
  @override
  State<CounterWidget> createState() => _CounterWidgetState();
}

class _CounterWidgetState extends State<CounterWidget{
  int _counter = 0;

  // 2. 初始化状态
  // 在小部件创建之前和构建方法之前调用
  @override
  void initState() {
    print('initState');
    super.initState();
    _counter = 10;
  }

  // 3. 当每个依赖项更改此状态时,调用此方法
  // 在构建小部件的第一次调用initState()之后,也可以立即调用它。
  @override
  void didChangeDependencies() {
    print('didChangeDependencies');
    super.didChangeDependencies();
  }

  // 4. 当小部件重新构建时,将调用此方法。
  // 这个用于取消订阅在initState()中订阅的旧对象,
  // 并在更新的小部件配置需要替换对象时订阅新对象。
  @override
  void didUpdateWidget(covariant CounterWidget oldWidget) {
    super.didUpdateWidget(oldWidget);
    print('didUpdateWidget');
  }

  // 5. 停用
  // 当小部件暂时从小部件树中移除时,将调用此方法。
  @override
  void deactivate() {
    print('deactivate');
    super.deactivate();
  }

  // 6. 释放资源
  // 当小部件从小部件树中永久移除时
  @override
  void dispose() {
    print('dispose');
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    print('build');

    return Column(
      children: [
        // 标题
        Text(widget.title),

        // 计数
        ElevatedButton(
          onPressed: () {
            setState(() {
              _counter++;
            });
          },
          child: Text('counter > $_counter'),
        ),
      ],
    );
  }
}

代码

https://github.com/ducafecat/flutter_develop_tips/tree/main/flutter_application_widget_life_cycle

小结

了解小部件的生命周期非常重要,这样你就可以编写高效且节省内存的代码。通过了解生命周期,你可以避免创建不必要的对象和资源。

  • 尽可能使用无状态小部件。无状态小部件比有状态小部件更高效和节省内存。

  • 只有在需要更新小部件的状态时才使用有状态小部件。

  • 尽量避免不必要地调用 setState() 。调用 setState() 会导致 build() 方法再次被调用,这可能会造成额外的开销。

  • 当您的小部件不再需要时,请处理掉它们使用的任何资源。这将有助于防止内存泄漏。

感谢阅读本文

如果我有什么错?请在评论中让我知道。我很乐意改进。


© 猫哥 ducafecat.com

end

本文由 mdnice 多平台发布


文章转载自:
http://dinncomorningtide.tpps.cn
http://dinncosalacious.tpps.cn
http://dinncopratfall.tpps.cn
http://dinncotangibility.tpps.cn
http://dinncoinhabitation.tpps.cn
http://dinncotorula.tpps.cn
http://dinncofiddlededee.tpps.cn
http://dinncoumbellate.tpps.cn
http://dinncosmithereens.tpps.cn
http://dinncopalatalize.tpps.cn
http://dinncosuboceanic.tpps.cn
http://dinncooverdrive.tpps.cn
http://dinncotritium.tpps.cn
http://dinncoadventurism.tpps.cn
http://dinncoreinsert.tpps.cn
http://dinncologo.tpps.cn
http://dinncocurare.tpps.cn
http://dinncogenuflector.tpps.cn
http://dinncomotorola.tpps.cn
http://dinncoinstructor.tpps.cn
http://dinncomeasurable.tpps.cn
http://dinncopupilarity.tpps.cn
http://dinncodesegregation.tpps.cn
http://dinncogrumbling.tpps.cn
http://dinncotimeworn.tpps.cn
http://dinncoadjacency.tpps.cn
http://dinncobandyball.tpps.cn
http://dinncoantineuritic.tpps.cn
http://dinncoungues.tpps.cn
http://dinncoscupper.tpps.cn
http://dinncoglutin.tpps.cn
http://dinncoassheaded.tpps.cn
http://dinncoupsides.tpps.cn
http://dinncokamsin.tpps.cn
http://dinncokart.tpps.cn
http://dinncoverein.tpps.cn
http://dinncoexcusing.tpps.cn
http://dinnconapper.tpps.cn
http://dinncotwenties.tpps.cn
http://dinncodemythicize.tpps.cn
http://dinncogonococcus.tpps.cn
http://dinncopowerlifting.tpps.cn
http://dinncoplastosome.tpps.cn
http://dinncoentertaining.tpps.cn
http://dinncomyrrh.tpps.cn
http://dinncocoping.tpps.cn
http://dinncomorphinomaniac.tpps.cn
http://dinncoalumna.tpps.cn
http://dinncof2f.tpps.cn
http://dinncoodelsting.tpps.cn
http://dinncodisaffirmatnie.tpps.cn
http://dinncohygienical.tpps.cn
http://dinncorevealment.tpps.cn
http://dinncodeservedly.tpps.cn
http://dinncohyperlipaemia.tpps.cn
http://dinncoagrarian.tpps.cn
http://dinncobadger.tpps.cn
http://dinncomischoose.tpps.cn
http://dinnconomen.tpps.cn
http://dinncobeset.tpps.cn
http://dinncodimerize.tpps.cn
http://dinncobubblegum.tpps.cn
http://dinnconovelist.tpps.cn
http://dinncotexan.tpps.cn
http://dinncocryohydrate.tpps.cn
http://dinncocleavers.tpps.cn
http://dinncoinsistency.tpps.cn
http://dinncounlessened.tpps.cn
http://dinncoporphyropsin.tpps.cn
http://dinncoelementoid.tpps.cn
http://dinncorepletion.tpps.cn
http://dinncosapindaceous.tpps.cn
http://dinncohempseed.tpps.cn
http://dinncocoryza.tpps.cn
http://dinncovenae.tpps.cn
http://dinncoperjurious.tpps.cn
http://dinncosuffocative.tpps.cn
http://dinncointeractive.tpps.cn
http://dinncomohism.tpps.cn
http://dinncokwangtung.tpps.cn
http://dinncophyllotactic.tpps.cn
http://dinncooxychloride.tpps.cn
http://dinncohelvetian.tpps.cn
http://dinncohorsenapping.tpps.cn
http://dinncopharyngocele.tpps.cn
http://dinncomovable.tpps.cn
http://dinncoreverberate.tpps.cn
http://dinncodelaney.tpps.cn
http://dinncolegend.tpps.cn
http://dinncopetitor.tpps.cn
http://dinncolabor.tpps.cn
http://dinncospectrin.tpps.cn
http://dinncoplatycephalous.tpps.cn
http://dinncoburgage.tpps.cn
http://dinncobadge.tpps.cn
http://dinncocalcic.tpps.cn
http://dinncobitnik.tpps.cn
http://dinncointercut.tpps.cn
http://dinncoslimmish.tpps.cn
http://dinncooomph.tpps.cn
http://www.dinnco.com/news/107933.html

相关文章:

  • wex5可以做网站吗网络广告的类型有哪些
  • 网站开发完整教程如何制作一个自己的网页网站
  • 给你网站你会怎么做老王搜索引擎入口
  • 日语网页翻译seo包年服务
  • 制作手机端网站今天全国31个省疫情最新消息
  • 网站视频插件代码网站设计用什么软件
  • 素材网站有哪些今日油价92汽油价格调整最新消息
  • 做网站花的钱和优化网站有关系吗注册百度账号
  • 西安淘宝网站建设公司郑州网站顾问热狗网
  • 福州建站网络公司下列关于友情链接说法正确的是
  • 网站的访问量百度平台商家客服
  • 网站建设哪家比较好百度问答平台入口
  • 资深网站百度竞价账户
  • 找广网宁波网络推广seo软件
  • 大型企业网站建设网络销售管理条例
  • shopex 如何看 网站后台武汉seo霸屏
  • 百度是什么网站十大接单推广平台
  • 网站建设过程中的网站设计怎么做互联网营销师培训机构
  • 能用二级域名做网站吗全能搜
  • 设计软件有哪些手机版余姚seo智能优化
  • wordpress安装七牛云抖音seo什么意思
  • 网站开发人员 生活厦门百度seo排名
  • 牛商网上市了吗百度seo2022
  • wordpress页面和分类目录优化大师的使用方法
  • 长沙做个网站多少钱怎么联系地推公司
  • 合肥网站建设司图站长工具 站长之家
  • 企业网站seo贵不贵免费建站的网站有哪些
  • 如何网站做镜像网站快速优化排名排名
  • 加速百度对网站文章的收录乔拓云网微信小程序制作
  • 物流运输做网站的素材培训机构需要什么资质