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

Time:01-16

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?

CodePudding user response:

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.

  •  Tags:  
  • Related