当前位置:网站首页>Actual combat of shutter statefulwidget
Actual combat of shutter statefulwidget
2022-07-21 21:32:00 【Blue faced scholar】
It took two years flutter, Have some experience , Some cases will be updated from today , Not empty head and brain , Only for practical use , For study or use flutter My little friend's reference , Learning is still shallow , If there is anything wrong, we hope all gods will correct it , So as not to mislead others , Thank you here. ~( Originality is not easy. , Please indicate the source and author when forwarding
Be careful : No special instructions ,flutter Version is 3.0+
Widget: Components , This concept can be seen everywhere in large front-end development , Very easy to understand , So in Flutter in Widget Has a wide range of concepts , It can be said that almost all objects are Widget( Everything is Widget It's also Flutter The core design idea of ),Flutter through Widget Nested to build ui Of , This is also a lot of people vomit bad Flutter The place of , ha-ha ~
One .Widget
First look at the official explanation
/// Describes the configuration for an [Element].
Widget Namely Element Configuration information , Here comes another important concept Element. that Element( Elements ) And what is it , The official explanation is as follows :
/// An instantiation of a [Widget] at a particular location in the tree.
Literally Element yes Widget Example . This involves tree, Then I have to mention Flutter Of ” skshu “:Widgets Trees ,Element Trees and Render Trees ( Render tree ).Widgets Tree generated Element Trees ,Element Tree generated Render Trees , This is also Flutter Rendering process of , In this article, we are wrong first Flutter The rendering process of has been explored too much , Understand first Widget The concept of .
Two .StatelessWidget and StatefulWidget
3、 ... and .StatefulWidget Use
1. According to the interface api The refresh data
@override
void initState() {
Api.getRelation(id).then((v) {
setState(() {
data = v;
});
});
super.initState();
}
...
static ScaffoldState of(BuildContext context) {
assert(context != null);
final ScaffoldState? result = context.findAncestorStateOfType<ScaffoldState>();
if (result != null)
return result;...
For example, we need to call Scaffold Of openDraw() Open the side sliding drawer , You can use Scaffold.of(context) obtain State
Scaffold.of(context).openDrawer()
We can also imitate this way in actual development
Mode two : adopt GlobalKey obtain state
This way is also our common way , Follow vue in key The concept of using is the same , however Globalkey The cost is relatively large , Use as little as possible
final GlobalKey<State> _globalKey = GlobalKey();
...
_globalKey.currentState.function();
Mode three : take state Directly exposed
This author often uses , I think it's very convenient . For example, you need to customize the variable header component , Then you can call state Methods
class EditView extends StatefulWidget {
// You can customize the incoming header
final dynamic mainItem;
...
@override
Widget build(BuildContext context) {
return Column(children:[ widget.mainItem(this); // take state Expose
])
....
void xxFunction(){
}
In use You can put the state Pass it to the head component , stay mainItem Component calls EditWidget Internal method of xxFunction().
EditView(
mainItem:(state)=>widget1(state)
)
widget1(state){
state.xxFunction()
}
3. Call the method after the component is loaded
WidgetsBinding We mentioned this in the previous article ,
/// Schedule a callback for the end of this frame.
.....
/// * [scheduleFrameCallback], which registers a callback for the start of
/// the next frame.
Call before the start of the next frame The method , It can be used as follows :
@override
void initState() {
// initialization map
super.initState(); WidgetsBinding.instance.addPostFrameCallback((_) {
// Add method
});}
Specific usage scenarios can be mined in your own project practice .
边栏推荐
- 源代码阅读
- 【MySQL】MySQL中 UNION 并的使用
- Qualcomm CAMX debug log control
- Notes on insert statements in azure SQL DW
- PostgreSQL HA集群高可用方案介绍 & pgpool-II+PostgreSQL HA方案部署
- Introduction to PostgreSQL ha cluster high availability scheme & pgpool-ii + PostgreSQL ha scheme deployment
- Do you know what are the schemes of the list paging interface?
- PostGIS 空间数据(geometry)管理常用命令
- 【MySQL】MySQL内连接和外连接详细总结
- LiveData 还有学习的必要吗?—— Jetpack 系列(2)
猜你喜欢
(note) Wu Enda deep learning L4 convolutional neural network W1
记一次 kotlin 在 MutableList 中使用 remove 引发的问题
Do you know what are the schemes of the list paging interface?
vi/vim基本命令
量子力学奇妙之旅-前置准备
LiveData 还有学习的必要吗?—— Jetpack 系列(2)
Invalid bound statement (not found): com.example.demo1.mapper.UserMapper.XXX
Qualcomm CAMX debug log control
Notes on insert statements in azure SQL DW
Lifecycle:生命周期感知型组件的基础 —— Jetpack 系列(1)
随机推荐
Invalid bound statement (not found): com.example.demo1.mapper.UserMapper.XXX
Introduction to PostgreSQL ha cluster high availability scheme & pgpool-ii + PostgreSQL ha scheme deployment
GIS-国内常见的地理坐标系
量子力学奇妙之旅-算符和电子自旋
Kotlin入门
【使用Kotlin编写您编写的第一个程序】
信号反射的前世今生
Output file is empty, nothing was encoded (check -ss / -t / -frames parameters if used) 解决方法
Use matlab app design tool to design a simple app
(note) Wu Enda's in-depth study l4w2
SQL SERVER索引基础详解___概念及原理
vi/vim基本命令
【PyTorch教程】02-如何获取张量的形状维度、数据类型和所在设备
Amy Tabb robot world hand eye calibration (2. Experimental results)
PostgreSQL新建用户登录报错:FATAL: Peer authentication failed for user “test“
[MySQL] 19-how to create and manage databases in MySQL
【PyTorch教程】05-如何使用PyTorch训练神经网络模型 (2022年最新)
[MySQL] 15 super detailed MySQL date type function summary
Dart 基础概念和内部原理
GIS WKB/EWKB 结构