title: Functions with Optional Parameter dart
body: <p>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:</p>
  <pre><code>void gfg1(int g1, [ int g2 ]) 
  { 
    // Creating function 1 
    print(&quot;g1 is $g1&quot;); 
    print(&quot;g2 is $g2&quot;); 
  } 
  
  void gfg2(int g1, { int g2, int g3 }) 
  { 
    // Creating function 1 
    print(&quot;g1 is $g1&quot;); 
    print(&quot;g2 is $g2&quot;); 
    print(&quot;g3 is $g3&quot;); 
  } 
  
  void gfg3(int g1, { int g2 : 12 }) 
  { 
    // Creating function 1 
    print(&quot;g1 is $g1&quot;); 
    print(&quot;g2 is $g2&quot;); 
  } 
  
  void main() 
  { 
    // Calling the function with optional parameter 
    print(&quot;Calling the function with optional parameter:&quot;); 
    gfg1(01); 
  
    // Calling the function with Optional Named parameter 
    print(&quot;Calling the function with Optional Named parameter:&quot;); 
    gfg2(01, g3 : 12); 
  
    // Calling function with default valued parameter 
    print(&quot;Calling function with default valued parameter&quot;); 
    gfg3(01); 
   } 
  </code></pre>
  <p>problem :</p>
  <pre><code>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.
  </code></pre>
  <p>this my dart version : Dart SDK version: 2.12.0-179.0.dev (dev) (Wed Dec 23 21:08:22 2020 -0800) on &quot;windows_x64&quot;</p>
  <p>reference : <a href="https://www.geeksforgeeks.org/dart-programming-functions/?ref=rp" rel="nofollow noreferrer">https://www.geeksforgeeks.org/dart-programming-functions/?ref=rp</a></p>