当前位置:网站首页>[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 :
StringCSDNTwo 、 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 :
StringCSDNint666Four 、 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 :
StringCSDNint6665、 ... 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 )
边栏推荐
- Go zero micro service practical series (VIII. How to handle tens of thousands of order requests per second)
- How to transfer business data with BorgWarner through EDI?
- Masa framework - DDD design (1)
- LSF basic command
- Vscode setting delete line shortcut [easy to understand]
- 福元医药上交所上市:市值105亿 胡柏藩身价超40亿
- Easy language ABCD sort
- 酒仙网IPO被终止:曾拟募资10亿 红杉与东方富海是股东
- 体验居家办公完成项目有感 | 社区征文
- 配置基于接口的ARP表项限制和端口安全(限制用户私自接入傻瓜交换机或非法主机接入)
猜你喜欢

OpenPose的使用

Tech Talk 活动预告 | 基于Amazon KVS打造智能视觉产品

DGraph: 大规模动态图数据集

一文看懂:数据指标体系的4大类型

The poor family once again gave birth to a noble son: Jiangxi poor county got the provincial number one, what did you do right?

Notice on holding a salon for young editors of scientific and Technological Journals -- the abilities and promotion strategies that young editors should have in the new era
![[error record] error -32000 received from application: there are no running service protocol](/img/6c/66099650de46cac88b805e6cfb90b9.jpg)
[error record] error -32000 received from application: there are no running service protocol

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

数字IC手撕代码--投票表决器

Amazon cloud technology community builder application window opens
随机推荐
Tech Talk 活动预告 | 基于Amazon KVS打造智能视觉产品
深度之眼(三)——矩阵的行列式
基于多元时间序列对高考预测分析案例
871. 最低加油次数
The impact of telecommuting on all aspects of our experience | community essay solicitation
Deep learning image data automatic annotation [easy to understand]
社交元宇宙平台Soul冲刺港股:年营收12.8亿 腾讯是股东
移动应用性能工具探索之路
Rock PI Development Notes (II): start with rock PI 4B plus (based on Ruixing micro rk3399) board and make system operation
易语言abcd排序
几行代码搞定RPC服务注册和发现
配置基于接口的ARP表项限制和端口安全(限制用户私自接入傻瓜交换机或非法主机接入)
Error when uploading code to remote warehouse: remote origin already exists
学习周刊-总第60期-2022年第25周
Does digicert SSL certificate support Chinese domain name application?
Seven charts, learn to do valuable business analysis
超卓航科上市:募资9亿市值超60亿 成襄阳首家科创板企业
Leetcode1380: lucky numbers in matrix
JS delete substring in string
Atcoder beginer contest 169 (B, C, D unique decomposition, e mathematical analysis f (DP))