can i ask? I'm studying the language dart Functions with Optional Parameters. When I run this code an error occurs and I'm confused to fix it. can you help me solve this:
void gfg1(int g1, [ int g2 ])
{
// Creating function 1
print("g1 is $g1");
print("g2 is $g2");
}
void gfg2(int g1, { int g2, int g3 })
{
// Creating function 1
print("g1 is $g1");
print("g2 is $g2");
print("g3 is $g3");
}
void gfg3(int g1, { int g2 : 12 })
{
// Creating function 1
print("g1 is $g1");
print("g2 is $g2");
}
void main()
{
// Calling the function with optional parameter
print("Calling the function with optional parameter:");
gfg1(01);
// Calling the function with Optional Named parameter
print("Calling the function with Optional Named parameter:");
gfg2(01, g3 : 12);
// Calling function with default valued parameter
print("Calling function with default valued parameter");
gfg3(01);
}
problem :
The parameter 'g2' can't have a value of 'null' because of its type, but the implicit default value is 'null'.
Try adding either an explicit non-'null' default value or the 'required' modifier.
The parameter 'g3' can't have a value of 'null' because of its type, but the implicit default value is 'null'.
Try adding either an explicit non-'null' default value or the 'required' modifier.
this my dart version : Dart SDK version: 2.12.0-179.0.dev (dev) (Wed Dec 23 21:08:22 2020 -0800) on "windows_x64"
reference : https://www.geeksforgeeks.org/dart-programming-functions/?ref=rp