当前位置:网站首页>[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 ;
StringCSDN
Two 、 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 ;
StringCSDN
Object 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 :
StringCSDNint666StringCSDNStringCSDN
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/15113321 ( The source code snapshot of this blog , You can find the source code of this blog )
边栏推荐
- SLAM|如何时间戳对齐?
- sql训练2
- SLC、MLC、TLC 和 QLC NAND SSD 之间的区别:哪个更好?
- 任职 22 年,PowerShell 之父将从微软离职:曾因开发 PowerShell 被微软降级过
- Looking for innocence in New York -- a beautiful day at the discovery center of Legoland, New Jersey
- 一款简约PHP个人发卡程序V4.0版本
- @Component 拿不到dao层
- Leetcode 面试题 17.04. 消失的数字
- Paddlepaddle 28 build an automatic coder based on convolution
- 在Tensorflow2中使用mnist_784数据集进行手写数字识别
猜你喜欢
LightGroupButton* sender = static_ cast<LightGroupButton*>(QObject::sender());
300+篇文献!一文详解基于Transformer的多模态学习最新进展
How to clean up discarded PVs and their corresponding folders
Unity learning shader notes [82] black and white processing of enhanced single channel color rendering
夜神模拟器+Fiddler抓包测试App
Leetcode(81)——搜索旋转排序数组 II
UE4 用spline畫正圓
Redis(7)----数据库与过期键
Leetcode 面试题 17.04. 消失的数字
[Yugong series] July 2022 go teaching course 001 introduction to go language premise
随机推荐
SLAM|如何时间戳对齐?
Google's official response: we have not given up tensorflow and will develop side by side with Jax in the future
Redis (6) -- object and data structure
在支付宝账户上买基金安全吗
promise 和 Observable 的区别
Websocket of Web real-time communication technology
Responses of different people in technology companies to bugs | daily anecdotes
C语言中函数参数传递的三种方式
Deep neural network Summary
What are the links of the problem
Relax again! These fresh students can settle directly in Shanghai
Leetcode interview question 16.11 Diving board
Simulateur nightGod + application de test de capture de paquets Fiddler
27:第三章:开发通行证服务:10:【注册/登录】接口:注册/登录OK后,把用户会话信息(uid,utoken)保存到redis和cookie中;(一个主要的点:设置cookie)
夜神模拟器+Fiddler抓包测试App
夜神模擬器+Fiddler抓包測試App
【愚公系列】2022年07月 Go教学课程 001-Go语言前提简介
Esp32-c3 introductory tutorial question ⑪ - ESP tls: create_ ssl_ handle failed, tls_ io_ instance->options. trusted_ certs null
SAP S/4HANA OData Mock Service 介绍
CDN acceleration and breaking J anti-theft chain function