Skip to content

Instantly share code, notes, and snippets.

@doyle-flutter
Created January 28, 2024 16:08
Show Gist options
  • Save doyle-flutter/3513e9e79aa405f43f667e798b1be578 to your computer and use it in GitHub Desktop.
Save doyle-flutter/3513e9e79aa405f43f667e798b1be578 to your computer and use it in GitHub Desktop.
class01 func
void main(){
/// 1
void func0(){
// ...
}
void func1(){
// ...
return;
}
void func2() => 0;
int func3() => 1;
func0();
func1();
func2();
func3();
/// 2
void Function() func4 = (){};
void Function() func5 = () => 5;
int Function() func6 = (){
return 6;
};
int Function() func7 = () => 7;
func4();
func5();
func6();
func7();
/// 3 P&A
void fpa0(int arg){}
void fpa1(int arg0, arg1, var arg2) => print("$arg0 $arg1 $arg2");
// fpa0(); // err -> arg
// fpa1(); // err -> arg0,1,2
fpa0(0);
fpa1(1,2,3);
/// 4 Named P&A
void fnpa0({int? arg}){}
void fnpa1({required int? arg}){}
void fnpa2({required int arg}){}
fnpa0();
// fnpa0(0); // err -> named
fnpa0(arg: 0);
// fnpa1(); // err -> required
fnpa1(arg: null);
fnpa1(arg: 1);
// fnpa2(); // err -> arg
// fnpa2(arg: null); // err -> not null
fnpa2(arg: 2);
/// 5 callback
void fcb(void Function() cb) => cb();
fcb(() => print("cb0"));
void fcb1(void Function(int, String) cb) => cb(1, "fcb1 - cb");
fcb1((int x, String y) => print("$x $y"));
int fcb2(int Function(int) cb) => cb(2) + 1;
int fcb2Value = fcb2((int z) => z+z);
print("fcb2Value + 1 = ${fcb2Value+1}");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment