Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is there a way to set a max limit to math operations in dart?

I have the following math operation:

    var _baseFontSize = _userfontsize*8;
    if (_baseFontSize > 14) { _baseFontSize = 14.0; }

Essentially whatever the _userfontsize is, my _baseFontSize should be 8x that number, but never exceeding 14.0.

Instead of doing this math operation in 2 lines as might be conventional, is there a way to set a max limit to this (or any given) math operation in dart?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can import dart:math and do something like this with min:

var _baseFontSize = min(_userfontsize * 8, 14.0);

T min<T extends num>(T a, T b)

Returns the lesser of two numbers.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading