当前位置:网站首页>[fluent] dart data type (VaR data type | object data type)
[fluent] dart data type (VaR data type | object data type)
2022-07-02 18:51:00 【Programmer community】
List of articles
- One 、 var data type
- Two 、 var The data type cannot be changed
- 3、 ... and 、 Object type
- Four 、 Complete code example
- 5、 ... and 、 Related resources
Dart In language dynamic , var , Object ,
3
3
3 Type of data ;
One 、 var data type
var It is also a keyword for defining variables , Use var Declare variables , It's also By the system according to the assignment Automatically Infer the data type of the variable ; This usage is similar to dynamic The variables defined by keywords are similar ;
Code example :
varDemo(){
// Statement var Variable var d = "CSDN"; // Print var The runtime type of the variable print(d.runtimeType); // Print var A variable's value print(d); }Running results : d The type of the variable is automatically inferred as String type ;
StringCSDNTwo 、 var The data type cannot be changed
var And dynamic The difference between variables is , once var After the dynamic data type of the variable of type is defined , The number is The data type cannot be modified , If var After the type variable is assigned a string , Assign it again int type , At this time, an error will be reported during compilation ,

3、 ... and 、 Object type
Object yes Base classes for all objects , Some methods are defined , Definition Object Type of variable after , You can call the Object Method ;
When you assign a value to it , Sure Assign the type value of its subclass , Such as string value , amount to Polymorphic usage ;
Object Methods defined in class :
class Object {
const Object(); external bool operator ==(other); external int get hashCode; external String toString(); @pragma("vm:entry-point") external dynamic noSuchMethod(Invocation invocation); external Type get runtimeType;}Code example :
objectDemo(){
// Definition Object Type variable Object d = "CSDN"; // call Object Object method // Print var The runtime type of the variable print(d.runtimeType); // Print var A variable's value print(d); }Running results : Variable d The runtime type of is String type ;
StringCSDNObject Variables and dynamic The difference between variables is , Object The data type is certain , Namely Object type , Object Type variable cannot be called Object A method that does not exist in a class ;

Four 、 Complete code example
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(); varDemo(); objectDemo(); 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); } varDemo(){
// Statement var Variable var d = "CSDN"; // Print var The runtime type of the variable print(d.runtimeType); // Print var A variable's value print(d); // Will have been automatically inferred as String Type of d Assign a value to a variable int Type values // At this time, errors will appear in the compilation //d = 666; } objectDemo(){
// Definition Object Type variable Object d = "CSDN"; // call Object Object method // Print var The runtime type of the variable print(d.runtimeType); // Print var A variable's value print(d); // call Object If there is no method, an error will be reported //d.getName() }}Running results :
StringCSDNint666StringCSDNStringCSDN5、 ... 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/15113321 ( The source code snapshot of this blog , You can find the source code of this blog )
边栏推荐
- Tips for material UV masking
- Server PHP environment building tutorial, PHP server environment building graphic explanation
- 27: Chapter 3: develop Passport Service: 10: [registration / login] interface: after the registration / login is OK, save the user session information (uid, utoken) to redis and cookies; (one main poi
- promise 和 Observable 的区别
- Distance measurement - Jaccard distance
- 饭卡 HDU2546
- Leetcode 面试题 17.04. 消失的数字
- Night God simulator +fiddler packet capture test app
- Is it safe to buy funds on Alipay account
- Ue4 dessine un cercle avec une ligne de contour
猜你喜欢

故障排查:kubectl报错ValidationError: unknown field \u00a0

夜神模拟器+Fiddler抓包测试App

M2DGR:多源多场景 地面机器人SLAM数据集(ICRA 2022 )

新加坡暑假旅游攻略:一天玩转新加坡圣淘沙岛

Ue4 dessine un cercle avec une ligne de contour
![Unity learning shader notes [82] black and white processing of enhanced single channel color rendering](/img/db/d745a434e76511742d1264706b5d9a.png)
Unity learning shader notes [82] black and white processing of enhanced single channel color rendering

阿里三面被面试官狂问Redis,简历上再也不敢写'精通'了

新加坡暑假旅遊攻略:一天玩轉新加坡聖淘沙島

工业软件讲堂-三维CAD设计软件的核心技术解析----讲坛第二次讲座

What is cloud primordial? This time, I can finally understand!
随机推荐
Introduction to sap s/4hana OData mock service
Redis(6)----对象与数据结构
快速排序基本思路(通俗易懂+例子)「建议收藏」
Typical application of "stack" - expression evaluation (implemented in C language)
MySQL about only_ full_ group_ By limit
夜神模擬器+Fiddler抓包測試App
Web version 3D visualization tool, 97 things programmers should know, AI frontier paper | information daily # 2022.07.01
Ali was wildly asked by the interviewer on three sides. Redis dared not write 'proficient' on his resume anymore
NM01-独立于总线协议的NM模块功能概述与API定义
The second bullet of AI development and debugging series: the exploration journey of multi machine distributed debugging
Leetcode interview question 16.17 Continuous sequence
材质UV遮罩的技巧
“栈”的典型应用—表达式求值(C语言实现)
StretchDIBits函数
Web版3D可视化工具,程序员应该知道的97件事,AI前沿论文 | 资讯日报 #2022.07.01
promise 和 Observable 的区别
Esp32-c3 introductory tutorial question ⑩ - error: implicit declaration of function 'ESP_ blufi_ close‘;
Installation of thingsboard, an open source IOT platform
Leetcode 面试题 16.17. 连续数列
Is it safe to buy funds on Alipay account