当前位置:网站首页>[shutter] dart data type (dynamic data type)
[shutter] dart data type (dynamic data type)
2022-07-02 17:13:00 【Programmer community】
List of articles
- One 、 dynamic data type
- Two 、 dynamic Variables cannot be syntax checked
- 3、 ... and 、 dynamic Variable runtime type modification
- Four 、 Complete code example
- 5、 ... and 、 Related resources
Dart In language dynamic , var , Object ,
3
3
3 Type of data ;
One 、 dynamic data type
dynamic data type : dynamic yes Drat In language Dynamic data type , adopt dynamic Keyword defined variables , stay The defined data type will not be controlled during compilation , The type of variable is handled only at runtime , Infer the current according to the type of variable assignment dynamic Runtime data type of data type , dynamic Variables only know the data type at run time ;
dynamic Variable definitions :
dynamic Variable name = A variable's value
dynamic Example of variable code :
dynamicDemo(){
dynamic d = "CSDN"; // Print dynamic The runtime type of the variable print(d.runtimeType); // Print dynamic A variable's value print(d); }
Running results :
StringCSDN
Two 、 dynamic Variables cannot be syntax checked
adopt dynamic Variables can define any data type , At compile time, the Dart The static syntax check of the language is invalid ;
Such as : First, define dynamic Variable , Assigned a string , Then call a method that does not belong to the string object , There must be a mistake here , But the static syntax check can't find out , You can only know the error here when the error is reported in the last run ;
An error occurred while running :
this Flutter There is also an error message in the interface :
3、 ... and 、 dynamic Variable runtime type modification
dynamic data type The runtime type can be changed , Aforementioned dynamic d The type is initialized to String type , Assign an integer to this variable halfway , At this point, the type of the variable becomes int type ;
Code example : For the first dynamic The variable is assigned a value String Type values “CSDN” , And then to dynamic The variable is assigned a value int Type values 666 ;
dynamicDemo(){
dynamic d = "CSDN"; // Print dynamic The runtime type of the variable print(d.runtimeType); // Print dynamic A variable's value print(d); // call dynamic Variable method , Static compilation cannot check for errors , The runtime will report an error //d.getName(); // by dynamic Variable assignment int data d = 666; // Print dynamic The runtime type of the variable print(d.runtimeType); // Print dynamic A variable's value print(d); }
Running results :
StringCSDNint666
Four 、 Complete code example
import 'package:flutter/material.dart';class DartType extends StatefulWidget {
@override _DartTypeState createState() => _DartTypeState();}class _DartTypeState extends State<DartType> {
@override Widget build(BuildContext context) {
dynamicDemo(); return Container(); } dynamicDemo(){
dynamic d = "CSDN"; // Print dynamic The runtime type of the variable print(d.runtimeType); // Print dynamic A variable's value print(d); // call dynamic Variable method , Static compilation cannot check for errors , The runtime will report an error //d.getName(); // by dynamic Variable assignment int data d = 666; // Print dynamic The runtime type of the variable print(d.runtimeType); // Print dynamic A variable's value print(d); }}
Running results :
StringCSDNint666
5、 ... and 、 Related resources
Reference material :
- Dart Developer website : https://api.dart.dev/
- Flutter Chinese net ( unofficial , The translation is very good ) : https://flutterchina.club/ , http://flutter.axuer.com/docs/
- Flutter Official website : https://flutter.dev/ ( Quilt wall )
- official GitHub Address : https://github.com/flutter
- Flutter Related issues : https://flutterchina.club/faq/ ( It is recommended to watch it at the introductory stage )
Blog source download :
GitHub Address : https://github.com/han1202012/flutter_app_hello ( Keep updating with the progress of the blog , There may not be the source code of this blog )
Blog source snapshot : https://download.csdn.net/download/han1202012/15110705 ( The source code snapshot of this blog , You can find the source code of this blog )
边栏推荐
- Deep learning image data automatic annotation [easy to understand]
- Use the API port of the bridge of knowledge and action to provide resources for partners to access
- 酒仙网IPO被终止:曾拟募资10亿 红杉与东方富海是股东
- System Verilog implements priority arbiter
- [essay solicitation activity] Dear developer, RT thread community calls you to contribute
- IP address translation address segment
- Leetcode1380: lucky numbers in matrix
- JS delete substring in string
- P6774 [NOI2020] 时代的眼泪(分块)
- 剑指 Offer 22. 链表中倒数第k个节点
猜你喜欢
Cell: Tsinghua Chenggong group revealed an odor of skin flora. Volatiles promote flavivirus to infect the host and attract mosquitoes
john爆破出現Using default input encoding: UTF-8 Loaded 1 password hash (bcrypt [Blowfish 32/64 X3])
Xiaopeng P7 had an accident on rainy days, and the airbag did not pop up. Official response: the impact strength did not meet the ejection requirements
DigiCert SSL证书支持中文域名申请吗?
Serial port controls steering gear rotation
Configure MySQL under Linux to authorize a user to access remotely, which is not restricted by IP
OpenHarmony如何启动远程设备的FA
Interpretation of key parameters in MOSFET device manual
Connect Porsche and 3PL EDI cases
Use of openpose
随机推荐
linux下配置Mysql授权某个用户远程访问,不受ip限制
Believe in yourself and finish the JVM interview this time
ETH数据集下载及相关问题
2、 Expansion of mock platform
【Leetcode】13. 罗马数字转整数
Use of openpose
Learning Weekly - total issue 60 - 25th week of 2022
2322. Remove the minimum fraction of edges from the tree (XOR and & Simulation)
Serial port controls steering gear rotation
13、Darknet YOLO3
Just a coincidence? The mysterious technology of apple ios16 is even consistent with the products of Chinese enterprises five years ago!
A case study of college entrance examination prediction based on multivariate time series
P6774 [NOI2020] 时代的眼泪(分块)
Does digicert SSL certificate support Chinese domain name application?
綠竹生物沖刺港股:年期內虧損超5億 泰格醫藥與北京亦莊是股東
System Verilog实现优先级仲裁器
绿竹生物冲刺港股:年期内亏损超5亿 泰格医药与北京亦庄是股东
基于多元时间序列对高考预测分析案例
871. Minimum refueling times
【云原生】简单谈谈海量数据采集组件Flume的理解