当前位置:网站首页>[fluent] dart function (function composition | private function | anonymous function | function summary)
[fluent] dart function (function composition | private function | anonymous function | function summary)
2022-07-02 20:22:00 【Programmer community】
List of articles
- One 、Dart Function constitution
- Two 、Dart Private functions
- 3、 ... and 、Dart Anonymous functions
- Four 、 Complete code example
- 5、 ... and 、Dart Methods to summarize
- 6、 ... and 、 Related resources
One 、Dart Function constitution
Dart Function constitution : Method name , Parameters , Return value ;
return type :
- ① default : The return value type can be defaulted ;
- ② Empty type : The return value type can be set to void ;
- ③ The real type : The return value type can be set to the real data type ;
Method name :
- ① Anonymous methods : No method name is required ;
- ② Common method : Methods other than anonymous methods require method names ;
Parameters :
- ① form : Parameters include Parameter type , Parameter name ;
- ② Type default : The parameter type can be defaulted ;
- ③ Parameter classification : Optional parameters , Default parameters ;
Examples of standard methods :
/// Standard method /// The return value is int type /// The function name is sum /// Parameter is int num1, int num2 int sum(int num1, int num2){
return num1 + num2; }
Two 、Dart Private functions
Private method :
- brief introduction : Only methods that can be accessed in the current file are called private methods ;
- Format : Underline the method name , Identifies that the method is private ;
Private method example :
/// The method is private int _minus(int num1, int num2){
return num1 - num2; }
3、 ... and 、Dart Anonymous functions
Anonymous methods : Only parameter list and method body , No method name , Anonymous methods can be assigned to a variable ,
Anonymous methods And Naming method Corresponding , The common way is to name ;
The anonymous method format is as follows : In parentheses is a list of parameters , In braces is the method body ;
( Parameter type Parameter name , Parameter type 2 Parameter name 2){
/// Anonymous method body };
Anonymous method example :
/// Anonymous method example anonymousFunction(){
var list = ['Tom', 'Jerry']; list.forEach( /// The following method is anonymous , Only parameter list and method body (i){
print(list.indexOf(i)); } ); }
Four 、 Complete code example
class Function{
/// Standard method /// The return value is int type /// The function name is sum /// Parameter is int num1, int num2 int sum(int num1, int num2){
return num1 + num2; } /// The method is private int _minus(int num1, int num2){
return num1 - num2; } /// Anonymous method example anonymousFunction(){
var list = ['Tom', 'Jerry']; list.forEach( /// The following method is anonymous , Only parameter list and method body (i){
print(list.indexOf(i)); } ); }}
5、 ... and 、Dart Methods to summarize
Entry method : stay main.dart Medium main() Method ;
void main() => runApp(MyApp());
Construction method : Reference resources 【Flutter】Dart object-oriented ( Name the construction method | Factory construction method | Name factory construction method ) Naming construction method in blog , Factory construction method, etc ;
getter and setter Method : Use get and set How to define keywords , Reference resources 【Flutter】Dart object-oriented ( get Method | set Method | Static methods ) Blog ;
Static methods : static Methods of keyword modification ; Reference resources 【Flutter】Dart object-oriented ( get Method | set Method | Static methods ) Blog ;
Abstract method : There is no method body method ; Reference resources 【Flutter】Dart object-oriented ( abstract class | Abstract method ) Blog ;
Private method : Method names begin with an underscore ;
Anonymous methods : Only parameter list and method body , No method name ;
6、 ... 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/15452191 ( The source code snapshot of this blog , You can find the source code of this blog )
边栏推荐
- Kt148a voice chip instructions, hardware, protocols, common problems, and reference codes
- Complete example of pytorch model saving +does pytorch model saving only save trainable parameters? Yes (+ solution)
- Dictionaries
- One side is volume, the other side is layoff. There are a lot of layoffs in byte commercialization department. What do you think of this wave?
- KT148A语音芯片ic的用户端自己更换语音的方法,上位机
- AcWing 340. Solution to communication line problem (binary + double ended queue BFS for the shortest circuit)
- 八年测开经验,面试28K公司后,吐血整理出高频面试题和答案
- Driverless learning (III): Kalman filter
- Codeforces round 651 (Div. 2) (a thinking, B thinking, C game, D dichotomy, e thinking)
- sql-labs
猜你喜欢
Design and implementation of ks004 based on SSH address book system
Resunnet - tensorrt8.2 Speed and Display record Sheet on Jetson Xavier NX (continuously supplemented)
[QT] QPushButton creation
Istio1.12: installation and quick start
Kt148a voice chip instructions, hardware, protocols, common problems, and reference codes
编写完10万行代码,我发了篇长文吐槽Rust
KT148A语音芯片ic的软件参考代码C语言,一线串口
Dictionaries
笔记本安装TIA博途V17后出现蓝屏的解决办法
Use graalvm native image to quickly expose jar code as a native shared library
随机推荐
How to set priorities in C language? Elaborate on C language priorities
编写完10万行代码,我发了篇长文吐槽Rust
Start practicing calligraphy
【Hot100】22. bracket-generating
【Hot100】21. 合并两个有序链表
Conscience summary! Jupyter notebook from Xiaobai to master, the nanny tutorial is coming!
What is online account opening? Is it safe to open an account online now?
Automatically generate VGg image annotation file
NMF-matlab
at编译环境搭建-win
Codeforces round 651 (Div. 2) (a thinking, B thinking, C game, D dichotomy, e thinking)
什么叫在线开户?现在网上开户安全么?
【QT】QPushButton创建
为什么我对流程情有独钟?
CRM Customer Relationship Management System
AcWing 1127. Sweet butter solution (shortest path SPFA)
自動生成VGG圖像注釋文件
KT148A语音芯片ic的软件参考代码C语言,一线串口
AcWing 181. Turnaround game solution (search ida* search)
「 工业缺陷检测深度学习方法」最新2022研究综述