当前位置:网站首页>[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 : null3、 ... 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 : TomFour 、 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 : Tom5、 ... 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 )
边栏推荐
- Outsourcing for three years, abandoned
- 【每日一题】241. 为运算表达式设计优先级
- [fluent] dart function (function composition | private function | anonymous function | function summary)
- CRM客户关系管理系统
- [internship] solve the problem of too long request parameters
- 【Hot100】22. 括号生成
- 自动化制作视频
- What are the preferential account opening policies of securities companies now? Is it actually safe to open an account online?
- at编译环境搭建-win
- Taiwan SSS Xinchuang sss1700 replaces cmmedia cm6533 24bit 96KHz USB audio codec chip
猜你喜欢

How can testers do without missing tests? Seven o'clock is enough

Second hand housing data analysis and prediction system

Conscience summary! Jupyter notebook from Xiaobai to master, the nanny tutorial is coming!

「 工业缺陷检测深度学习方法」最新2022研究综述
![[871. Minimum refueling times]](/img/5f/75e717d1fc9d1c5f9e1d8f59dda38c.png)
[871. Minimum refueling times]

外包干了三年,废了...
![[internship] solve the problem of too long request parameters](/img/42/413cf867f0cb34eeaf999f654bf02f.png)
[internship] solve the problem of too long request parameters

Shardingsphere jdbc5.1.2 about select last_ INSERT_ ID () I found that there was still a routing problem

I did a craniotomy experiment: talk about macromolecule coding theory and Lao Wang's fallacy from corpus callosum and frontal leukotomy

sql-labs
随机推荐
接口测试到底怎么做?看完这篇文章就能清晰明了
Function, function, efficiency, function, utility, efficacy
c语言链表--待补充
什么叫在线开户?现在网上开户安全么?
数据库模式笔记 --- 如何在开发中选择合适的数据库+关系型数据库是谁发明的?
在网上炒股开户安全吗?我是新手,还请指导
Research Report on the overall scale, major manufacturers, major regions, products and applications of hollow porcelain insulators in the global market in 2022
想请教一下,究竟有哪些劵商推荐?手机开户是安全么?
CRM Customer Relationship Management System
Motivation! Big Liangshan boy a remporté le prix Zhibo! Un article de remerciement pour les internautes qui pleurent
[kubernetes series] comparison of space and memory usage before and after kubedm reset initialization
Friends who firmly believe that human memory is stored in macromolecular substances, please take a look
[QT] QPushButton creation
Driverless learning (4): Bayesian filtering
What is online account opening? Is it safe to open an account online now?
For (Auto A: b) and for (Auto & A: b) usage
外包干了三年,废了...
Research Report on the overall scale, major manufacturers, major regions, products and applications of metal oxide arresters in the global market in 2022
Jetson XAVIER NX上ResUnet-TensorRT8.2速度與顯存記錄錶(後續不斷補充)
有时候只查询一行语句,执行也慢