Skip to content

Instantly share code, notes, and snippets.

@polyGeek
Created July 29, 2021 15:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save polyGeek/858328eb11b38f9c05862626860febd3 to your computer and use it in GitHub Desktop.
Save polyGeek/858328eb11b38f9c05862626860febd3 to your computer and use it in GitHub Desktop.
Example of Named Constructors
void main() {
Temperature cel = Temperature( celsius: 11 );
print( 'cel: ' + cel.celsius.toString() );
Temperature far = Temperature.f( farenheit: 70 );
print( 'far: ' + far.celsius.toString () );
}
class Temperature {
Temperature( { required this.celsius } );
Temperature.f( { required double farenheit } ) {
celsius = ( farenheit - 32 ) / 1.8;
}
late double celsius;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment