当前位置:网站首页>[fluent] dart technique (independent main function entry | nullable type determination | default value setting)
[fluent] dart technique (independent main function entry | nullable type determination | default value setting)
2022-07-02 20:30:00 【Programmer community】
List of articles
- One 、 Independent main function entry
- Two 、 Nullable type determination
- 3、 ... and 、 Default settings
- Four 、 Complete code example
- 5、 ... and 、 Related resources
One 、 Independent main function entry
stay dart Declaration in the document main() function , You can leave Flutter Environmental Science , Execute this independently main function ;
/// Detachable Flutter Functions executed independently by the environment void main(){
print("main");}
main There are two triangular icons on the left side of the function , Click the button , The... Can be executed main function ;
Two 、 Nullable type determination
Nullable type determination : Not sure if the object is empty , adopt ?. Method call , ( Be similar to Kotlin The nullable type of ) , ? The function of is to determine whether it is empty , If it is empty , Terminate the call , No null pointer exception will be reported ;
/// Detachable Flutter Functions executed independently by the environment void main(){
print("main"); Student student; /// 1. Security call : Not sure if the object is empty , adopt ?. Method call /// ( Be similar to Kotlin The nullable type of ) /// ? The function of is to determine whether it is empty , If it is empty , Terminate the call print(" Print student name : ${student?.name}");}class Student{
String name; int age; Student(this.name, this.age);}
Execution results :
main Print student name : null
3、 ... and 、 Default settings
Use ?? You can set a default value for a null value , If a value is not obtained , Or get null , You can set a default value for this variable or expression ;
student?.name??"Tom"
The function of the above code is if student?.name Value is empty , Then return to “Tom” The default value is ;
Code example :
/// 2. Set the default value /// Use ?? You can set a default value for a null value /// Here if student?.name It's empty , The default value is "Tom" print(" Print student name : ${student?.name??"Tom"}");
Execution results :
Print student name : Tom
Four 、 Complete code example
Complete code example :
/// Detachable Flutter Functions executed independently by the environment void main(){
print("main"); Student student; /// 1. Security call : Not sure if the object is empty , adopt ?. Method call /// ( Be similar to Kotlin The nullable type of ) /// ? The function of is to determine whether it is empty , If it is empty , Terminate the call print(" Print student name : ${student?.name}"); /// 2. Set the default value /// Use ?? You can set a default value for a null value /// Here if student?.name It's empty , The default value is "Tom" print(" Print student name : ${student?.name??"Tom"}");}class Student{
String name; int age; Student(this.name, this.age);}
Code execution result :
main Print student name : null Print student name : Tom
5、 ... and 、 Related resources
Reference material :
- Flutter Official website : https://flutter.dev/
- Flutter Developing documents : https://flutter.cn/docs ( Strongly recommend )
- official GitHub Address : https://github.com/flutter
- Flutter The Chinese community : https://flutter.cn/
- Flutter Practical tutorial : https://flutter.cn/docs/cookbook
- Flutter CodeLab : https://codelabs.flutter-io.cn/
- Dart Chinese document : https://dart.cn/
- 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 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/15463304( The source code snapshot of this blog , You can find the source code of this blog )
边栏推荐
- JASMINER X4 1U deep disassembly reveals the secret behind high efficiency and power saving
- Is it safe to open an account for online stock speculation? I'm a novice, please guide me
- CRM客户关系管理系统
- B端电商-订单逆向流程
- Jetson XAVIER NX上ResUnet-TensorRT8.2速度與顯存記錄錶(後續不斷補充)
- Research Report on the overall scale, major manufacturers, major regions, products and application segmentation of the inverted front fork of the global market in 2022
- 「 工业缺陷检测深度学习方法」最新2022研究综述
- Web3js method to obtain account information and balance
- 【Hot100】21. 合并两个有序链表
- [cloud native topic -49]:kubesphere cloud Governance - operation - step by step deployment of microservice based business applications - basic processes and steps
猜你喜欢
Postman接口测试实战,这5个问题你一定要知道
Friends who firmly believe that human memory is stored in macromolecular substances, please take a look
Jetson XAVIER NX上ResUnet-TensorRT8.2速度与显存记录表(后续不断补充)
AcWing 340. Solution to communication line problem (binary + double ended queue BFS for the shortest circuit)
AMD's largest transaction ever, the successful acquisition of Xilinx with us $35billion
面试经验总结,为你的offer保驾护航,满满的知识点
Implementation of online shopping mall system based on SSM
In depth understanding of modern web browsers (I)
【实习】解决请求参数过长问题
[QT] QPushButton creation
随机推荐
[Chongqing Guangdong education] reference materials for labor education of college students in Nanjing University
Complete example of pytorch model saving +does pytorch model saving only save trainable parameters? Yes (+ solution)
Codeforces Round #771 (Div. 2)(A-C)
How to realize the function of detecting browser type in Web System
Taiwan SSS Xinchuang sss1700 replaces cmmedia cm6533 24bit 96KHz USB audio codec chip
How to do interface testing? After reading this article, it will be clear
Function, function, efficiency, function, utility, efficacy
How can testers do without missing tests? Seven o'clock is enough
CRM Customer Relationship Management System
Resunet tensorrt8.2 speed and video memory record table on Jetson Xavier NX (continuously supplemented later)
Why do I have a passion for process?
【QT】QPushButton创建
Is it safe to buy funds on securities accounts? Where can I buy funds
After eight years of test experience and interview with 28K company, hematemesis sorted out high-frequency interview questions and answers
【Hot100】21. Merge two ordered linked lists
Review of the latest 2022 research on "deep learning methods for industrial defect detection"
【NLP】一文详解生成式文本摘要经典论文Pointer-Generator
在消费互联网时代,诞生了为数不多的头部平台的话
Cs5268 perfectly replaces ag9321mcq typec multi in one docking station solution
有时候只查询一行语句,执行也慢