Skip to content

Instantly share code, notes, and snippets.

@dirisujesse
Last active March 26, 2020 17:46
Show Gist options
  • Save dirisujesse/66e67e8b7eb6b68e1ccf45e3caf62fb2 to your computer and use it in GitHub Desktop.
Save dirisujesse/66e67e8b7eb6b68e1ccf45e3caf62fb2 to your computer and use it in GitHub Desktop.
Responsive font scaling strategy for flutter
import 'package:flutter/widgets.dart' show BuildContext, MediaQuery;
class FontSizer {
num _shortestSide;
FontSizer(BuildContext context) {
_shortestSide = MediaQuery.of(context).size.shortestSide;
}
num sp(double percentage) {
return ((_shortestSide) * (percentage / 1000)).ceil().toDouble();
}
}
@jogboms
Copy link

jogboms commented Feb 15, 2020

The 1000 is a magic number?

@dirisujesse
Copy link
Author

Yep

@jogboms
Copy link

jogboms commented Mar 26, 2020

😱

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment