当前位置:网站首页>[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 )
边栏推荐
- sql-labs
- 【Hot100】21. Merge two ordered linked lists
- How my mother-in-law and daughter-in-law get along
- Implementing yolox from scratch: dataset class
- Outsourcing for three years, abandoned
- Review of the latest 2022 research on "deep learning methods for industrial defect detection"
- In depth understanding of modern web browsers (I)
- [cloud native topic -49]:kubesphere cloud Governance - operation - step by step deployment of microservice based business applications - basic processes and steps
- Research Report on the overall scale, major manufacturers, major regions, products and application segmentation of shock absorber oil in the global market in 2022
- 数据库模式笔记 --- 如何在开发中选择合适的数据库+关系型数据库是谁发明的?
猜你喜欢
Codeforces round 651 (Div. 2) (a thinking, B thinking, C game, D dichotomy, e thinking)
[NLP] a detailed generative text Abstract classic paper pointer generator
Data preparation for behavior scorecard modeling
Istio1.12: installation and quick start
Highly qualified SQL writing: compare lines. Don't ask why. Asking is highly qualified..
【每日一题】241. 为运算表达式设计优先级
Review of the latest 2022 research on "deep learning methods for industrial defect detection"
Taiwan SSS Xinchuang sss1700 replaces cmmedia cm6533 24bit 96KHz USB audio codec chip
笔记本安装TIA博途V17后出现蓝屏的解决办法
Redis sentinel cluster working principle and architecture deployment # yyds dry goods inventory #
随机推荐
[real case] trap of program design - beware of large data
[QT] QPushButton creation
AcWing 341. Optimal trade solution (shortest path, DP)
[871. Minimum refueling times]
Research Report on the overall scale, major manufacturers, major regions, products and applications of battery control units in the global market in 2022
功能、作用、效能、功用、效用、功效
Research Report on the overall scale, major manufacturers, major regions, products and applications of hollow porcelain insulators in the global market in 2022
After writing 100000 lines of code, I sent a long article roast rust
Automatic reading of simple books
[internship] solve the problem of too long request parameters
Basic concept of database, installation and configuration of database, basic use of MySQL, operation of database in the project
Highly qualified SQL writing: compare lines. Don't ask why. Asking is highly qualified..
Development skills of rxjs observable custom operator
Cron表达式(七子表达式)
Share several map bed websites for everyone to share pictures
[Chongqing Guangdong education] reference materials for labor education of college students in Nanjing University
How to realize the function of detecting browser type in Web System
Istio1.12: installation and quick start
CRM Customer Relationship Management System
Research Report on the overall scale, major manufacturers, major regions, products and application segmentation of multi-channel signal conditioners in the global market in 2022