当前位置:网站首页>[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 )
边栏推荐
- OpenHarmony如何启动远程设备的FA
- [cloud native] briefly talk about the understanding of flume, a massive data collection component
- 【Leetcode】13. Roman numeral to integer
- 远程办公对我们的各方面影响心得 | 社区征文
- 【Leetcode】14. Longest Common Prefix
- C语言自定义函数的方法
- Executive engine module of high performance data warehouse practice based on Impala
- Seven charts, learn to do valuable business analysis
- 使用知行之桥的API端口,提供资源供合作伙伴访问
- 871. Minimum refueling times
猜你喜欢
Rock PI Development Notes (II): start with rock PI 4B plus (based on Ruixing micro rk3399) board and make system operation
MOSFET器件手册关键参数解读
电脑自带软件使图片底色变为透明(抠图白底)
超卓航科上市:募资9亿市值超60亿 成襄阳首家科创板企业
871. 最低加油次数
如何与博格华纳BorgWarner通过EDI传输业务数据?
Tech talk activity preview | building intelligent visual products based on Amazon kVs
Day 18 of leetcode dynamic planning introduction
关于举办科技期刊青年编辑沙龙——新时代青年编辑应具备的能力及提升策略的通知...
对接保时捷及3PL EDI案例
随机推荐
TCP拥塞控制详解 | 2. 背景
What will you do after digital IC Verification?
【Leetcode】14. 最长公共前缀
如何与博格华纳BorgWarner通过EDI传输业务数据?
电脑自带软件使图片底色变为透明(抠图白底)
Understand one article: four types of data index system
Just a coincidence? The mysterious technology of apple ios16 is even consistent with the products of Chinese enterprises five years ago!
有赞和腾讯云、阿里云一同摘得“中国企业云科技服务商50强”[通俗易懂]
酒仙网IPO被终止:曾拟募资10亿 红杉与东方富海是股东
PWM controlled steering gear
2322. 从树中删除边的最小分数(异或和&模拟)
剑指 Offer 24. 反转链表
默认浏览器设置不了怎么办?
使用知行之桥的API端口,提供资源供合作伙伴访问
Deep learning image data automatic annotation [easy to understand]
Domestic relatively good OJ platform [easy to understand]
【云原生】简单谈谈海量数据采集组件Flume的理解
L'explosion de John utilise l'encodage d'entrée par défaut: UTF - 8 Loaded 1 password Hash (bcrypt [blowfish 32 / 64 X3])
C语言自定义函数的方法
VMware安装win10镜像