Created
July 29, 2021 15:17
-
-
Save polyGeek/858328eb11b38f9c05862626860febd3 to your computer and use it in GitHub Desktop.
Example of Named Constructors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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