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

网站建设怎么下载代码seo搜狗排名

网站建设怎么下载代码,seo搜狗排名,高档网站建,python能否做网站flutter开发实战-第一帧布局完成回调实现 在开发中,我们有时候需要在第一帧布局完成后调用一些相关的方法。这里记录一下是实现过程。 Flutter中有多种不同的Binding,每种Binding都负责不同的功能。下面是Flutter中常见的Binding: 这里简单…

flutter开发实战-第一帧布局完成回调实现
在这里插入图片描述
在开发中,我们有时候需要在第一帧布局完成后调用一些相关的方法。这里记录一下是实现过程。

Flutter中有多种不同的Binding,每种Binding都负责不同的功能。下面是Flutter中常见的Binding:
这里简单说明一下WidgetsBinding

一、WidgetsBinding

WidgetsBinding:负责管理Flutter应用程序的生命周期,包括启动、暂停、恢复和停止等。
WidgetsBinding它用于监听用户设置的更改,如语言的修改。 不仅如此, WidgetsBinding 否是 Widgets 与 Flutter 引擎之间通信的桥梁,有两个主要的功能:
  * 1 负责处理Widgets结构变更的过程;
  * 2 第二个是触发渲染事件。
一些小组件的结构更改是 BuildOwner 来完成的,它跟踪需要重建的小部件,并处理应用于整个小部件结构的其他任务。

二、实现第一帧布局完成后调用相关方法

在WidgetsBinding中,我们可以看到endOfFrame方法,源码如下

/// Returns a Future that completes after the frame completes.////// If this is called between frames, a frame is immediately scheduled if/// necessary. If this is called during a frame, the Future completes after/// the current frame.////// If the device's screen is currently turned off, this may wait a very long/// time, since frames are not scheduled while the device's screen is turned/// off.Future<void> get endOfFrame {if (_nextFrameCompleter == null) {if (schedulerPhase == SchedulerPhase.idle) {scheduleFrame();}_nextFrameCompleter = Completer<void>();addPostFrameCallback((Duration timeStamp) {_nextFrameCompleter!.complete();_nextFrameCompleter = null;});}return _nextFrameCompleter!.future;}

方法中描述如下

该方法返回在帧完成后完成的Future。
如果在帧之前调用的时候,则会立即调度帧。如果在帧期间调用此操作,则Future将在当前帧完成后调用。
如果设备的屏幕当前已关闭,这可能会等待很长时间。

所以我们需要在initState中调用相关方法

WidgetsBinding.instance.endOfFrame.then((value) {if (mounted) {// TODO调用相关方法}},);

实现第一帧布局完成后调用完成代码如下

class AfterLayoutPage extends StatefulWidget {const AfterLayoutPage({super.key});@overrideState<AfterLayoutPage> createState() => _AfterLayoutPageState();
}class _AfterLayoutPageState extends State<AfterLayoutPage> {@overrideWidget build(BuildContext context) {return Scaffold(appBar: AppBar(title: const Text('AfterLayoutPage'),),body: Container(color: Colors.blueGrey,),);}@overridevoid initState() {// TODO: implement initStatesuper.initState();WidgetsBinding.instance.endOfFrame.then((value) {if (mounted) {showHelloWorld();}},);}void showHelloWorld() {showDialog(context: context,builder: (BuildContext context) {return AlertDialog(content: const Text('Hello World'),actions: <Widget>[TextButton(onPressed: () => Navigator.of(context).pop(),child: const Text('DISMISS'),)],);},);}
}

可以将该实现包装成一个Mixin

import 'dart:async';import 'package:flutter/widgets.dart';mixin AfterLayoutMixin<T extends StatefulWidget> on State<T> {@overridevoid initState() {super.initState();WidgetsBinding.instance.endOfFrame.then((_) {if (mounted) afterFirstLayout(context);},);}FutureOr<void> afterFirstLayout(BuildContext context);
}

调整后代码如下

class AfterLayoutPage extends StatefulWidget {const AfterLayoutPage({super.key});@overrideState<AfterLayoutPage> createState() => _AfterLayoutPageState();
}class _AfterLayoutPageState extends State<AfterLayoutPage> with AfterLayoutMixin<AfterLayoutPage> {@overrideWidget build(BuildContext context) {return Scaffold(appBar: AppBar(title: const Text('AfterLayoutPage'),),body: Container(color: Colors.blueGrey,),);}@overridevoid afterFirstLayout(BuildContext context) {// Calling the same function "after layout" to resolve the issue.showHelloWorld();}void showHelloWorld() {showDialog(context: context,builder: (BuildContext context) {return AlertDialog(content: const Text('Hello World'),actions: <Widget>[TextButton(onPressed: () => Navigator.of(context).pop(),child: const Text('DISMISS'),)],);},);}
}

三、小结

flutter开发实战-第一帧布局完成回调实现

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

http://www.yayakq.cn/news/484019/

相关文章:

  • 软件开发包括网站开发吗下载用的网站怎么做
  • 网站空间免费的能用吗青岛代理记账多少钱
  • 个人网站设计与开发电商网站创办过程
  • 晋江模板建站怎么做图片展示网站
  • 郑州网站免费制作图片主题wordpress
  • 网站 备案 中国 名字清远市seo广告优化
  • 招聘网站建设价格网站建设与管理 教学设计
  • 手机网站推荐哪些重庆网站icp备案查询
  • 网站开发范围说明书百度软件应用中心下载
  • 央企直招出国劳务网站北京建设
  • 相关网站怎么做化妆品网络营销策划方案
  • 美橙互联 送网站提供网站建设课程代码
  • 建网站赚钱网站建设ppt演示文稿
  • 注册网站什么要求广告信息
  • 正能量不良网站直接进入wordpress导航链接
  • 重庆建网站推广价格如何建设淘宝网站
  • 中石化第四建设有限公司网站北京住房城乡建设部网站八大员
  • 单页营销网站模板网站建设怎么样工作
  • 网站建设目的和功能定位wordpress填写信息插件
  • 原创 网站 源码加强思政部网站建设
  • 手机网站类型手机html网页制作软件
  • 云南建设厅网站首页免费创网站
  • 网站建设学习什么平台运营需要多少钱
  • 织梦网站图片不显示图片河南网站建设工作室
  • 嘉兴品牌网站建设贵阳网站网站建设
  • 电子商务网站建设html王烨妮
  • 网站的背景图怎么做万户网络公司如何
  • 网站建设开发服务费怎么做账怎样建设自己的网站的视频
  • 网站文章不收录的原因用dw做的网站怎么上传图片
  • 什么是cms网站系统番禺人才网招聘网